Skip to content

Commit

Permalink
fix: Update templates for better styling w/o djangocms-admin-style (#352
Browse files Browse the repository at this point in the history
)

* Remove remove_published_where

* Fix: Add `submit-row` to admin forms for better styling with plain Django admin
Fix: Remove unused helper function

* fix typo
  • Loading branch information
fsbraun authored Sep 22, 2023
1 parent 5944cff commit 6ac73e8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 61 deletions.
21 changes: 3 additions & 18 deletions djangocms_versioning/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
from django.contrib.contenttypes.models import ContentType
from django.core.mail import EmailMessage
from django.db import models
from django.db.models.sql.where import WhereNode
from django.template.loader import render_to_string
from django.utils.encoding import force_str

from . import versionables
from .conf import EMAIL_NOTIFICATIONS_FAIL_SILENTLY
from .constants import DRAFT, PUBLISHED
from .constants import DRAFT

try:
from djangocms_internalsearch.helpers import emit_content_change
Expand Down Expand Up @@ -286,23 +285,9 @@ def remove_published_where(queryset):
"""
By default, the versioned queryset filters out so that only versions
that are published are returned. If you need to return the full queryset
this method can be used.
It will modify the sql to remove `where state = 'published'`
use the "admin_manager" instead of "objects"
"""
where_children = queryset.query.where.children
all_except_published = [
lookup for lookup in where_children
if not (
lookup.lookup_name == "exact" and
lookup.rhs == PUBLISHED and
lookup.lhs.field.name == "state"
)
]

queryset.query.where = WhereNode()
queryset.query.where.children = all_except_published
return queryset
raise NotImplementedError("remove_published_where has been replaced by ContentObj.admin_manager")


def get_latest_admin_viewable_content(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls static %}
{% block title %}{% trans "Discard Confirmation" %}{% endblock %}

{% block extrahead %}
{{ block.super }}
Expand All @@ -12,19 +11,20 @@
{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation{% endblock %}

{% block content %}
<h1>{% block title %}{% trans "Discard Confirmation" %}{% endblock %}</h1>
<p>{% translate "Are you sure you want to discard following version?" %}</p>
<h3>{{ object_name }}</h3>
<h4>{% blocktrans %}Version number: {{ version_number }}{% endblocktrans %}</h4>
<form action="" method="POST">
{% csrf_token %}
<input class="button confirm-link js-versioning-keep-sideframe"
type="submit"
name="discard"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate "No, take me back" %}">
</a>
<div class="submit-row">
<input class="button confirm-link js-versioning-keep-sideframe default"
type="submit"
name="discard"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}" class="cancel-link js-versioning-keep-sideframe" role="button">
{% translate 'No, take me back' %}
</a>
</div>
</form>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls static %}
{% block title %}{% translate "Revert Confirmation" %}{% endblock %}

{% block extrahead %}
{{ block.super }}
Expand All @@ -13,6 +12,7 @@
{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation{% endblock %}

{% block content %}
<h1>{% block title %}{% translate "Revert Confirmation" %}{% endblock %}</h1>
<p>
{% if draft_version %}
{% translate "Reverting to this version may cause loss of an existing draft version. Please select an option to continue" %}
Expand All @@ -24,25 +24,25 @@ <h3>{{ object_name }}</h3>
<h4>{% blocktrans %}Version number: {{ version_number }}{% endblocktrans %}</h4>
<form action="" method="POST">
{% csrf_token %}
{% if draft_version %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
type="submit"
name="discard"
value="{% translate 'Discard existing draft and Revert' %}">
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
name="archive"
type="submit"
value="{% translate 'Archive existing draft and Revert' %}">
{% else %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
type="submit"
name="revert"
value="{% translate "Yes, I'm sure" %}">
{% endif %}
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate 'No, take me back' %}">
</a>
<div class="submit-row">
{% if draft_version %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
type="submit"
name="discard"
value="{% translate 'Discard existing draft and Revert' %}">
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
name="archive"
type="submit"
value="{% translate 'Archive existing draft and Revert' %}">
{% else %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
type="submit"
name="revert"
value="{% translate "Yes, I'm sure" %}">
{% endif %}
<a href="{{ back_url }}" class="cancel-link js-versioning-keep-sideframe" role="button">
{% translate 'No, take me back' %}
</a>
</div>
</form>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls static %}
{% block title %}{% translate "Revert Confirmation" %}{% endblock %}

{% block extrahead %}
{{ block.super }}
Expand All @@ -12,6 +11,7 @@
{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation{% endblock %}

{% block content %}
<h1>{% block title %}{% translate "Revert Confirmation" %}{% endblock %}</h1>
<p>{% translate "Unpublishing will remove this version from live. Are you sure you want to unpublish?" %}</p>
<h3>{{ object_name }}</h3>
<h4>{% blocktrans %} Version number: {{ version_number }}{% endblocktrans %}</h4>
Expand All @@ -22,13 +22,15 @@ <h4>{% blocktrans %} Version number: {{ version_number }}{% endblocktrans %}</h4
</div>
<form action="" method="POST">
{% csrf_token %}
<input class="button confirm-link js-versioning-keep-sideframe"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate 'No, take me back' %}">
</a>
<div class="submit-row">
<input class="button confirm-link js-versioning-keep-sideframe"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate 'No, take me back' %}">
</a>
</div>
</form>
{% endblock %}
5 changes: 2 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from djangocms_versioning.constants import DRAFT, PUBLISHED
from djangocms_versioning.datastructures import VersionableItem, default_copy
from djangocms_versioning.helpers import remove_published_where
from djangocms_versioning.models import Version, VersionQuerySet
from djangocms_versioning.test_utils import factories
from djangocms_versioning.test_utils.polls.cms_config import PollsCMSConfig
Expand Down Expand Up @@ -244,11 +243,11 @@ def test_get_for_content(self):
version = factories.PollVersionFactory()
self.assertEqual(Version.objects.get_for_content(version.content), version)

def test_versioned_queryset_return_full_with_helper_method(self):
def test_versioned_admin_manager(self):
"""With an extra helper method we can return the full queryset"""
factories.PollVersionFactory()
normal_count = PollContent.objects.all()
full_count = remove_published_where(PollContent.objects.all())
full_count = PollContent.admin_manager.all()

self.assertEqual(normal_count.count(), 0)
self.assertEqual(full_count.count(), 1)
Expand Down

0 comments on commit 6ac73e8

Please sign in to comment.