Merge pull request #7 from ribaguifi/dev/django2.1

Upgrade to Django 2.1
This commit is contained in:
Santiago L 2021-05-11 13:06:52 +02:00 committed by GitHub
commit 18a41d507b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 38 deletions

View File

@ -1,12 +1,12 @@
from rest_framework import status from rest_framework import status
from rest_framework.decorators import detail_route from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
from .serializers import SetPasswordSerializer from .serializers import SetPasswordSerializer
class SetPasswordApiMixin(object): class SetPasswordApiMixin(object):
@detail_route(methods=['post'], serializer_class=SetPasswordSerializer) @action(detail=True, methods=['post'], serializer_class=SetPasswordSerializer)
def set_password(self, request, pk): def set_password(self, request, pk):
obj = self.get_object() obj = self.get_object()
data = request.data data = request.data

View File

@ -1,6 +1,6 @@
from django.http import HttpResponse from django.http import HttpResponse
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.decorators import detail_route from rest_framework.decorators import action
from orchestra.api import router, LogApiMixin from orchestra.api import router, LogApiMixin
from orchestra.contrib.accounts.api import AccountApiMixin from orchestra.contrib.accounts.api import AccountApiMixin
@ -15,7 +15,7 @@ class BillViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
queryset = Bill.objects.all() queryset = Bill.objects.all()
serializer_class = BillSerializer serializer_class = BillSerializer
@detail_route(methods=['get']) @action(detail=True, methods=['get'])
def document(self, request, pk): def document(self, request, pk):
bill = self.get_object() bill = self.get_object()
content_type = request.META.get('HTTP_ACCEPT') content_type = request.META.get('HTTP_ACCEPT')

View File

