Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct record linked from Campaign table #578

Merged
20 changes: 7 additions & 13 deletions app/admin_ui/tables/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,6 @@ def render_short_name(self, value, record):
'canonical-redirect',
kwargs={
"canonical_uuid": record.uuid,
# this property is coming from an annotation on the inital query
"draft_uuid": record.draft_uuid,
"model": camel_to_snake(record.model_name),
},
),
Expand All @@ -526,7 +524,13 @@ class CampaignChangeListTable(LimitedTableBase):
verbose_name="Short Name",
accessor="latest_update__short_name",
backup_accessor="content_object.short_name",
linkify=("change-update", [tables.A("uuid")]),
linkify=(
"canonical-redirect",
{
"canonical_uuid": tables.A('uuid'),
"model": 'campaign',
},
),
)
funding_agency = BackupValueColumn(
verbose_name="Funding Agency",
Expand All @@ -548,8 +552,6 @@ def render_short_name(self, value, record):
'canonical-redirect',
kwargs={
"canonical_uuid": record.uuid,
# this property is coming from an annotation on the inital query
"draft_uuid": record.draft_uuid,
"model": camel_to_snake(record.model_name),
},
),
Expand Down Expand Up @@ -578,8 +580,6 @@ def render_short_name(self, value, record):
'canonical-redirect',
kwargs={
"canonical_uuid": record.uuid,
# this property is coming from an annotation on the inital query
"draft_uuid": record.draft_uuid,
"model": camel_to_snake(record.model_name),
},
),
Expand All @@ -600,8 +600,6 @@ def render_short_name(self, value, record):
'canonical-redirect',
kwargs={
"canonical_uuid": record.uuid,
# this property is coming from an annotation on the inital query
"draft_uuid": record.draft_uuid,
"model": camel_to_snake(record.model_name),
},
),
Expand Down Expand Up @@ -633,8 +631,6 @@ def render_short_name(self, value, record):
'canonical-redirect',
kwargs={
"canonical_uuid": record.model_instance_uuid or record.uuid,
# TODO this change object has not property draft uuid
"draft_uuid": record.uuid,
"model": camel_to_snake(record.model_name),
},
),
Expand Down Expand Up @@ -909,8 +905,6 @@ def render_short_name(self, value, record):
'canonical-redirect',
kwargs={
"canonical_uuid": record.uuid,
# this property is coming from an annotation on the inital query
"draft_uuid": record.draft_uuid,
"model": camel_to_snake(record.model_name),
},
),
Expand Down
4 changes: 2 additions & 2 deletions app/admin_ui/templates/snippets/object_header_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<li class="nav-item">
<a
class="nav-link {% if url_name == 'canonical-published-detail' %}active{% endif %} {% if not has_published_draft %}disabled{% endif %}"
href="{% url 'canonical-published-detail' model=view_model canonical_uuid=canonical_uuid draft_uuid=draft_uuid%}"
href="{% url 'canonical-published-detail' model=view_model canonical_uuid=canonical_uuid %}"
>
Published
</a>
</li>
<li class="nav-item">
<a
class="nav-link {% if not has_progress_draft %} disabled {% endif %} {% if url_name == 'canonical-draft-edit' or url_name == 'create-update' %}active{% endif %}"
href="{% url 'canonical-draft-edit' model=view_model canonical_uuid=canonical_uuid draft_uuid=object.uuid%}"
href="{% url 'canonical-draft-edit' model=view_model canonical_uuid=canonical_uuid %}"
>
Edits
{% if draft_status == 'Published' and url_name == 'create-update' %}
Expand Down
1 change: 0 additions & 1 deletion app/admin_ui/templatetags/template_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def object_header_tabs(context, change: Change, canonical_change: Optional[Chang
"draft_status": draft_status,
"draft_status_class": draft_status_class,
"canonical_uuid": canonical_uuid,
"draft_uuid": change.uuid,
"has_progress_draft": has_progress_draft,
"has_published_draft": has_published_draft,
"request": context.get("request"),
Expand Down
8 changes: 4 additions & 4 deletions app/admin_ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@
path('v2/<str:model>', v2.CanonicalRecordList.as_view(), name="canonical-list"),
# Helper route to redirect user to appropriate view without prior knowledge of record's status (ie if it's been published). If published, return redirect to `/<uuid:canonical_uuid>/published`. Otherwise, redirect to `/<uuid:canonical_uuid>/edit`.
path(
'v2/<str:model>/<uuid:canonical_uuid>/<uuid:draft_uuid>',
'v2/<str:model>/<uuid:canonical_uuid>',
v2.redirect_helper,
name="canonical-redirect",
),
# Read-only view the published record for this concept. Render `400` response if record is not yet published.
path(
'v2/<str:model>/<uuid:canonical_uuid>/published/<uuid:draft_uuid>',
'v2/<str:model>/<uuid:canonical_uuid>/published',
v2.CanonicalRecordPublished.as_view(),
name="canonical-published-detail",
),
# Update for latest published draft.
# View latest draft for canonical record.
path(
'v2/<str:model>/<uuid:canonical_uuid>/edit/<uuid:draft_uuid>',
'v2/<str:model>/<uuid:canonical_uuid>/edit',
v2.CanonicalDraftEdit.as_view(),
name="canonical-draft-edit",
),
Expand Down
15 changes: 10 additions & 5 deletions app/admin_ui/views/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def get_queryset(self):
Change.objects.of_type(*self.models)
.filter(action=Change.Actions.CREATE)
.annotate(
draft_uuid=Subquery(related_drafts.values("uuid")[:1]),
latest_status=Subquery(related_drafts.values("status")[:1]),
latest_action=Subquery(related_drafts.values("action")[:1]),
latest_updated_at=Subquery(related_drafts.values("updated_at")[:1]),
Expand Down Expand Up @@ -480,19 +479,25 @@ def form_valid(self, form):
mark_safe(f"<b>Unable to transition draft.</b> {format_validation_error(err)}"),
)
else:
obj = self.get_object()
messages.success(
self.request,
(
f"Transitioned \"{obj.model_name}: {obj.update.get('short_name', obj.uuid)}\" "
f"to \"{obj.get_status_display()}\"."
f"Transitioned {form.change.model_name}:"
+ f" {form.change.update.get('short_name', form.change.uuid)!r}"
+ f" to {form.change.get_status_display()!r}."
),
)

return super().form_valid(form)

def get_success_url(self):
return self.request.META.get("HTTP_REFERER") or super().get_success_url()
return reverse(
"canonical-redirect",
kwargs={
"canonical_uuid": self.kwargs[self.pk_url_kwarg],
"model": self.get_form().change.content_type.model,
},
)


def format_validation_error(err: ValidationError) -> str:
Expand Down
Loading
Loading