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

As an editor fixing mistakes, it would be useful to be able to temporarily unpublish a document rather than deleting it #1702

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions africanlii/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ def get_context_data(self, **kwargs):
)

context["recent_articles"] = recent_articles
context["recent_soft_law"] = GenericDocument.objects.exclude(
frbr_uri_doctype="doc"
).order_by("-date")[:5]
context["recent_reports_guides"] = GenericDocument.objects.filter(
frbr_uri_doctype="doc"
).order_by("-date")[:5]
context["recent_legal_instruments"] = CoreDocument.objects.filter(
frbr_uri_doctype="act"
).order_by("-date")[:5]
context["recent_soft_law"] = (
GenericDocument.objects.exclude(published=False)
.exclude(frbr_uri_doctype="doc")
.order_by("-date")[:5]
)
context["recent_reports_guides"] = (
GenericDocument.objects.exclude(published=False)
.filter(frbr_uri_doctype="doc")
.order_by("-date")[:5]
)
context["recent_legal_instruments"] = (
CoreDocument.objects.exclude(published=False)
.filter(frbr_uri_doctype="act")
.order_by("-date")[:5]
)
context["au_organs"] = AfricanUnionOrgan.objects.prefetch_related("author")
context["au_institutions"] = AfricanUnionInstitution.objects.prefetch_related(
"author"
Expand Down
8 changes: 6 additions & 2 deletions liiweb/views/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["court_classes"] = CourtClass.objects.prefetch_related("courts")
context["recent_judgments"] = Judgment.objects.order_by("-date")[:5]
context["recent_legislation"] = Legislation.objects.order_by("-date")[:10]
context["recent_judgments"] = Judgment.objects.exclude(
published=False
).order_by("-date")[:5]
context["recent_legislation"] = Legislation.objects.exclude(
published=False
).order_by("-date")[:10]
context["taxonomies"] = Taxonomy.dump_bulk()
context["taxonomy_url"] = "taxonomy_detail"
context["recent_articles"] = (
Expand Down
3 changes: 2 additions & 1 deletion liiweb/views/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class LegislationListView(TemplateView):

def get_queryset(self):
qs = (
self.model.objects.distinct("work_frbr_uri")
self.model.objects.exclude(published=False)
.distinct("work_frbr_uri")
.order_by("work_frbr_uri", "-date", "language__pk")
.preferred_language(get_language(self.request))
)
Expand Down
15 changes: 15 additions & 0 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ class DocumentAdmin(BaseAdmin):
"reindex_for_search",
"apply_labels",
"ensure_source_file_pdf",
"publish",
"unpublish",
]

fieldsets = [
Expand Down Expand Up @@ -429,6 +431,7 @@ class DocumentAdmin(BaseAdmin):
"toc_json",
"content_html_is_akn",
"allow_robots",
"published",
],
},
),
Expand Down Expand Up @@ -587,6 +590,18 @@ def has_change_permission(self, request, obj=None):
return True
return super().has_change_permission(request, obj=obj)

def publish(self, request, queryset):
queryset.update(published=True)
self.message_user(request, _("Documents published."))

publish.short_description = gettext_lazy("Publish selected documents")

def unpublish(self, request, queryset):
queryset.update(published=False)
self.message_user(request, _("Documents unpublished."))

unpublish.short_description = gettext_lazy("Unpublish selected documents")


class TaxonomyForm(MoveNodeForm):
def save(self, commit=True):
Expand Down
18 changes: 18 additions & 0 deletions peachjam/migrations/0117_coredocument_published.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2024-01-24 12:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0116_copy_and_delete_old_order_outcome_field_data"),
]

operations = [
migrations.AddField(
model_name="coredocument",
name="published",
field=models.BooleanField(default=True, verbose_name="published"),
),
]
7 changes: 7 additions & 0 deletions peachjam/models/core_document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ class CoreDocument(PolymorphicModel):
help_text=_("Allow this document to be indexed by search engine robots."),
)

published = models.BooleanField(
_("published"),
default=True,
Sandravaphilips marked this conversation as resolved.
Show resolved Hide resolved
db_index=True,
help_text=_("Is this document published and visible on the website?"),
)

# options for the FRBR URI doctypes
frbr_uri_doctypes = FRBR_URI_DOCTYPES
labels = models.ManyToManyField(Label, verbose_name=_("labels"), blank=True)
Expand Down
4 changes: 4 additions & 0 deletions peachjam/views/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def dispatch(self, request, *args, **kwargs):
return redirect(url)
raise Http404()

if not obj.published:
raise Http404()

if not exact or portion:
url = obj.get_absolute_url()
# this translates from /akn/.../~sec_2 to /akn/.../#sec_2
Expand All @@ -53,6 +56,7 @@ def dispatch(self, request, *args, **kwargs):
return redirect(url)

view_class = registry.views.get(obj.doc_type)

if view_class:
view = view_class()
view.setup(request, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion peachjam/views/gazette.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def group_years(years, locality={}):


class GazetteListView(TemplateView):
queryset = Gazette.objects.prefetch_related("source_file")
queryset = Gazette.objects.exclude(published=False).prefetch_related("source_file")
template_name = "peachjam/gazette_list.html"
navbar_link = "gazettes"

Expand Down
6 changes: 5 additions & 1 deletion peachjam/views/generic_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ class DocumentListView(ListView):
queryset = CoreDocument.objects.prefetch_related("nature", "work")

def get_base_queryset(self):
return self.queryset if self.queryset is not None else self.model.objects
return (
self.queryset.exclude(published=False)
if self.queryset is not None
else self.model.objects.exclude(published=False)
)

def get_queryset(self):
qs = self.get_base_queryset()
Expand Down
18 changes: 13 additions & 5 deletions peachjam/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ class HomePageView(TemplateView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
recent_judgments = Judgment.objects.order_by("-date")[:5]
recent_documents = GenericDocument.objects.order_by("-date")[:5]
recent_instruments = LegalInstrument.objects.order_by("-date")[:5]
recent_legislation = Legislation.objects.order_by("-date")[:5]
documents_count = CoreDocument.objects.count()
recent_judgments = Judgment.objects.exclude(published=False).order_by("-date")[
:5
]
recent_documents = GenericDocument.objects.exclude(published=False).order_by(
"-date"
)[:5]
recent_instruments = LegalInstrument.objects.exclude(published=False).order_by(
"-date"
)[:5]
recent_legislation = Legislation.objects.exclude(published=False).order_by(
"-date"
)[:5]
documents_count = CoreDocument.objects.exclude(published=False).count()

authors = Author.objects.exclude(
Q(genericdocument__isnull=True),
Expand Down
4 changes: 3 additions & 1 deletion peachjam/views/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["court_classes"] = CourtClass.objects.prefetch_related("courts")
context["recent_judgments"] = Judgment.objects.order_by("-date")[:30]
context["recent_judgments"] = Judgment.objects.exclude(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we need to do the same in all the HomePageView classes -- also search for recent_* and ensure those are corrected (mostly in homepage views I think).

published=False
).order_by("-date")[:30]
context["doc_type"] = "Judgment"
return context

Expand Down
2 changes: 1 addition & 1 deletion peachjam_search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SearchableDocument(Document):
]

def should_index_object(self, obj):
if isinstance(obj, ExternalDocument):
if isinstance(obj, ExternalDocument) or not obj.published:
return False
return True

Expand Down
Loading