diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-05-18 16:23:02 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:20:58 +0100 |
commit | 07e3e2e9c3da9f05634a45f65723504c229f2baa (patch) | |
tree | 7e3ea0f3306eea50e9f95a7c90b397c5515e97fb /ishtar_common | |
parent | 3b671732319aa14f194821a8f547ae280e1e0648 (diff) | |
download | Ishtar-07e3e2e9c3da9f05634a45f65723504c229f2baa.tar.bz2 Ishtar-07e3e2e9c3da9f05634a45f65723504c229f2baa.zip |
Migration to Django 2.2 - many fixes
- remove redondant permissions
- fix missing kwargs for widget and form fields
- fix default to callable for model field
- quick and dirty fix for datepicker
- is_authenticated() -> is_authenticated
- fix registration urls
- remove six usage (no more python2)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/admin.py | 9 | ||||
-rw-r--r-- | ishtar_common/backend.py | 2 | ||||
-rw-r--r-- | ishtar_common/management/commands/media_clean_unused.py | 3 | ||||
-rw-r--r-- | ishtar_common/models.py | 6 | ||||
-rw-r--r-- | ishtar_common/models_common.py | 8 | ||||
-rw-r--r-- | ishtar_common/templates/account_activation_email.txt | 2 | ||||
-rw-r--r-- | ishtar_common/templates/navbar.html | 6 | ||||
-rw-r--r-- | ishtar_common/templates/registration/activate.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/registration/activation_complete.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/registration/login.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/registration/password_reset_complete.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/registration/password_reset_email.html | 2 | ||||
-rw-r--r-- | ishtar_common/templatetags/ishtar_helpers.py | 2 | ||||
-rw-r--r-- | ishtar_common/templatetags/window_field.py | 2 | ||||
-rw-r--r-- | ishtar_common/urls_registration.py | 34 | ||||
-rw-r--r-- | ishtar_common/utils.py | 5 | ||||
-rw-r--r-- | ishtar_common/views.py | 2 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 27 |
18 files changed, 78 insertions, 40 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index 752594616..69f8ec92c 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -61,7 +61,8 @@ from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render from django.urls import reverse from django.utils.decorators import method_decorator -from django.utils.text import slugify, mark_safe +from django.utils.text import slugify +from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from django.views.decorators.csrf import csrf_protect @@ -105,7 +106,7 @@ ISHTAR_FORMS = [ class ImportGenericForm(forms.Form): csv_file = forms.FileField( - _("CSV file"), + label=_("CSV file"), help_text=_("Only unicode encoding is managed - convert your" " file first"), ) @@ -709,7 +710,7 @@ class ImportActionAdmin(admin.ModelAdmin): class ImportGeoJsonForm(forms.Form): json_file = forms.FileField( - _("Geojson file"), + label=_("Geojson file"), help_text=_( "Only unicode encoding is managed - convert your" " file first. The file must be a geojson file or a zip " @@ -936,7 +937,7 @@ class ImportGEOJSONActionAdmin(object): class ImportJSONForm(forms.Form): json_file = forms.FileField( - _("Zipped JSON file"), + label=_("Zipped JSON file"), help_text=_("Import from a zipped JSON file generated by Ishtar"), ) diff --git a/ishtar_common/backend.py b/ishtar_common/backend.py index e3d53c80e..00f90f444 100644 --- a/ishtar_common/backend.py +++ b/ishtar_common/backend.py @@ -33,7 +33,7 @@ class ObjectPermBackend(ModelBackend): supports_anonymous_user = True def has_perm(self, user_obj, perm, model=None, obj=None, session=None): - if not user_obj.is_authenticated(): + if not user_obj.is_authenticated: return False if not model: # let it manage by the default backend diff --git a/ishtar_common/management/commands/media_clean_unused.py b/ishtar_common/management/commands/media_clean_unused.py index 33237c1c7..f09cc9e9a 100644 --- a/ishtar_common/management/commands/media_clean_unused.py +++ b/ishtar_common/management/commands/media_clean_unused.py @@ -7,7 +7,6 @@ https://github.com/akolpakov/django-unused-media import os -import six.moves from django.conf import settings from django.core.management.base import BaseCommand @@ -89,7 +88,7 @@ class Command(BaseCommand): # ask user question = 'Are you sure you want to remove {} unused files? (y/N)'.format(len(unused_media)) - if six.moves.input(question).upper() != 'Y': + if input(question).upper() != 'Y': self.info('Interrupted by user. Exit.') return diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 6196e1efe..b4d6eb0f2 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1756,7 +1756,7 @@ class UserDashboard: class StatsCache(models.Model): model = models.CharField(_("Model name"), max_length=200) model_pk = models.IntegerField(_("Associated primary key")) - values = JSONField(default={}, blank=True) + values = JSONField(default=dict, blank=True) updated = models.DateTimeField(default=datetime.datetime.now) update_requested = models.DateTimeField(blank=True, null=True) @@ -2407,7 +2407,6 @@ class Organization(Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, Main verbose_name = _("Organization") verbose_name_plural = _("Organizations") permissions = ( - ("view_organization", "Can view all Organizations"), ("view_own_organization", "Can view own Organization"), ("add_own_organization", "Can add own Organization"), ("change_own_organization", "Can change own Organization"), @@ -2697,7 +2696,6 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem): GinIndex(fields=["data"]), ] permissions = ( - ("view_person", "Can view all Persons"), ("view_own_person", "Can view own Person"), ("add_own_person", "Can add own Person"), ("change_own_person", "Can change own Person"), @@ -3401,7 +3399,6 @@ class Author(FullSearch): verbose_name_plural = _("Authors") ordering = ("author_type__order", "person__name") permissions = ( - ("view_author", "Can view all Authors"), ("view_own_author", "Can view own Author"), ("add_own_author", "Can add own Author"), ("change_own_author", "Can change own Author"), @@ -4045,7 +4042,6 @@ class Document( verbose_name_plural = _("Documents") ordering = ("title",) permissions = ( - ("view_document", ugettext("Can view all Documents")), ("view_own_document", ugettext("Can view own Document")), ("add_own_document", ugettext("Can add own Document")), ("change_own_document", ugettext("Can change own Document")), diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 6b137f2fd..66cf0c5e5 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -31,7 +31,7 @@ from django.core.cache import cache from django.core.exceptions import ObjectDoesNotExist from django.core.files import File from django.core.serializers import serialize -from django.urls import reverse +from django.urls import reverse, NoReverseMatch from django.core.validators import validate_slug from django.db import connection from django.db.models import Q, Count, Max @@ -1002,7 +1002,7 @@ class Imported(models.Model): class JsonData(models.Model, CachedGen): - data = JSONField(default={}, blank=True) + data = JSONField(default=dict, blank=True) class Meta: abstract = True @@ -1320,7 +1320,7 @@ class BaseHistorizedItem( null=True, ) last_modified = models.DateTimeField(blank=True, default=datetime.datetime.now) - history_m2m = JSONField(default={}, blank=True) + history_m2m = JSONField(default=dict, blank=True) need_update = models.BooleanField(verbose_name=_("Need update"), default=False) locked = models.BooleanField( verbose_name=_("Item locked for edition"), default=False @@ -1727,7 +1727,7 @@ class OwnPerms(object): """ if not replace_query: replace_query = {} - if hasattr(user, "is_authenticated") and not user.is_authenticated(): + if hasattr(user, "is_authenticated") and not user.is_authenticated: returned = cls.objects.filter(pk__isnull=True) if values: returned = [] diff --git a/ishtar_common/templates/account_activation_email.txt b/ishtar_common/templates/account_activation_email.txt index 7498a86c7..fbd90ad58 100644 --- a/ishtar_common/templates/account_activation_email.txt +++ b/ishtar_common/templates/account_activation_email.txt @@ -5,7 +5,7 @@ * {% trans "Login:" %} {{login}} * {% trans "Password:" %} {{password}} -{% trans "You can log in here:" %} {{scheme}}://{{site}}{% url "auth_login" %} +{% trans "You can log in here:" %} {{scheme}}://{{site}}{% url "login" %} {% trans "Thank you for you interest in the project." %} diff --git a/ishtar_common/templates/navbar.html b/ishtar_common/templates/navbar.html index bc244973c..d8e368bbc 100644 --- a/ishtar_common/templates/navbar.html +++ b/ishtar_common/templates/navbar.html @@ -30,17 +30,17 @@ <a class="dropdown-item" href="{% url 'profile' %}"> {% trans "Profile" %} </a> - <a class="dropdown-item" href="{% url 'auth_password_change' %}"> + <a class="dropdown-item" href="{% url 'password_change' %}"> {% trans "Change password" %} </a> - <a class="dropdown-item" href="{% url 'auth_logout' %}"> + <a class="dropdown-item" href="{% url 'logout' %}"> {% trans "Log out" %} </a> </div> </li> {% else %} <li class="nav-item"> - <a class="nav-link" href="{% url 'auth_login' %}">{% trans "Log in" %}</a> + <a class="nav-link" href="{% url 'login' %}">{% trans "Log in" %}</a> </li> {% endif %} {% if LANGUAGES|length > 1 %} diff --git a/ishtar_common/templates/registration/activate.html b/ishtar_common/templates/registration/activate.html index 0dcbccc00..261b38b1f 100644 --- a/ishtar_common/templates/registration/activate.html +++ b/ishtar_common/templates/registration/activate.html @@ -7,7 +7,7 @@ <p>{% trans "Account successfully activated" %}</p> -<p><a href="{% url auth_login %}">{% trans "Log in" %}</a></p> +<p><a href="{% url 'login' %}">{% trans "Log in" %}</a></p> {% else %} diff --git a/ishtar_common/templates/registration/activation_complete.html b/ishtar_common/templates/registration/activation_complete.html index 7db8c186e..dbe6c15ed 100644 --- a/ishtar_common/templates/registration/activation_complete.html +++ b/ishtar_common/templates/registration/activation_complete.html @@ -5,7 +5,7 @@ <div class='info'> <p>{% trans "You may now login with your username and password." %}</p> {% if not user.is_authenticated %} -<a href="{% url "auth_login" %}">{% trans "Login now" %}</a> +<a href="{% url 'login' %}">{% trans "Login now" %}</a> {% else %} <a href="/">{% trans "Home" %}</a> {% endif %} diff --git a/ishtar_common/templates/registration/login.html b/ishtar_common/templates/registration/login.html index 4d8e2f37b..452ef91ef 100644 --- a/ishtar_common/templates/registration/login.html +++ b/ishtar_common/templates/registration/login.html @@ -35,7 +35,7 @@ <hr/> <div class="row justify-content-center"> <div class="col-md-6"> - <small class="text-secondary">{% trans "Forgot password?" %} <a href="{% url 'auth_password_reset' %}">{% trans "Reset it" %}</a> – + <small class="text-secondary">{% trans "Forgot password?" %} <a href="{% url 'password_reset' %}">{% trans "Reset it" %}</a> – {% trans "Not member?" %} <a href="{% url 'registration_register' %}">{% trans "Register" %}</a></small> </div> </div> diff --git a/ishtar_common/templates/registration/password_reset_complete.html b/ishtar_common/templates/registration/password_reset_complete.html index dfa3ce682..053270f78 100644 --- a/ishtar_common/templates/registration/password_reset_complete.html +++ b/ishtar_common/templates/registration/password_reset_complete.html @@ -5,6 +5,6 @@ <div class='info'> <p>{% trans "Password reset successfully" %}</p> -<p><a href="{% url auth_login %}">{% trans "Log in" %}</a></p> +<p><a href="{% url 'login' %}">{% trans "Log in" %}</a></p> </div> {% endblock %} diff --git a/ishtar_common/templates/registration/password_reset_email.html b/ishtar_common/templates/registration/password_reset_email.html index a55c86958..05612cf58 100644 --- a/ishtar_common/templates/registration/password_reset_email.html +++ b/ishtar_common/templates/registration/password_reset_email.html @@ -1,5 +1,5 @@ {% load i18n %} {% blocktrans %}Reset password at {{ site_name }}{% endblocktrans %}: {% block reset_link %} -{{ protocol }}://{{ domain }}{% url auth_password_reset_confirm uidb36=uid, token=token %} +{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb36=uid, token=token %} {% endblock %} diff --git a/ishtar_common/templatetags/ishtar_helpers.py b/ishtar_common/templatetags/ishtar_helpers.py index 375f80ae7..ade89bdc0 100644 --- a/ishtar_common/templatetags/ishtar_helpers.py +++ b/ishtar_common/templatetags/ishtar_helpers.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from django.template import Library -from django.utils.text import mark_safe +from django.utils.safestring import mark_safe register = Library() diff --git a/ishtar_common/templatetags/window_field.py b/ishtar_common/templatetags/window_field.py index 0a1914556..0e6b4e0d6 100644 --- a/ishtar_common/templatetags/window_field.py +++ b/ishtar_common/templatetags/window_field.py @@ -3,7 +3,7 @@ import os from django import template from django.template import loader from django.utils.translation import ugettext as _ -from django.utils.text import mark_safe +from django.utils.safestring import mark_safe from ishtar_common.templatetags.link_to_window import link_to_window diff --git a/ishtar_common/urls_registration.py b/ishtar_common/urls_registration.py new file mode 100644 index 000000000..4b9e85289 --- /dev/null +++ b/ishtar_common/urls_registration.py @@ -0,0 +1,34 @@ +from django.conf.urls import include, url +from django.views.generic.base import TemplateView + +from django_registration import views + + +urlpatterns = [ + url(r'^accounts/activate/complete/$', + TemplateView.as_view( + template_name='registration/activation_complete.html' + ), + name='registration_activation_complete'), + # Activation keys get matched by \w+ instead of the more specific + # [a-fA-F0-9]{40} because a bad activation key should still get to + # the view; that way it can return a sensible "invalid key" + # message instead of a confusing 404. + url(r'^accounts/activate/(?P<activation_key>\w+)/$', + views.ActivationView.as_view(), + name='registration_activate'), + url(r'^accounts/register/$', + views.RegistrationView.as_view(), + name='registration_register'), + url(r'^accounts/register/complete/$', + TemplateView.as_view( + template_name='registration/registration_complete.html' + ), + name='registration_complete'), + url(r'^accounts/register/closed/$', + TemplateView.as_view( + template_name='registration/registration_closed.html' + ), + name='registration_disallowed'), + url("^accounts/", include('django.contrib.auth.urls')), +]
\ No newline at end of file diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index cbf4242b2..3a349c04b 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -33,7 +33,6 @@ import re import requests from secretary import Renderer as MainSecretaryRenderer, UndefinedSilently import shutil -import six import subprocess import sys import tempfile @@ -227,7 +226,7 @@ def check_model_access_control(request, model, available_perms=None): """ own = True # more restrictive by default allowed = False - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return allowed, own if not available_perms: @@ -1797,7 +1796,7 @@ def get_all_media(exclude=None, debug=False): exclude = [] media = set() - full_dirs = list(os.walk(six.text_type(settings.MEDIA_ROOT))) + full_dirs = list(os.walk(settings.MEDIA_ROOT)) ln_full = len(full_dirs) for idx_main, full_dir in enumerate(full_dirs): root, dirs, files = full_dir diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 24ef044bb..81e6d5e05 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -44,7 +44,7 @@ from django.http import ( JsonResponse, ) from django.shortcuts import redirect, render, get_object_or_404 -from django.urls import reverse +from django.urls import reverse, NoReverseMatch from django.utils.decorators import method_decorator from django.utils.translation import ugettext, ugettext_lazy as _ from django.views.generic import ListView, TemplateView, View diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index bab6b3e00..e444261d9 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -71,11 +71,11 @@ class SelectReadonly(forms.Select): label = str(i) yield (i.pk, label) - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None, choices=(), renderer=None): if value: self.choices = list(self.get_choices(value)) value = self.choices[0][0] - return super(SelectReadonly, self).render(name, value, attrs) + return super(SelectReadonly, self).render(name, value, attrs, renderer=None) class SelectReadonlyField(forms.ChoiceField): @@ -98,7 +98,14 @@ class SelectReadonlyField(forms.ChoiceField): self.available = kwargs.pop("available") widget = SelectReadonly(model=self.model, available=self.available) super(SelectReadonlyField, self).__init__( - choices, required, widget, label, initial, help_text, *args, **kwargs + choices=choices, + required=required, + widget=widget, + label=label, + initial=initial, + help_text=help_text, + *args, + **kwargs ) def get_q(self): @@ -132,7 +139,7 @@ class Select2DynamicBase(Select2Media): """ MULTIPLE = False - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None, choices=(), renderer=None): choices = choices or getattr(self, "choices", []) if value: values = [value] @@ -170,7 +177,7 @@ class Select2DynamicBase(Select2Media): if self.MULTIPLE: options.append("multiple: 'true'") - html = super(Select2DynamicBase, self).render(name, value, attrs) + html = super(Select2DynamicBase, self).render(name, value, attrs, renderer=None) html += """<script type="text/javascript"> $(document).ready(function() {{ $("#id_{}").select2({{ {} }}); @@ -245,7 +252,7 @@ class Select2Base(Select2Media): for i in self.get_q().all(): yield (i.pk, str(i)) - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None, choices=(), renderer=None): self.remote = str(self.remote) if self.remote in ("None", "false"): # test on lazy object is buggy... so we have this ugly test @@ -328,7 +335,7 @@ class Select2Base(Select2Media): """+</a></span></div>""".format(url_new, self.model.SLUG) ) - html += super(Select2Base, self).render(name, value, attrs) + html += super(Select2Base, self).render(name, value, attrs, renderer=None) html += new html += """<script type="text/javascript"> $(document).ready(function() {{ @@ -355,12 +362,14 @@ class CheckboxSelectMultiple(CheckboxSelectMultipleBase): TODO: test and remove (test case: treatment type not keep on modif) """ - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None, choices=(), renderer=None): if type(value) in (str, str): value = value.split(",") if not isinstance(value, (list, tuple)): value = [value] - return super(CheckboxSelectMultiple, self).render(name, value, attrs) + return super(CheckboxSelectMultiple, self).render( + name, value, attrs, renderer=None + ) class Select2BaseField(object): |