-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [GAPS-26] - djangocms-moderation integration (#13)
- Loading branch information
Showing
23 changed files
with
371 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,68 @@ | ||
from django.conf import settings | ||
from django.template.loader import render_to_string | ||
from django.urls import reverse | ||
from django.utils.html import format_html | ||
|
||
from cms.app_base import CMSAppConfig | ||
|
||
from .constants import CONTENT_EXPIRY_EXPIRE_FIELD_LABEL | ||
|
||
|
||
def get_moderation_content_expiry_link(obj): | ||
""" | ||
Return a user friendly button for viewing content expiry in the | ||
actions section of the Moderation Request Admin Changelist | ||
in djangocms-moderation. | ||
:param obj: A Moderation Request object supplied from the admin view table row | ||
:return: A link to the expiry record if one exists | ||
""" | ||
version = obj.moderation_request.version | ||
|
||
# If a content expiry record exists we can go to it | ||
if hasattr(version, "contentexpiry"): | ||
view_endpoint = format_html( | ||
"{}?collection__id__exact={}&_popup=1", | ||
reverse("admin:djangocms_content_expiry_contentexpiry_change", args=[version.contentexpiry.pk]), | ||
obj.pk, | ||
) | ||
return render_to_string( | ||
"djangocms_content_expiry/calendar_icon.html", {"url": view_endpoint, "field_id": f"contentexpiry_{obj.pk}"} | ||
) | ||
return "" | ||
|
||
|
||
def get_expiry_date(obj): | ||
""" | ||
A custom field to show the expiry date in the | ||
Moderation Request Admin Changelist in djangocms-moderation. | ||
:param obj: A Moderation Request object supplied from the admin view table row | ||
:return: The expiry date from the matching moderation request object | ||
""" | ||
version = obj.moderation_request.version | ||
|
||
if hasattr(version, "contentexpiry"): | ||
return version.contentexpiry.expires | ||
|
||
|
||
get_expiry_date.short_description = CONTENT_EXPIRY_EXPIRE_FIELD_LABEL | ||
|
||
|
||
class ContentExpiryAppConfig(CMSAppConfig): | ||
# Enable moderation to be able to "configure it" | ||
djangocms_moderation_enabled = True | ||
moderated_models = [] | ||
moderation_request_changelist_actions = [ | ||
get_moderation_content_expiry_link, | ||
] | ||
moderation_request_changelist_fields = [ | ||
get_expiry_date, | ||
] | ||
# Enable versioning because moderation is versioning dependant | ||
djangocms_versioning_enabled = True | ||
versioning = [] | ||
|
||
djangocms_content_expiry_enabled = getattr( | ||
settings, "DJANGOCMS_CONTENT_EXPIRY_ENABLED", True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.conf import settings | ||
|
||
|
||
DEFAULT_RANGEFILTER_DELTA = getattr( | ||
settings, "CMS_CONTENT_EXPIRY_DEFAULT_RANGEFILTER_DELTA", 30 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
CONTENT_EXPIRY_EXPIRE_FIELD_LABEL = _("expiry date") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django import forms | ||
from django.contrib.admin import widgets | ||
from django.contrib.admin.sites import site | ||
|
||
from .models import ContentExpiry | ||
|
||
|
||
class ForeignKeyReadOnlyWidget(widgets.ForeignKeyRawIdWidget): | ||
""" | ||
A Widget for displaying ForeignKeys in a read only interface rather than | ||
in a <select> box. | ||
""" | ||
template_name = 'admin/widgets/foreign_key_read_only.html' | ||
|
||
|
||
class ContentExpiryForm(forms.ModelForm): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
version_field = ContentExpiry._meta.get_field('version').remote_field | ||
self.fields['version'].widget = ForeignKeyReadOnlyWidget(version_field, site) | ||
|
||
user_field = ContentExpiry._meta.get_field('created_by').remote_field | ||
self.fields['created_by'].widget = ForeignKeyReadOnlyWidget(user_field, site) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from django.contrib.auth import get_user_model | ||
|
||
from djangocms_content_expiry.conf import DEFAULT_RANGEFILTER_DELTA | ||
|
||
|
||
def get_authors(): | ||
""" | ||
Helper to return all authors created by content expiry | ||
""" | ||
User = get_user_model() | ||
return User.objects.filter(contentexpiry__created_by__isnull=False).distinct() | ||
|
||
|
||
def get_rangefilter_expires_default(): | ||
""" | ||
Sets a default date range to help filter | ||
Content Expiry records | ||
""" | ||
start_date = datetime.now() - timedelta(DEFAULT_RANGEFILTER_DELTA) | ||
end_date = datetime.now() | ||
return start_date, end_date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
djangocms_content_expiry/static/djangocms_content_expiry/svg/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions
2
djangocms_content_expiry/templates/admin/widgets/foreign_key_read_only.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<input type="hidden" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}> | ||
{{ link_label }} |
2 changes: 2 additions & 0 deletions
2
djangocms_content_expiry/templates/djangocms_content_expiry/calendar_icon.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% load static i18n %} | ||
<a class="btn cms-moderation-action-btn js-moderation-action related-widget-wrapper-link" id="change_content_expiry_id_{{ field_id }}" href="{{ url }}" title="{% trans 'View Expiry' %}"><span class="svg-juxtaposed-font"><img src="{% static 'djangocms_content_expiry/svg/calendar.svg' %}" /></span></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.