From e679a4b6291a568679b05423493aae7a380b56de Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Tue, 18 Feb 2020 21:14:29 +0100 Subject: [PATCH] Fix formatting issues --- apps/activity/api/serializers.py | 3 ++- apps/api/urls.py | 2 -- apps/member/api/serializers.py | 3 ++- apps/member/filters.py | 4 +--- apps/member/forms.py | 7 ++----- apps/member/models.py | 2 -- apps/member/tables.py | 4 ++-- apps/member/urls.py | 18 +++++++++--------- apps/member/views.py | 16 +++++++--------- apps/note/api/serializers.py | 5 +++-- apps/note/api/views.py | 16 ++++++++-------- apps/note/forms.py | 3 ++- apps/note/models/transactions.py | 14 +++++++------- apps/note/tables.py | 12 +++++------- apps/note/urls.py | 12 ++++++------ apps/note/views.py | 14 +++++++------- 16 files changed, 63 insertions(+), 72 deletions(-) diff --git a/apps/activity/api/serializers.py b/apps/activity/api/serializers.py index 46bd8384..b3c70338 100644 --- a/apps/activity/api/serializers.py +++ b/apps/activity/api/serializers.py @@ -2,9 +2,10 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from ..models import ActivityType, Activity, Guest from rest_framework import serializers +from ..models import ActivityType, Activity, Guest + class ActivityTypeSerializer(serializers.ModelSerializer): """ diff --git a/apps/api/urls.py b/apps/api/urls.py index 475120fc..4ff23e57 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -5,8 +5,6 @@ from django.conf.urls import url, include from django.contrib.auth.models import User from rest_framework import routers, serializers, viewsets -from rest_framework.authtoken import views as token_views - from activity.api.urls import register_activity_urls from member.api.urls import register_members_urls from note.api.urls import register_note_urls diff --git a/apps/member/api/serializers.py b/apps/member/api/serializers.py index cf4420d5..126d69b2 100644 --- a/apps/member/api/serializers.py +++ b/apps/member/api/serializers.py @@ -2,9 +2,10 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from ..models import Profile, Club, Role, Membership from rest_framework import serializers +from ..models import Profile, Club, Role, Membership + class ProfileSerializer(serializers.ModelSerializer): """ diff --git a/apps/member/filters.py b/apps/member/filters.py index 76e0d52b..ab63795a 100644 --- a/apps/member/filters.py +++ b/apps/member/filters.py @@ -2,14 +2,12 @@ # Copyright (C) 2018-2019 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from django_filters import FilterSet, CharFilter, NumberFilter +from django_filters import FilterSet, CharFilter from django.contrib.auth.models import User from django.db.models import CharField from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Submit -from .models import Club - class UserFilter(FilterSet): class Meta: diff --git a/apps/member/forms.py b/apps/member/forms.py index ef32e9b8..3ea23762 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -2,17 +2,14 @@ # Copyright (C) 2018-2019 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later from dal import autocomplete -from django.contrib.auth.forms import UserChangeForm, UserCreationForm +from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User from django import forms from .models import Profile, Club, Membership -from django.utils.translation import gettext_lazy as _ - from crispy_forms.helper import FormHelper -from crispy_forms import layout, bootstrap -from crispy_forms.bootstrap import InlineField, FormActions, StrictButton, Div, Field +from crispy_forms.bootstrap import Div from crispy_forms.layout import Layout diff --git a/apps/member/models.py b/apps/member/models.py index ae5d90d5..1009fe11 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -4,8 +4,6 @@ from django.conf import settings from django.db import models -from django.db.models.signals import post_save -from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ from django.urls import reverse, reverse_lazy diff --git a/apps/member/tables.py b/apps/member/tables.py index 8ae10476..e6417353 100644 --- a/apps/member/tables.py +++ b/apps/member/tables.py @@ -1,10 +1,10 @@ #!/usr/bin/env python import django_tables2 as tables -from .models import Club -from django.conf import settings from django.contrib.auth.models import User +from .models import Club + class ClubTable(tables.Table): class Meta: diff --git a/apps/member/urls.py b/apps/member/urls.py index d4e3e6af..d21c2a63 100644 --- a/apps/member/urls.py +++ b/apps/member/urls.py @@ -10,16 +10,16 @@ from . import views app_name = 'member' urlpatterns = [ - path('signup/',views.UserCreateView.as_view(),name="signup"), - path('club/',views.ClubListView.as_view(),name="club_list"), - path('club//',views.ClubDetailView.as_view(),name="club_detail"), - path('club//add_member/',views.ClubAddMemberView.as_view(),name="club_add_member"), - path('club/create/',views.ClubCreateView.as_view(),name="club_create"), - path('user/',views.UserListView.as_view(),name="user_list"), - path('user/',views.UserDetailView.as_view(),name="user_detail"), - path('user//update',views.UserUpdateView.as_view(),name="user_update_profile"), + path('signup/', views.UserCreateView.as_view(), name="signup"), + path('club/', views.ClubListView.as_view(), name="club_list"), + path('club//', views.ClubDetailView.as_view(), name="club_detail"), + path('club//add_member/', views.ClubAddMemberView.as_view(), name="club_add_member"), + path('club/create/', views.ClubCreateView.as_view(), name="club_create"), + path('user/', views.UserListView.as_view(), name="user_list"), + path('user/', views.UserDetailView.as_view(), name="user_detail"), + path('user//update', views.UserUpdateView.as_view(), name="user_update_profile"), path('manage-auth-token/', views.ManageAuthTokens.as_view(), name='auth_token'), # API for the user autocompleter - path('user/user-autocomplete',views.UserAutocomplete.as_view(),name="user_autocomplete"), + path('user/user-autocomplete', views.UserAutocomplete.as_view(), name="user_autocomplete"), ] diff --git a/apps/member/views.py b/apps/member/views.py index 86ce3b19..020b984a 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -6,23 +6,21 @@ from dal import autocomplete from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import redirect from django.utils.translation import gettext_lazy as _ -from django.views.generic import CreateView, ListView, DetailView, UpdateView, RedirectView, TemplateView +from django.views.generic import CreateView, DetailView, UpdateView, TemplateView from django.contrib.auth.models import User from django.urls import reverse_lazy from django.db.models import Q - from django_tables2.views import SingleTableView from rest_framework.authtoken.models import Token +from note.models import Alias, NoteUser +from note.models.transactions import Transaction +from note.tables import HistoryTable -from note.models import Alias, Note, NoteUser from .models import Profile, Club, Membership from .forms import SignUpForm, ProfileForm, ClubForm, MembershipForm, MemberFormSet, FormSetHelper from .tables import ClubTable, UserTable from .filters import UserFilter, UserFilterFormHelper -from note.models.transactions import Transaction -from note.tables import HistoryTable - class UserCreateView(CreateView): """ @@ -197,9 +195,9 @@ class UserAutocomplete(autocomplete.Select2QuerySetView): return qs -################################### -############## CLUB ############### -################################### +# ******************************* # +# CLUB # +# ******************************* # class ClubCreateView(LoginRequiredMixin, CreateView): diff --git a/apps/note/api/serializers.py b/apps/note/api/serializers.py index 90c802a9..a0b92725 100644 --- a/apps/note/api/serializers.py +++ b/apps/note/api/serializers.py @@ -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): """ diff --git a/apps/note/api/views.py b/apps/note/api/views.py index a63cf102..1d015125 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -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: diff --git a/apps/note/forms.py b/apps/note/forms.py index 8f670455..225afb91 100644 --- a/apps/note/forms.py +++ b/apps/note/forms.py @@ -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 diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 5c242255..95940b65 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -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): diff --git a/apps/note/tables.py b/apps/note/tables.py index f13b502e..4a52dd13 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -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) diff --git a/apps/note/urls.py b/apps/note/urls.py index 7c19c425..6567cb95 100644 --- a/apps/note/urls.py +++ b/apps/note/urls.py @@ -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//',views.TransactionTemplateUpdateView.as_view(),name='template_update'), - path('buttons/',views.TransactionTemplateListView.as_view(),name='template_list'), - path('consos//',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//', views.TransactionTemplateUpdateView.as_view(), name='template_update'), + path('buttons/', views.TransactionTemplateListView.as_view(), name='template_list'), + path('consos//', 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'), ] diff --git a/apps/note/views.py b/apps/note/views.py index d4590e5f..e7776687 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -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()