Skip to content

Commit

Permalink
Added ensure\>=1.0.4 which is compatible with Python 3.12. Fixed flak…
Browse files Browse the repository at this point in the history
…e8 warnings.
  • Loading branch information
Dmitri-Sintsov committed Dec 10, 2023
1 parent 9304b67 commit 51ec043
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions django_jinja_knockout/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ensure import ensure_annotations
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.db import models
Expand Down Expand Up @@ -62,6 +63,7 @@ def get_actions(self, request):


# http://stackoverflow.com/questions/5197280/for-a-django-model-how-can-i-get-the-django-admin-url-to-add-another-or-list-o
@ensure_annotations
def get_admin_url(model: models.Model, action='change'):
return reverse(
f"admin:{model._meta.app_label}_{model._meta.model_name}_{action}", args=[model.pk]
Expand Down
2 changes: 1 addition & 1 deletion django_jinja_knockout/forms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __new__(mcs, name, bases, attrs):
# Django >=4.2
if 'Meta' not in attrs:
attrs['Meta'] = type('Meta', bases, attrs)
setattr(attrs['Meta'], 'formfield_callback', display_model_formfield_callback)
attrs['Meta'].formfield_callback = display_model_formfield_callback
if 'template_dir' not in attrs:
attrs['template_dir'] = 'render/display/'
if 'layout_type' not in attrs:
Expand Down
4 changes: 2 additions & 2 deletions django_jinja_knockout/templatetags/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def __init__(self, environment):
environment.globals['url'] = self._url_reverse

@pass_context
def _url_reverse(self, context, name, *args, **kwargs):
return tpl.url(name, request=context.get('request'), *args, **kwargs)
def _url_reverse(self, context, name, **kwargs):
return tpl.url(name, request=context.get('request'), **kwargs)


extensions = {
Expand Down
2 changes: 1 addition & 1 deletion django_jinja_knockout/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def selenium_factory(cls):
# https://github.com/jsoma/selenium-github-actions/blob/main/scraper.py
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import ChromeType
from selenium.webdriver.chrome.service import Service
# from selenium.webdriver.chrome.service import Service
driver_kwargs['service_kwargs'] = {
'executable_path': ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()
}
Expand Down
3 changes: 3 additions & 0 deletions django_jinja_knockout/tpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lxml.html
from lxml import etree
from jinja2 import Undefined, DebugUndefined
from ensure import ensure_annotations
from datetime import date, datetime
from urllib.parse import urlencode

Expand Down Expand Up @@ -52,11 +53,13 @@ def limitstr(value, maxlen=50, suffix='...'):


# Insert separator to s between each specified left to right.
@ensure_annotations
def repeat_insert(s: str, separator: str = ' ', each: int = 3):
return ' '.join(s[i:i + each] for i in range(0, len(s), each))


# Insert separator to s between each specified right to left.
@ensure_annotations
def repeat_insert_rtl(s: str, separator: str = ' ', each: int = 3):
reversed_insert = repeat_insert(s[::-1], separator, each)
return reversed_insert[::-1]
Expand Down
5 changes: 5 additions & 0 deletions django_jinja_knockout/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import OrderedDict
from functools import wraps
from urllib.parse import urlparse
from ensure import ensure_annotations

from django.core.exceptions import ValidationError, FieldError
from django.conf import settings
Expand Down Expand Up @@ -221,16 +222,20 @@ class ViewmodelView(TemplateResponseMixin, ContextMixin, View):
def __init__(self, **kwargs):
super().__init__(**kwargs)

@ensure_annotations
def process_error_viewmodel(self, viewmodel: dict):
viewmodel.setdefault('view', 'alert_error')

@ensure_annotations
def process_error_vm_list(self, vms: vm_list):
for vm in vms:
self.process_error_viewmodel(vm)

@ensure_annotations
def process_success_viewmodel(self, viewmodel: dict):
viewmodel.setdefault('view', 'alert')

@ensure_annotations
def process_success_vm_list(self, vms: vm_list):
for vm in vms:
self.process_success_viewmodel(vm)
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Additional requirements go here
django>=3.2.0
django>=4.2.0
Jinja2
bleach
ensure>=1.0.4
lxml
sqlparse
sqlparse>0.4.3
pytz

0 comments on commit 51ec043

Please sign in to comment.