Élie Bouttier 8 years ago
parent
commit
e174cbf2d2

+ 1 - 1
accounts/admin.py

@@ -28,7 +28,7 @@ class UserAdmin(AuthUserAdmin):
             return super().get_fieldsets(request, obj)
         if obj:
             return (
-                AuthUserAdmin.fieldsets[0], # Note: password is mandatory (but readonly)
+                AuthUserAdmin.fieldsets[0],  # Note: password is mandatory (but readonly)
                 AuthUserAdmin.fieldsets[1],
             )
         else:

+ 1 - 1
accounts/apps.py

@@ -5,4 +5,4 @@ class AccountsConfig(AppConfig):
     name = 'accounts'
 
     def ready(self):
-        import accounts.signals
+        import accounts.signals  # noqa

+ 0 - 1
adhesions/admin.py

@@ -1,6 +1,5 @@
 from django.contrib import admin
 from django.contrib.contenttypes.admin import GenericStackedInline
-from django.contrib.auth.models import User
 
 from .forms import AdherentForm
 from .models import Profile, Corporation, Adherent

+ 1 - 1
adhesions/apps.py

@@ -6,4 +6,4 @@ class AdhesionsConfig(AppConfig):
     verbose_name = 'Adhésions'
 
     def ready(self):
-        import adhesions.signals
+        import adhesions.signals  # noqa

+ 0 - 1
adhesions/forms.py

@@ -1,5 +1,4 @@
 from django import forms
-from django.forms.models import modelform_factory
 from django.forms import widgets
 from django.utils.safestring import mark_safe
 

+ 1 - 1
banking/admin.py

@@ -3,7 +3,7 @@ from django.contrib.contenttypes.admin import GenericTabularInline
 from django.contrib.contenttypes.models import ContentType
 from django.db.models import Q
 
-from services.models import Service, ServiceType
+from services.models import ServiceType
 from .models import Payment
 
 

+ 5 - 6
banking/models.py

@@ -5,14 +5,14 @@ from django.core.validators import MaxValueValidator
 
 
 class Payment(models.Model):
-    TRANSFERT = 0 
-    WITHDRAWAL = 1 
-    PAYMENT_CHOICES = ( 
+    TRANSFERT = 0
+    WITHDRAWAL = 1
+    PAYMENT_CHOICES = (
         (TRANSFERT, 'Virement'),
         (WITHDRAWAL, 'Prélèvement'),
     )
     limit = models.Q(app_label='adhesions', model='Adherent') \
-          | models.Q(app_label='services', model='Service')
+        | models.Q(app_label='services', model='Service')
     reason_type = models.ForeignKey(ContentType, on_delete=models.CASCADE,
                                     limit_choices_to=limit)
     reason_id = models.PositiveIntegerField()
@@ -51,9 +51,8 @@ class Payment(models.Model):
             return self.reason.adherent
     get_adherent.short_description = 'Adhérent'
 
-
     def __str__(self):
-        s = str(self.amount) + '€' 
+        s = str(self.amount) + '€'
         if self.period:
             if self.period == 1:
                 s += '/mois'

+ 1 - 1
djadhere/settings.py

@@ -37,7 +37,7 @@ INSTALLED_APPS = [
     'djadhere',
     'django.contrib.admin',
     'django.contrib.auth',
-    'accounts', # must be after django.contrib.auth
+    'accounts',  # must be after django.contrib.auth
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',

+ 1 - 1
manage.py

@@ -11,7 +11,7 @@ if __name__ == "__main__":
         # issue is really that Django is missing to avoid masking other
         # exceptions on Python 2.
         try:
-            import django
+            import django  # noqa
         except ImportError:
             raise ImportError(
                 "Couldn't import Django. Are you sure it's installed and "

+ 0 - 3
services/admin.py

@@ -1,6 +1,4 @@
 from django.contrib import admin
-from django.db.models import Q
-from django.utils import timezone
 
 from .models import Service, ServiceType, IPResource
 from banking.admin import ValidatedPaymentInline, PendingOrNewPaymentInline
@@ -33,7 +31,6 @@ class ServiceStatusFilter(admin.SimpleListFilter):
         )
 
     def queryset(self, request, queryset):
-        now = timezone.now()
         if self.value() == 'forthcoming':
             return queryset.filter(Service.get_forthcoming_filter())
         if self.value() == 'ongoing':

+ 1 - 1
services/apps.py

@@ -6,4 +6,4 @@ class ServicesConfig(AppConfig):
     verbose_name = 'Services'
 
     def ready(self):
-        import services.signals
+        import services.signals  # noqa

+ 8 - 5
services/management/commands/servicesstats.py

@@ -1,6 +1,5 @@
-from django.core.management.base import BaseCommand, CommandError
+from django.core.management.base import BaseCommand
 from django.db.models import DecimalField, F, Sum, Func, Q
-from django.utils import timezone
 
 from decimal import Decimal
 
@@ -15,19 +14,23 @@ class Command(BaseCommand):
         total_income = Decimal(0.0)
         lines = []
         for service_type in ServiceType.objects.all():
-            now = timezone.now()
             services = service_type.services.filter(Service.get_ongoing_filter())
             ntotal = services.count()
             services = services.exclude(adherent=None)
             nadh = services.count()
             ninf = ntotal - nadh
-            services = services.exclude(Q(contribution__isnull=True) | Q(contribution__amount=0) | Q(contribution__period=0))
+            services = services.exclude(
+                Q(contribution__isnull=True)
+                | Q(contribution__amount=0)
+                | Q(contribution__period=0)
+            )
             npay = services.count()
             ngra = nadh - npay
             amount = Func(F('contribution__amount'), function='CAST', template=as_float_template)
             period = F('contribution__period')
             output_field = DecimalField(max_digits=9, decimal_places=2)
-            income = services.aggregate(income=Sum(amount / period, output_field=output_field))['income'] or Decimal(0.0)
+            income = services.aggregate(income=Sum(amount / period,
+                                                   output_field=output_field))['income'] or Decimal(0.0)
             total_income += income
             lines += [(str(service_type), npay, ninf, ngra, income,)]
         self.stdout.write("%-16s%12s%12s%12s%12s%12s" % ('Service', 'npay', 'ninf', 'ngra', 'eur', 'pourcent'))

+ 5 - 3
services/models.py

@@ -67,13 +67,15 @@ class Service(models.Model):
     def get_forthcoming_filter():
         now = timezone.now()
         return Q(start__isnull=True, end__isnull=True) \
-             | Q(start__gt=now)
+            | Q(start__gt=now)
+
     @staticmethod
     def get_ongoing_filter():
         now = timezone.now()
         return Q(start__lte=now, end__isnull=True) \
-             | Q(start__lte=now, end__gt=now) \
-             | Q(start__isnull=True, end__gt=now)
+            | Q(start__lte=now, end__gt=now) \
+            | Q(start__isnull=True, end__gt=now)
+
     @staticmethod
     def get_finished_filter():
         now = timezone.now()

+ 3 - 0
setup.cfg

@@ -0,0 +1,3 @@
+[flake8]
+max-line-length = 119
+exclude = */migrations/*, venv/*, */tests.py, */views.py