Skip to content

Commit

Permalink
Merge branch 'main' into causelist
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed Oct 11, 2024
2 parents 71b40b4 + fe113af commit 32af9e4
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion peachjam/adapters/indigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def create_publication_file(self, publication_document, doc, title, stub=False):
logger.info(
f" Deleting existing PublicationFile file on {doc.work_frbr_uri}"
)
doc.publication_file.file.delete()
doc.publication_file.file.delete(save=False)

if stub:
if hasattr(doc, "source_file"):
Expand Down
14 changes: 14 additions & 0 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
citations_processor,
pj_settings,
)
from peachjam.models.activity import EditActivity
from peachjam.plugins import plugins
from peachjam.resources import (
ArticleResource,
Expand Down Expand Up @@ -287,6 +288,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)
content_html = forms.CharField(
widget=CKEditorWidget(
extra_plugins=["lawwidgets"],
Expand Down Expand Up @@ -339,6 +342,8 @@ def __init__(self, data=None, *args, **kwargs):
if self.instance and self.instance.content_html_is_akn:
self.fields["content_html"].widget.attrs["readonly"] = True

self.fields["edit_activity_start"].initial = timezone.now()

def clean_content_html(self):
# prevent CKEditor-based editing of AKN HTML
if self.instance.content_html_is_akn:
Expand Down Expand Up @@ -528,6 +533,15 @@ def save_model(self, request, obj, form, change):

super().save_model(request, obj, form, change)

# update the edit activity end time
EditActivity.objects.create(
document=obj,
user=request.user,
stage="corrections" if change else "initial",
start=form.cleaned_data["edit_activity_start"],
end=timezone.now(),
)

def save_related(self, request, form, formsets, change):
# after saving related models, also save this model again so that it can update fields based on related changes
# if date, title, or content changed, re-extract citations or if new document
Expand Down
61 changes: 61 additions & 0 deletions peachjam/migrations/0165_editactivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generated by Django 4.2.14 on 2024-10-10 13:20

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("peachjam", "0164_peachjamsettings_robots_txt"),
]

operations = [
migrations.CreateModel(
name="EditActivity",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("start", models.DateTimeField()),
("end", models.DateTimeField()),
("seconds", models.IntegerField()),
(
"stage",
models.CharField(
choices=[
("initial", "initial"),
("corrections", "corrections"),
],
default="initial",
max_length=255,
),
),
(
"document",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="peachjam.coredocument",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ("start",),
},
),
]
26 changes: 26 additions & 0 deletions peachjam/models/activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.contrib.auth.models import User
from django.db import models

from peachjam.models import CoreDocument


class EditActivity(models.Model):
"""Time spent editing a document via the admin area."""

document = models.ForeignKey(CoreDocument, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
start = models.DateTimeField()
end = models.DateTimeField()
seconds = models.IntegerField()
stage = models.CharField(
max_length=255,
choices=(("initial", "initial"), ("corrections", "corrections")),
default="initial",
)

class Meta:
ordering = ("start",)

def save(self, *args, **kwargs):
self.seconds = (self.end - self.start).total_seconds()
super().save(*args, **kwargs)
4 changes: 4 additions & 0 deletions peachjam/templates/admin/change_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% extends "admin/change_form.html" %}
{% load i18n comments humanize static %}
{% block form_top %}
{{ block.super }}
{% if adminform.form.edit_activity_start %}{{ adminform.form.edit_activity_start.as_hidden }}{% endif %}
{% endblock %}
{% block extra_actions %}
{{ block.super }}
{% if PEACHJAM_SETTINGS.editor_help_link and adminform.model_admin.help_topic %}
Expand Down

0 comments on commit 32af9e4

Please sign in to comment.