Skip to content

Commit

Permalink
chore: Django bump to <=5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomáš Daniel committed Apr 17, 2024
1 parent f8e0ae8 commit cb6b91a
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 51 deletions.
20 changes: 1 addition & 19 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,8 @@ jobs:
max-parallel: 4
matrix:
include:
- python-version: "3.7"
django-version: Django==3.1

- python-version: "3.8"
django-version: Django==3.1

- python-version: "3.7"
django-version: Django==3.2

- python-version: "3.8"
django-version: Django==3.2

- python-version: "3.9"
django-version: Django==3.2

- python-version: "3.10"
django-version: Django==3.2

- python-version: "3.11"
django-version: Django==3.2
django-version: Django==4.2

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions chamber/formatters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils import numberformat
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.safestring import mark_safe


Expand All @@ -16,6 +16,6 @@ def natural_number_with_currency(number, currency, show_decimal_place=True, use_
thousand_sep=' ',
force_grouping=True
),
force_text(currency)
force_str(currency)
)
return mark_safe(humanized.replace(' ', '\u00a0')) if use_nbsp else humanized
4 changes: 2 additions & 2 deletions chamber/forms/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from django.utils.translation import ugettext
from django.utils.translation import gettext

from chamber.config import settings

Expand Down Expand Up @@ -38,7 +38,7 @@ class PriceField(DecimalField):
widget = PriceNumberInput

def __init__(self, *args, **kwargs):
currency = kwargs.pop('currency', ugettext('CZK'))
currency = kwargs.pop('currency', gettext('CZK'))
kwargs.setdefault('max_digits', 10)
kwargs.setdefault('decimal_places', 2)
if 'widget' not in kwargs:
Expand Down
8 changes: 4 additions & 4 deletions chamber/forms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.core.exceptions import ValidationError
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext
from django.utils.translation import gettext


