Skip to content

Commit

Permalink
allow edit activity stage to be passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Oct 11, 2024
1 parent 00a22e8 commit f1bd68d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 19 additions & 3 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ def value_from_datadict(self, data, files, name):

class DocumentForm(forms.ModelForm):
# to track edit activity
edit_activity_start = forms.DateTimeField(widget=forms.HiddenInput(), required=True)
edit_activity_start = forms.DateTimeField(widget=forms.HiddenInput())
edit_activity_stage = forms.CharField(widget=forms.HiddenInput())
content_html = forms.CharField(
widget=CKEditorWidget(
extra_plugins=["lawwidgets"],
Expand Down Expand Up @@ -344,6 +345,9 @@ def __init__(self, data=None, *args, **kwargs):
self.fields["content_html"].widget.attrs["readonly"] = True

self.fields["edit_activity_start"].initial = timezone.now()
self.fields["edit_activity_stage"].initial = (
"corrections" if self.instance.pk else "initial"
)

def clean_content_html(self):
# prevent CKEditor-based editing of AKN HTML
Expand Down Expand Up @@ -528,6 +532,14 @@ class NewForm(self.new_document_form_mixin, form):

return super().get_form(request, obj, **kwargs)

def render_change_form(self, request, context, *args, **kwargs):
# this is our only chance to inject a pre-filled field from the querystring for both add and change
if request.GET.get("stage"):
context["adminform"].form.fields[
"edit_activity_stage"
].initial = request.GET["stage"]
return super().render_change_form(request, context, *args, **kwargs)

def save_model(self, request, obj, form, change):
if not change:
obj.created_by = request.user
Expand All @@ -538,7 +550,7 @@ def save_model(self, request, obj, form, change):
EditActivity.objects.create(
document=obj,
user=request.user,
stage="corrections" if change else "initial",
stage=form.cleaned_data["edit_activity_stage"],
start=form.cleaned_data["edit_activity_start"],
end=timezone.now(),
)
Expand Down Expand Up @@ -981,7 +993,11 @@ def upload_view(self, request):
messages.success(
request, _("Judgment uploaded. Please check details carefully.")
)
return redirect("admin:peachjam_judgment_change", doc.pk)
url = (
reverse("admin:peachjam_judgment_change", args=[doc.pk])
+ "?stage=after-extraction"
)
return redirect(url)
except ExtractorError as e:
form.add_error(None, str(e))

Expand Down
3 changes: 2 additions & 1 deletion peachjam/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{% load i18n comments humanize static %}
{% block form_top %}
{{ block.super }}
{% if adminform.form.edit_activity_start %}{{ adminform.form.edit_activity_start.as_hidden }}{% endif %}
{% if adminform.form.edit_activity_start %}{{ adminform.form.edit_activity_start }}{% endif %}
{% if adminform.form.edit_activity_stage %}{{ adminform.form.edit_activity_stage }}{% endif %}
{% endblock %}
{% block extra_actions %}
{{ block.super }}
Expand Down

0 comments on commit f1bd68d

Please sign in to comment.