@ -1,5 +1,5 @@
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.decorators import detail_route from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
from orchestra.api import router from orchestra.api import router
@ -19,7 +19,7 @@ class DomainViewSet(AccountApiMixin, viewsets.ModelViewSet):
qs = super(DomainViewSet, self).get_queryset() qs = super(DomainViewSet, self).get_queryset()
return qs.prefetch_related('records') return qs.prefetch_related('records')
@detail_route() @action(detail=True)
def view_zone(self, request, pk=None): def view_zone(self, request, pk=None):
domain = self.get_object() domain = self.get_object()
return Response({ return Response({

View File

@ -1,5 +1,5 @@
from rest_framework import viewsets, mixins from rest_framework import viewsets, mixins
from rest_framework.decorators import detail_route from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
from orchestra.api import router, LogApiMixin from orchestra.api import router, LogApiMixin
@ -13,13 +13,13 @@ class TicketViewSet(LogApiMixin, viewsets.ModelViewSet):
queryset = Ticket.objects.all() queryset = Ticket.objects.all()
serializer_class = TicketSerializer serializer_class = TicketSerializer
@detail_route() @action(detail=True)
def mark_as_read(self, request, pk=None): def mark_as_read(self, request, pk=None):
ticket = self.get_object() ticket = self.get_object()
ticket.mark_as_read_by(request.user) ticket.mark_as_read_by(request.user)
return Response({'status': 'Ticket marked as read'}) return Response({'status': 'Ticket marked as read'})
@detail_route() @action(detail=True)
def mark_as_unread(self, request, pk=None): def mark_as_unread(self, request, pk=None):
ticket = self.get_object() ticket = self.get_object()
ticket.mark_as_unread_by(request.user) ticket.mark_as_unread_by(request.user)

View File

@ -1,3 +1,7 @@
from django.utils.text import format_lazy
from django.utils.translation import ugettext_lazy
def get_chunks(porders, ini, end, ix=0): def get_chunks(porders, ini, end, ix=0):
if ix >= len(porders): if ix >= len(porders):
return [[ini, end, []]] return [[ini, end, []]]
@ -130,3 +134,16 @@ def compensate(order, compensations):
for __, compensation in ordered_intersections: for __, compensation in ordered_intersections:
remaining_compensations.append(compensation) remaining_compensations.append(compensation)
return remaining_compensations, applied_compensations return remaining_compensations, applied_compensations
def get_rate_methods_help_text(rate_class):
method_help_texts = [
format_lazy('{}' * 4, *['<br>&nbsp;&nbsp;', method.verbose_name, ': ', method.help_text])
for method in rate_class.get_methods().values()
]
prefix = ugettext_lazy("Algorithm used to interprete the rating table.")
help_text_items = [prefix] + method_help_texts
return format_lazy(
'{}' * len(help_text_items),
*help_text_items
)

View File

@ -1,18 +1,20 @@
import calendar import calendar
import decimal import decimal
from orchestra.contrib.services import helpers
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.apps import apps from django.apps import apps
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.module_loading import autodiscover_modules from django.utils.module_loading import autodiscover_modules
from django.utils.translation import string_concat, ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from orchestra.core import caches, validators from orchestra.core import caches, validators
from orchestra.utils.python import import_class from orchestra.utils.python import import_class
from . import settings from . import settings
from .handlers import ServiceHandler from .handlers import ServiceHandler
from .helpers import get_rate_methods_help_text
autodiscover_modules('handlers') autodiscover_modules('handlers')
@ -145,13 +147,12 @@ class Service(models.Model):
(ANUAL, _("Anual data")), (ANUAL, _("Anual data")),
), ),
default=BILLING_PERIOD) default=BILLING_PERIOD)
rate_algorithm = models.CharField(_("rate algorithm"), max_length=64, rate_algorithm = models.CharField(
_("rate algorithm"), max_length=64,
choices=rate_class.get_choices(), choices=rate_class.get_choices(),
default=rate_class.get_default(), default=rate_class.get_default(),
help_text=string_concat(_("Algorithm used to interprete the rating table."), *[ help_text=get_rate_methods_help_text(rate_class),
string_concat('<br>&nbsp;&nbsp;', method.verbose_name, ': ', method.help_text) )
for name, method in rate_class.get_methods().items()
]))
on_cancel = models.CharField(_("on cancel"), max_length=16, on_cancel = models.CharField(_("on cancel"), max_length=16,
help_text=_("Defines the cancellation behaviour of this service."), help_text=_("Defines the cancellation behaviour of this service."),
choices=( choices=(

View File

@ -1,4 +1,4 @@
from django.utils.translation import string_concat from django.utils.text import format_lazy
from ..utils.python import AttrDict from ..utils.python import AttrDict
@ -36,7 +36,8 @@ class Register(object):
if 'verbose_name' not in kwargs: if 'verbose_name' not in kwargs:
raise KeyError("%s verbose_name is required for views" % view_name) raise KeyError("%s verbose_name is required for views" % view_name)
if 'verbose_name_plural' not in kwargs: if 'verbose_name_plural' not in kwargs:
kwargs['verbose_name_plural'] = string_concat(kwargs['verbose_name'], 's') kwargs['verbose_name_plural'] = format_lazy('{}' * 2, *[kwargs['verbose_name'], 's'])
self.register(view_name, **kwargs) self.register(view_name, **kwargs)
def get(self, *args): def get(self, *args):

View File

@ -1,4 +1,4 @@
Django==2.0 Django==2.1
django-fluent-dashboard==1.0.1 django-fluent-dashboard==1.0.1
django-admin-tools==0.9.1 django-admin-tools==0.9.1
django-extensions==2.1.1 django-extensions==2.1.1
@ -7,10 +7,10 @@ celery==3.1.23
kombu==3.0.35 kombu==3.0.35
billiard==3.3.0.23 billiard==3.3.0.23
Markdown==2.4 Markdown==2.4
djangorestframework==3.9.3 djangorestframework==3.10.3
ecdsa==0.11 ecdsa==0.11
Pygments==1.6 Pygments==1.6
django-filter==1.1 django-filter==2.2.0
jsonfield==0.9.22 jsonfield==0.9.22
python-dateutil==2.2 python-dateutil==2.2
https://github.com/glic3rinu/passlib/archive/master.zip https://github.com/glic3rinu/passlib/archive/master.zip