class RestrictedFileValidator:
Expand All @@ -15,7 +15,7 @@ def __init__(self, max_upload_size):
def __call__(self, data):
if data.size > self.max_upload_size:
raise ValidationError(
ugettext('Please keep filesize under {max}. Current filesize {current}').format(
gettext('Please keep filesize under {max}. Current filesize {current}').format(
max=filesizeformat(self.max_upload_size),
current=filesizeformat(data.size)
)
Expand All @@ -33,7 +33,7 @@ def __call__(self, data):
extension_mime_type = mimetypes.guess_type(data.name)[0]

if extension_mime_type not in self.content_types:
raise ValidationError(ugettext('Extension of file name is not allowed'))
raise ValidationError(gettext('Extension of file name is not allowed'))

return data

Expand All @@ -48,6 +48,6 @@ def __call__(self, data):
mime_type = magic.from_buffer(data.read(2048), mime=True)
data.seek(0)
if mime_type not in self.content_types:
raise ValidationError(ugettext('File content was evaluated as not supported file type'))
raise ValidationError(gettext('File content was evaluated as not supported file type'))

return data
2 changes: 1 addition & 1 deletion chamber/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db.models.manager import BaseManager
from django.db.models.base import ModelBase
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.utils.functional import cached_property

from chamber.exceptions import PersistenceException
Expand Down
14 changes: 7 additions & 7 deletions chamber/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from django.db import models
from django.db.models import FileField as OriginFileField
from django.db.models.fields import DecimalField as OriginDecimalField
from django.utils.encoding import force_text
from django.utils.translation import ugettext
from django.utils.encoding import force_str
from django.utils.translation import gettext

from chamber.config import settings
from chamber.forms import fields as chamber_fields
Expand Down Expand Up @@ -71,7 +71,7 @@ def generate_filename(self, instance, filename):
"""
from unidecode import unidecode

return super().generate_filename(instance, unidecode(force_text(filename)))
return super().generate_filename(instance, unidecode(force_str(filename)))


class FileField(RestrictedFileFieldMixin, OriginFileField):
Expand Down Expand Up @@ -133,12 +133,12 @@ def clean(self, value, model_instance):

def _raise_error_if_value_should_be_empty(self, value, subvalue):
if self.enum and subvalue not in self.enum.categories and value is not None:
raise ValidationError(ugettext('Value must be empty'))
raise ValidationError(gettext('Value must be empty'))

def _raise_error_if_value_not_allowed(self, value, subvalue, model_instance):
allowed_values = self.enum.get_allowed_states(getattr(model_instance, self.supchoices_field_name))
if subvalue in self.enum.categories and value not in allowed_values:
raise ValidationError(ugettext('Allowed choices are {}.').format(
raise ValidationError(gettext('Allowed choices are {}.').format(
', '.join(('{} ({})'.format(*(self.enum.get_label(val), val)) for val in allowed_values))
))

Expand Down Expand Up @@ -169,7 +169,7 @@ def validate(self, value, model_instance):
if ((self.name in model_instance.changed_fields or model_instance.is_adding) and
value not in allowed_next_values):
raise ValidationError(
ugettext('Allowed choices are {}.').format(
gettext('Allowed choices are {}.').format(
', '.join(('{} ({})'.format(*(self.enum.get_label(val), val)) for val in allowed_next_values))))


Expand All @@ -184,7 +184,7 @@ class EnumSequenceCharField(EnumSequenceFieldMixin, models.CharField):
class PriceField(DecimalField):

def __init__(self, *args, **kwargs):
self.currency = kwargs.pop('currency', ugettext('CZK'))
self.currency = kwargs.pop('currency', gettext('CZK'))
super().__init__(*args, **{
'decimal_places': 2,
'max_digits': 10,
Expand Down
6 changes: 3 additions & 3 deletions chamber/models/humanized_helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.utils.translation import ugettext
from django.utils.translation import gettext

from chamber.formatters import natural_number_with_currency

Expand All @@ -7,5 +7,5 @@ def price_humanized(value, inst, currency=None):
"""
Return a humanized price
"""
return (natural_number_with_currency(value, ugettext('CZK') if currency is None else currency) if value is not None
else ugettext('(None)'))
return (natural_number_with_currency(value, gettext('CZK') if currency is None else currency) if value is not None
else gettext('(None)'))
4 changes: 2 additions & 2 deletions chamber/utils/http.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from collections import OrderedDict

from django.http.request import QueryDict
from django.utils.encoding import force_text
from django.utils.encoding import force_str


def query_string_from_dict(qs_dict):
qs_prepared_dict = OrderedDict()
for key, val in qs_dict.items():
if isinstance(val, list):
val = '[%s]' % ','.join([force_text(v) for v in val])
val = '[%s]' % ','.join([force_str(v) for v in val])
qs_prepared_dict[key] = val

qdict = QueryDict('').copy()
Expand Down
2 changes: 1 addition & 1 deletion chamber/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (0, 6, 19)
VERSION = (0, 7, 1)


def get_version():
Expand Down
2 changes: 1 addition & 1 deletion example/dj/apps/test_chamber/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth.models import AbstractBaseUser
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from chamber import models as chamber_models
from chamber.models import fields as chamber_fields
Expand Down
10 changes: 5 additions & 5 deletions example/dj/apps/test_chamber/tests/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.core.exceptions import ValidationError
from django.core.files import File
from django.test import TransactionTestCase
from django.utils.translation import ugettext_lazy
from django.utils.translation import gettext_lazy

from chamber.exceptions import PersistenceException
from chamber.forms import fields as form_fields
Expand Down Expand Up @@ -130,20 +130,20 @@ def test_should_validate_positive_price_field(self):

def test_should_check_price_form_field(self):
field = TestFieldsModel._meta.get_field('price') # pylint: disable=W0212
assert_equal(ugettext_lazy('EUR'), field.currency)
assert_equal(gettext_lazy('EUR'), field.currency)
form_field = field.formfield()
assert_true(isinstance(form_field.widget, form_fields.PriceNumberInput))
assert_equal(field.currency, form_field.widget.placeholder)

def test_should_check_total_price_form_field(self):
field = TestFieldsModel._meta.get_field('total_price') # pylint: disable=W0212
assert_equal(ugettext_lazy('CZK'), field.currency)
assert_equal(gettext_lazy('CZK'), field.currency)
form_field = field.formfield()
assert_true(isinstance(form_field.widget, form_fields.PriceNumberInput))

model_fields = (
('price', ugettext_lazy('EUR'), {'max_digits', 'decimal_places'}),
('total_price', ugettext_lazy('CZK'), {'max_digits', 'decimal_places', 'validators'}),
('price', gettext_lazy('EUR'), {'max_digits', 'decimal_places'}),
('total_price', gettext_lazy('CZK'), {'max_digits', 'decimal_places', 'validators'}),
)

@data_consumer(model_fields)
Expand Down
2 changes: 1 addition & 1 deletion example/dj/backend_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import django

from django.conf.urls import url
from django.urls import re_path as url

from test_chamber import views # pylint: disable=E0401

Expand Down
2 changes: 1 addition & 1 deletion example/dj/frontend_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import django

from django.conf.urls import url
from django.urls import re_path as url

from test_chamber import views # pylint: disable=E0401

Expand Down
2 changes: 1 addition & 1 deletion example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django<=3.2
Django~=4.2
flake8
freezegun==1.1.0
coveralls
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'Framework :: Django',
],
install_requires=[
'django>=2.2, <4.0',
'django>=4.2',
'Unidecode>=1.1.1',
'pyprind>=2.11.2',
'python-magic>=0.4.27'
Expand Down

0 comments on commit cb6b91a

Please sign in to comment.