Skip to content

Commit

Permalink
Removes providing_args kwargs for django 4x support
Browse files Browse the repository at this point in the history
  • Loading branch information
adepeter committed Aug 15, 2022
1 parent 92f6052 commit 244bd25
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ __pycache__/
# C extensions
*.so

# django project
django_violation_proj/

# Distribution / packaging
.Python
build/
Expand Down Expand Up @@ -38,6 +41,8 @@ MANIFEST
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
Pipfile.lock
Pipfile

# Unit test / coverage reports
htmlcov/
Expand Down
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_violation_proj.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Django>=3.1
Django>=3.1<=5.0
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = attr: violation.__version__
description = django-violation is a reusable Django application for reporting illicit/improper acts.
long_description = file: README.md
long_description_content_type = text/markdown
author = Oluwaseun Peter
author = Peter Oluwaseun
author_email = adepeter26@gmail.com
url = https://github.com/adepeter/django-violations
license = MIT
Expand All @@ -14,6 +14,8 @@ classifiers =
Framework :: Django
Framework :: Django :: 3.0
Framework :: Django :: 3.1
Framework :: Django :: 4.0
Framework :: Django :: 4.1
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Expand All @@ -23,6 +25,8 @@ classifiers =
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
project_urls =
Source = https://github.com/adepeter/django-violations
Tracker = https://github.com/adepeter/django-violations/issues
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist =
flake8
isort
py35-django222
py{36,37,38}-django{111, 22, 30, master}
py{36,37,38,39}-django{111, 22, 30, 40, 41, master}
docs

[travis]
Expand All @@ -14,12 +14,14 @@ python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39

[testenv]
deps =
django111: Django~=1.11.0
django22: Django>=2.2<3.0
django30: Django>=3.0<3.1
django40: Django>=4.0<5.0
djangomaster: https://github.com/django/django/archive/master.tar.gz#egg=django
coverage
commands =
Expand Down
2 changes: 1 addition & 1 deletion violation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = (1, 1, 6)
VERSION = (1, 2, 0)
__version__ = ".".join(str(i) for i in VERSION)
6 changes: 2 additions & 4 deletions violation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ def last_modified(self, obj):

def rules_violated(self, obj):
rules = obj.rules.all()
return ('%s' % ', '.join([rule.name for rule in rules]))
return f"{', '.join([rule.name for rule in rules])}"

short_description = 'Violated rules'

def get_readonly_fields(self, request, obj=None):
if obj is not None:
return self.list_display
return []
return self.list_display if obj is not None else []
20 changes: 8 additions & 12 deletions violation/forms/violation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@ def __init__(self, *args, **kwargs):

def get_queryset(self):
if self.categories is None:
if self.queryset is not None:
queryset = self.queryset
if isinstance(self.queryset, QuerySet):
queryset = queryset.all()
else:
raise NotSupportedError('%s is actually not a QuerySet' % self.queryset)
else:
if self.queryset is None:
raise ImproperlyConfigured('self.categories or self.queryset is needed to load this form')
queryset = self.queryset
if isinstance(self.queryset, QuerySet):
queryset = queryset.all()
else:
raise NotSupportedError(f'{self.queryset} is actually not a QuerySet')
else:
queryset = Rule.objects.filter(
category__in=[category for category in self.categories]
)
queryset = Rule.objects.filter(category__in=list(self.categories))
return queryset

def clean_rules(self):
Expand All @@ -65,8 +62,7 @@ def clean_rules(self):
report an item more than ones
"""
cleaned_rules = self.cleaned_data['rules']
check_spam_violations = self.check_spam_rules(cleaned_rules, self.request.user)
if check_spam_violations:
if check_spam_violations := self.check_spam_rules(cleaned_rules, self.request.user):
raise forms.ValidationError(
_('A rule cannot be reported twice for violation'),
code='multiple_violations'
Expand Down
27 changes: 27 additions & 0 deletions violation/migrations/0002_alter_rule_id_alter_violation_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.1 on 2022-08-15 22:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("violation", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="rule",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
migrations.AlterField(
model_name="violation",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
]
2 changes: 1 addition & 1 deletion violation/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.dispatch import Signal

report_handler = Signal(providing_args=['violation', 'violator'])
report_handler = Signal()

0 comments on commit 244bd25

Please sign in to comment.