Skip to content

Commit

Permalink
Aggressively prune draft_uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Oct 12, 2023
1 parent 1a6aff6 commit 2b0dc9b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 22 deletions.
18 changes: 7 additions & 11 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",
update_accessor="content_object.short_name",
linkify=("change-update", [tables.A("uuid")]),
linkify=(
"canonical-redirect",
{
"canonical_uuid": tables.A('uuid'),
"model": 'campaign',
},
),
)
funding_agency = ConditionalValueColumn(
verbose_name="Funding Agency",
Expand Down Expand Up @@ -578,8 +582,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 +602,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 +633,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 +907,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
2 changes: 1 addition & 1 deletion app/admin_ui/templates/snippets/object_header_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<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>
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
4 changes: 2 additions & 2 deletions app/admin_ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
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",
),
Expand Down
1 change: 0 additions & 1 deletion 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
7 changes: 1 addition & 6 deletions app/admin_ui/views/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


# TODO add login requirement
def redirect_helper(request, canonical_uuid, draft_uuid, model):
def redirect_helper(request, canonical_uuid, model):
try:
has_progress_draft = (
Change.objects.exclude(status=Change.Statuses.PUBLISHED)
Expand All @@ -52,7 +52,6 @@ def redirect_helper(request, canonical_uuid, draft_uuid, model):
kwargs={
"canonical_uuid": canonical_uuid,
"model": model,
"draft_uuid": draft_uuid,
},
)
)
Expand Down Expand Up @@ -103,7 +102,6 @@ def get_queryset(self):
)
)
.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 @@ -272,7 +270,6 @@ def get_success_url(self, **kwargs):
"canonical-redirect",
kwargs={
"canonical_uuid": self.kwargs[self.pk_url_kwarg],
"draft_uuid": self.object.pk,
"model": self.kwargs["model"],
},
)
Expand All @@ -294,7 +291,6 @@ def get_context_data(self, **kwargs):
"descendents": context["object"].get_descendents().select_related("content_type"),
"comparison_form": self._get_comparison_form(context['model_form']),
"canonical_uuid": self.kwargs[self.pk_url_kwarg],
"draft_uuid": self.object.pk,
}

def _get_comparison_form(self, model_form):
Expand Down Expand Up @@ -448,7 +444,6 @@ def get_context_data(self, **kwargs):
Change.objects.get(uuid=self.kwargs[self.pk_url_kwarg]).model_name.lower()
),
"display_name": Change.objects.get(uuid=self.kwargs[self.pk_url_kwarg]).model_name,
"draft_uuid": self.object.pk,
}

def get_success_url(self):
Expand Down

0 comments on commit 2b0dc9b

Please sign in to comment.