Skip to content

Commit

Permalink
feat(django): Add partial support for Django v4
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroLitvinov committed Apr 9, 2022
1 parent a57fa8e commit a9dbfc4
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 67 deletions.
11 changes: 7 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ Known issues
Documentation
=============

Full module documentation is hosted at ReadTheDocs: http://django-moderation.readthedocs.org/

Full documentation is hosted at `ReadTheDocs django-moderation <https://django-moderation.readthedocs.org/>`_


Contributors
============

Special thanks to all persons that contributed to this project.

- jonwd7 https://github.com/jonwd7
- treyhunner https://github.com/treyhunner

Thank you for all ideas, bug fixes, patches.
- `jonwd7 <https://github.com/jonwd7>`_
- `treyhunner <https://github.com/treyhunner>`_
- `DmytroLitvinov <https://github.com/DmytroLitvinov>`_

Thank you for all ideas, bug fixes, patches, maintaining.

4 changes: 1 addition & 3 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ Getting started quick guide
Installation
------------

Use easy_install:

.. code-block:: bash
$ easy_install django-moderation
$ pip install django-moderation
Or download source code from http://github.com/dominno/django-moderation and run
installation script:
Expand Down
6 changes: 4 additions & 2 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ Added features
- Minor changes at docs


0.8.0 (2022-04-05)
0.8.0 (2022-04-09)
------------------

- Drop support of Django<2.2. Now it supports only Django>=2.2,<4
- Drop support of Python3.5. Now it supports only Python 3.6, 3.7, 3.8, 3.9
- Drop support of ``DJANGO_MODERATION_MODERATORS`` setting
- Formatted code with `black`
- Drop dependency `django-model-utils` which we used for Choices functionality
- Drop dependency `django-model-utils` which we used for Choices functionality
- Add partial support for Django 4.0 - remove ugettext, change `smart_text` to `smart_str`,
change `ifequal` template tag to `if`.
15 changes: 8 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Welcome to django-moderation's documentation!
Introduction
------------

django-moderation is reusable application for Django framework, that allows to
``django-moderation`` is reusable application for Django framework, that allows to
moderate any model objects.

Possible use cases:
**Possible use cases**:

- User creates his profile, profile is not visible on site.
It will be visible on site when moderator approves it.
- User change his profile, old profile data is visible on site.
New data will be visible on site when moderator approves it.

Features:
**Features**:

- configurable admin integration(data changed in admin can be visible on
site when moderator approves it)
Expand All @@ -38,8 +38,9 @@ Contributors

Special thanks to all persons that contributed to this project.

- jonwd7 http://github.com/jonwd7
- treyhunner http://github.com/treyhunner
- `jonwd7 <https://github.com/jonwd7>`_
- `treyhunner <https://github.com/treyhunner>`_
- `DmytroLitvinov <https://github.com/DmytroLitvinov>`_

Thank you for all ideas, bug fixes, patches.

Expand All @@ -52,9 +53,9 @@ Screenshots
Requirements
============

Python 3.5, 3.6, 3.7
Python 3.6, 3.7, 3.8, 3.9

Django 1.11, 2.0, 2.1, 2.2
Django 2.2, 3.1, 3.2


Contents:
Expand Down
10 changes: 0 additions & 10 deletions example_project/settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import os

ADMINS = (
# ('Your Name', '[email protected]'),
)

DEBUG = True

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
Expand All @@ -20,13 +14,9 @@
}

TIME_ZONE = 'UTC'

LANGUAGE_CODE = 'en'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = [
Expand Down
4 changes: 2 additions & 2 deletions moderation/filterspecs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.admin.filters import FieldListFilter
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.utils.translation import gettext as _

from . import moderation
Expand Down Expand Up @@ -34,7 +34,7 @@ def choices(self, cl):
}
for ct_type in self.content_types:
yield {
'selected': smart_text(ct_type.id) == self.lookup_val,
'selected': smart_str(ct_type.id) == self.lookup_val,
'query_string': cl.get_query_string({self.lookup_kwarg: ct_type.id}),
'display': str(ct_type),
}
4 changes: 2 additions & 2 deletions moderation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def automoderate(self, user=None):
return status

