mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
Fix formatting issues
This commit is contained in:
@ -2,11 +2,12 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from ..models.notes import Note, NoteClub, NoteSpecial, NoteUser, Alias
|
||||
from ..models.transactions import TransactionTemplate, Transaction, MembershipTransaction
|
||||
from rest_framework import serializers
|
||||
from rest_polymorphic.serializers import PolymorphicSerializer
|
||||
|
||||
from ..models.notes import Note, NoteClub, NoteSpecial, NoteUser, Alias
|
||||
from ..models.transactions import TransactionTemplate, Transaction, MembershipTransaction
|
||||
|
||||
|
||||
class NoteSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
|
@ -75,12 +75,12 @@ class NotePolymorphicViewSet(viewsets.ModelViewSet):
|
||||
|
||||
note_type = self.request.query_params.get("type", None)
|
||||
if note_type:
|
||||
l = str(note_type).lower()
|
||||
if "user" in l:
|
||||
types = str(note_type).lower()
|
||||
if "user" in types:
|
||||
queryset = queryset.filter(polymorphic_ctype__model="noteuser")
|
||||
elif "club" in l:
|
||||
elif "club" in types:
|
||||
queryset = queryset.filter(polymorphic_ctype__model="noteclub")
|
||||
elif "special" in l:
|
||||
elif "special" in types:
|
||||
queryset = queryset.filter(
|
||||
polymorphic_ctype__model="notespecial")
|
||||
else:
|
||||
@ -116,14 +116,14 @@ class AliasViewSet(viewsets.ModelViewSet):
|
||||
|
||||
note_type = self.request.query_params.get("type", None)
|
||||
if note_type:
|
||||
l = str(note_type).lower()
|
||||
if "user" in l:
|
||||
types = str(note_type).lower()
|
||||
if "user" in types:
|
||||
queryset = queryset.filter(
|
||||
note__polymorphic_ctype__model="noteuser")
|
||||
elif "club" in l:
|
||||
elif "club" in types:
|
||||
queryset = queryset.filter(
|
||||
note__polymorphic_ctype__model="noteclub")
|
||||
elif "special" in l:
|
||||
elif "special" in types:
|
||||
queryset = queryset.filter(
|
||||
note__polymorphic_ctype__model="notespecial")
|
||||
else:
|
||||
|
@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from dal import autocomplete, forward
|
||||
from dal import autocomplete
|
||||
from django import forms
|
||||
|
||||
from .models import Transaction, TransactionTemplate
|
||||
|
||||
|
||||
|
@ -7,12 +7,13 @@ from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.urls import reverse
|
||||
|
||||
from .notes import Note,NoteClub
|
||||
from .notes import Note, NoteClub
|
||||
|
||||
"""
|
||||
Defines transactions
|
||||
"""
|
||||
|
||||
|
||||
class TransactionCategory(models.Model):
|
||||
"""
|
||||
Defined a recurrent transaction category
|
||||
@ -32,6 +33,7 @@ class TransactionCategory(models.Model):
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
|
||||
class TransactionTemplate(models.Model):
|
||||
"""
|
||||
Defined a recurrent transaction
|
||||
@ -57,7 +59,7 @@ class TransactionTemplate(models.Model):
|
||||
TransactionCategory,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name=_('type'),
|
||||
max_length=31
|
||||
max_length=31,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@ -65,7 +67,7 @@ class TransactionTemplate(models.Model):
|
||||
verbose_name_plural = _("transaction templates")
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('note:template_update',args=(self.pk,))
|
||||
return reverse('note:template_update', args=(self.pk, ))
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
@ -98,9 +100,7 @@ class Transaction(models.Model):
|
||||
verbose_name=_('quantity'),
|
||||
default=1,
|
||||
)
|
||||
amount = models.PositiveIntegerField(
|
||||
verbose_name=_('amount'),
|
||||
)
|
||||
amount = models.PositiveIntegerField(verbose_name=_('amount'), )
|
||||
transaction_type = models.CharField(
|
||||
verbose_name=_('type'),
|
||||
max_length=31,
|
||||
@ -142,7 +142,7 @@ class Transaction(models.Model):
|
||||
|
||||
@property
|
||||
def total(self):
|
||||
return self.amount*self.quantity
|
||||
return self.amount * self.quantity
|
||||
|
||||
|
||||
class MembershipTransaction(Transaction):
|
||||
|
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
import django_tables2 as tables
|
||||
from django.db.models import F
|
||||
|
||||
@ -15,11 +14,10 @@ class HistoryTable(tables.Table):
|
||||
template_name = 'django_tables2/bootstrap.html'
|
||||
sequence = ('...', 'total', 'valid')
|
||||
|
||||
total = tables.Column() #will use Transaction.total() !!
|
||||
total = tables.Column() # will use Transaction.total() !!
|
||||
|
||||
def order_total(self, QuerySet, is_descending):
|
||||
def order_total(self, queryset, is_descending):
|
||||
# needed for rendering
|
||||
QuerySet = QuerySet.annotate(
|
||||
total=F('amount') *
|
||||
F('quantity')).order_by(('-' if is_descending else '') + 'total')
|
||||
return (QuerySet, True)
|
||||
queryset = queryset.annotate(total=F('amount') * F('quantity')) \
|
||||
.order_by(('-' if is_descending else '') + 'total')
|
||||
return (queryset, True)
|
||||
|
@ -10,12 +10,12 @@ from .models import Note
|
||||
app_name = 'note'
|
||||
urlpatterns = [
|
||||
path('transfer/', views.TransactionCreate.as_view(), name='transfer'),
|
||||
path('buttons/create/',views.TransactionTemplateCreateView.as_view(),name='template_create'),
|
||||
path('buttons/update/<int:pk>/',views.TransactionTemplateUpdateView.as_view(),name='template_update'),
|
||||
path('buttons/',views.TransactionTemplateListView.as_view(),name='template_list'),
|
||||
path('consos/<str:template_type>/',views.ConsoView.as_view(),name='consos'),
|
||||
path('consos/',views.ConsoView.as_view(),name='consos'),
|
||||
path('buttons/create/', views.TransactionTemplateCreateView.as_view(), name='template_create'),
|
||||
path('buttons/update/<int:pk>/', views.TransactionTemplateUpdateView.as_view(), name='template_update'),
|
||||
path('buttons/', views.TransactionTemplateListView.as_view(), name='template_list'),
|
||||
path('consos/<str:template_type>/', views.ConsoView.as_view(), name='consos'),
|
||||
path('consos/', views.ConsoView.as_view(), name='consos'),
|
||||
|
||||
# API for the note autocompleter
|
||||
path('note-autocomplete/', views.NoteAutocomplete.as_view(model=Note),name='note_autocomplete'),
|
||||
path('note-autocomplete/', views.NoteAutocomplete.as_view(model=Note), name='note_autocomplete'),
|
||||
]
|
||||
|
@ -5,11 +5,11 @@
|
||||
from dal import autocomplete
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.db.models import Q
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, ListView, DetailView, UpdateView
|
||||
from django.views.generic import CreateView, ListView, UpdateView
|
||||
|
||||
from .models import Note, Transaction, TransactionCategory, TransactionTemplate, Alias
|
||||
from .models import Transaction, TransactionCategory, TransactionTemplate, Alias
|
||||
from .forms import TransactionForm, TransactionTemplateForm, ConsoForm
|
||||
|
||||
|
||||
@ -75,12 +75,12 @@ class NoteAutocomplete(autocomplete.Select2QuerySetView):
|
||||
# Filtrage par type de note (user, club, special)
|
||||
note_type = self.forwarded.get("note_type", None)
|
||||
if note_type:
|
||||
l = str(note_type).lower()
|
||||
if "user" in l:
|
||||
types = str(note_type).lower()
|
||||
if "user" in types:
|
||||
qs = qs.filter(note__polymorphic_ctype__model="noteuser")
|
||||
elif "club" in l:
|
||||
elif "club" in types:
|
||||
qs = qs.filter(note__polymorphic_ctype__model="noteclub")
|
||||
elif "special" in l:
|
||||
elif "special" in types:
|
||||
qs = qs.filter(note__polymorphic_ctype__model="notespecial")
|
||||
else:
|
||||
qs = qs.none()
|
||||
|
Reference in New Issue
Block a user