def _get_moderation_status_and_reason(self, obj, user):
'''
"""
Returns tuple of moderation status and reason for auto moderation
'''
"""
reason = self.moderator.is_auto_reject(obj, user)
if reason:
return MODERATION_STATUS_REJECTED, reason
Expand Down
18 changes: 9 additions & 9 deletions moderation/signals.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import django.dispatch
from django.dispatch import Signal

pre_moderation = django.dispatch.Signal(providing_args=['instance', 'status'])
# Arguments: "instance", "status"
pre_moderation = Signal()

post_moderation = django.dispatch.Signal(providing_args={'instance', 'status'})
# Arguments: "instance", "status"
post_moderation = Signal()

pre_many_moderation = django.dispatch.Signal(
providing_args={'queryset', 'status', 'by', 'reason'}
)
# Arguments: "queryset", "status", "by", "reason"
pre_many_moderation = Signal()

post_many_moderation = django.dispatch.Signal(
providing_args={'queryset', 'status', 'by', 'reason'}
)
# Arguments: "queryset", "status", "by", "reason"
post_many_moderation = Signal()
22 changes: 11 additions & 11 deletions moderation/templates/moderation/html_diff.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{% spaceless %}
{% for operation in diff_operations %}
{% ifequal operation.operation "replace" %}
{% if operation.operation == "replace" %}
<del class="diff modified">{{ operation.deleted }}</del>
<ins class="diff modified">{{ operation.inserted }}</ins>
{% endifequal %}
{% ifequal operation.operation "delete" %}
{% endif %}

{% if operation.operation == "delete" %}
<del class="diff">{{ operation.deleted }}</del>
{% endifequal %}
{% ifequal operation.operation "insert" %}
{% endif %}

{% if operation.operation == "insert" %}
<ins class="diff">{{ operation.inserted }}</ins>
{% endifequal %}
{% ifequal operation.operation "equal" %}
{% endif %}

{% if operation.operation == "equal" %}
<span>{{ operation.inserted }}</span>
{% endifequal %}
{% endif %}
{% endfor %}
{% endspaceless %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Dear {{ user.first_name }}

Your {{ content_type }} entry has been {% ifequal moderated_object.status 0 %}rejected{% endifequal %}{% ifequal moderated_object.status 1 %}accepted{% endifequal %}.
Your {{ content_type }} entry has been {% if moderated_object.status == 0 %}rejected{% endif %}{% if moderated_object.status == 1 %}accepted{% endif %}.

{% if moderated_object.reason %}
Reason: {{ moderated_object.reason }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ content_type }} entry has been {% ifequal moderated_object.status 0 %}rejected{% endifequal %}{% ifequal moderated_object.status 1 %}accepted{% endifequal %}
{{ content_type }} entry has been {% if moderated_object.status == 0 %}rejected{% endif %}{% if moderated_object.status == 1 %}accepted{% endif %}
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
version = __import__('moderation').__version__

tests_require = [
'unittest2py3k',
'django>=2.2',
'django-webtest',
'webtest',
'mock',
'pillow',
]

Expand Down
10 changes: 5 additions & 5 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Test models used in django-moderations tests
Test models used in django-moderation tests
"""
from django.conf import settings
from django.contrib.auth.models import User
Expand All @@ -9,22 +9,22 @@

class UserProfile(models.Model):
user = models.ForeignKey(
getattr(settings, 'AUTH_USER_MODEL', 'auth.User'),
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='user_profile_set',
related_name='user_profiles',
)
description = models.TextField()
url = models.URLField()

def __str__(self):
return "%s - %s" % (self.user, self.url)
return f"{self.user} - {self.url}"


class SuperUserProfile(UserProfile):
super_power = models.TextField()

def __str__(self):
return "%s - %s - %s" % (self.user, self.url, self.super_power)
return f"{self.user} - {self.url} - {self.super_power}"


class ModelWithSlugField(models.Model):
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/unit/testadmin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mock
from unittest import mock

from django.contrib.admin.sites import site
from django.contrib.auth.models import Permission, User
from django.test.testcases import TestCase
Expand Down
5 changes: 1 addition & 4 deletions tests/tests/unit/testmoderator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from unittest.mock import Mock

from django.contrib.auth.models import Group, User
from django.core import mail
Expand Down Expand Up @@ -174,17 +175,13 @@ def test_auto_approve_for_groups_user_not_in_group(self):
self.assertFalse(self.moderator.is_auto_approve(self.obj, self.user))

def test_is_auto_reject_user_is_anonymous(self):
from mock import Mock

user = Mock()
user.is_anonymous = lambda: True
reason = self.moderator.is_auto_reject(self.obj, user)
self.assertTrue(reason)
self.assertEqual(reason, 'Auto-rejected: Anonymous User')

def test_is_auto_reject_user_is_not_anonymous(self):
from mock import Mock

user = Mock()
user.is_anonymous = lambda: False
self.assertFalse(self.moderator.is_auto_reject(self.obj, user))
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ envlist =
django2.2-py{36,37,38}
django3.1-py{36,37,38,39}
django3.2-py{36,37,38,39}
django4.0-py{38,39}


[testenv]
commands = python setup.py test

deps =
mock
pillow
unittest2py3k
django2.2: Django>=2.2,<3.0
django3.1: Django>=3.1,<3.2
django3.2: Django>=3.2,<4.0
django3.2: Django>=3.2,<4.0
django4.0: Django>=4.0,<4.1

0 comments on commit a9dbfc4

Please sign in to comment.