Commit 5d691aaa authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

flake8

parent e472f292
from django.db import models
from django.urls import reverse
from adhesions.models import Adhesion, User, Corporation
from adhesions.models import Adhesion, User
class Profile(models.Model):
......
......@@ -2,13 +2,12 @@ from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase
from .models import Profile
from .forms import UserForm, ProfileForm
class ViewsTestCase(TestCase):
def setUp(self):
user = User.objects.create_user(
User.objects.create_user(
"user",
first_name="first",
last_name="last",
......
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericStackedInline, GenericTabularInline
from django.db.models import Q
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User as AuthUser
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.http import HttpResponseRedirect
from django.utils.html import format_html, mark_safe
from django.urls import reverse
from django.utils.html import format_html
from django.utils import timezone
from django.conf.urls import url
from django.template.response import TemplateResponse
......@@ -21,7 +16,7 @@ from banking.models import PaymentUpdate
from datetime import timedelta
### Inlines
# ## Inlines
class ProfileInline(admin.StackedInline):
......@@ -82,7 +77,7 @@ class InactiveServiceInline(ServiceInline):
return super().get_queryset(request).filter(active=False)
### Filters
# ## Filters
class AdherentTypeFilter(admin.SimpleListFilter):
......@@ -119,7 +114,7 @@ class AdhesionImportedFilter(admin.SimpleListFilter):
return queryset.filter(notes="")
### Mixins
# ## Mixins
class AdtSearchMixin:
......@@ -141,7 +136,7 @@ class AdtSearchMixin:
return queryset, use_distinct
### ModelAdmin
# ## ModelAdmin
class UserAdmin(AdtSearchMixin, AuthUserAdmin):
......
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.backends import ModelBackend
from .models import User, Adhesion
from .models import User
class AdhesionBackend(ModelBackend):
......@@ -14,7 +13,7 @@ class AdhesionBackend(ModelBackend):
adhesion_id = int(username)
except ValueError:
return None
user_type = ContentType.objects.get_for_model(User)
# user_type = ContentType.objects.get_for_model(User)
try:
user = User.objects.get(adhesion__id=adhesion_id)
except User.DoesNotExist:
......
from django import forms
from djadhere.utils import StringWidget
from .models import Adhesion, Corporation, User
from .models import User
class UserCreationForm(forms.ModelForm):
......
from django.core.management.base import BaseCommand, CommandParser, CommandError
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand
from django.utils.timezone import now
from django.contrib.auth.models import User
from adhesions.models import Adhesion, Corporation
from adhesions.models import Adhesion
from datetime import timedelta
......@@ -18,7 +16,8 @@ class Command(BaseCommand):
parser.add_argument(
"--newer-than",
type=int,
help="Afficher les adhérents inscrit depuis moins d’un certain nombre de jours.",
help="Afficher les adhérents inscrit depuis moins "
"d’un certain nombre de jours.",
)
group = parser.add_mutually_exclusive_group()
group.add_argument(
......@@ -29,7 +28,8 @@ class Command(BaseCommand):
group.add_argument(
"--unknown",
action="store_true",
help="Afficher uniquement les adhérents dont la cotisation n’est pas connue.",
help="Afficher uniquement les adhérents dont la cotisation "
"n’est pas connue.",
)
group.add_argument(
"--inactive",
......
from django.core.management.base import BaseCommand, CommandParser, CommandError
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from django.conf import settings
from adhesions.models import Adhesion, Corporation
from ldap3 import Server, Connection, ALL
from ldap3 import BASE, LEVEL, SUBTREE
from ldap3 import LEVEL
from ldap3 import ALL_ATTRIBUTES, MODIFY_REPLACE
import ldap3
......
from django.core.management.base import BaseCommand, CommandParser, CommandError
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from adhesions.models import Adhesion, Corporation
......@@ -33,8 +31,8 @@ class Command(BaseCommand):
if user.first_name != "FIXME":
self.stdout.write(
self.style.WARNING(
"L’adherent ADT%d s’est vu spécifier un prénom (%s), risque de perte de données."
% (pk, user.first_name)
"L’adherent ADT%d s’est vu spécifier un prénom (%s), "
"risque de perte de données." % (pk, user.first_name)
)
)
if not boolean_input("Continuer ? [y/n]"):
......@@ -42,8 +40,8 @@ class Command(BaseCommand):
if user.last_name != "%d" % pk:
self.stdout.write(
self.style.WARNING(
"L’adherent ADT%d s’est vu spécifier un nom (%s), risque de perte de données."
% (pk, user.last_name)
"L’adherent ADT%d s’est vu spécifier un nom (%s), "
"risque de perte de données." % (pk, user.last_name)
)
)
if not boolean_input("Continuer ? [y/n]"):
......@@ -54,8 +52,8 @@ class Command(BaseCommand):
if user.profile.ssh_keys:
self.stdout.write(
self.style.WARNING(
"L’adherent ADT%d s’est vu spécifier une clef SSH, risque de perte de données."
% (pk, user.last_name)
"L’adherent ADT%d s’est vu spécifier une clef SSH, "
"risque de perte de données." % pk
)
)
if not boolean_input("Continuer ? [y/n]"):
......
from django.core.management.base import BaseCommand, CommandParser, CommandError
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.conf import settings
from adhesions.models import Adhesion, Corporation
from adhesions.models import Adhesion
from ldap3 import Server, Connection, ALL
from ldap3 import BASE, LEVEL, SUBTREE
from ldap3 import LEVEL
from ldap3 import ALL_ATTRIBUTES
import ldap3
......@@ -50,10 +48,15 @@ class Command(BaseCommand):
)
delete = True
# if adh.active is None:
# self.stdout.write(self.style.ERROR("Adhesion ADT{} {} unknown"\
# .format(adh.pk, ldap_user.cn.value)))
# delete = False
if adh.active == False:
# self.stdout.write(
# self.style.ERROR(
# "Adhesion ADT{} {} unknown".format(
# adh.pk, ldap_user.cn.value
# )
# )
# )
# delete = False
if not adh.active:
self.stdout.write(
self.style.ERROR(
"Adhesion ADT{} {} inactive".format(
......
from django.core.exceptions import ImproperlyConfigured
from django.core import serializers
from adhesions.models import Corporation
......
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User as AuthUser
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.utils.html import format_html
from django.contrib.humanize.templatetags.humanize import naturalday
......
......@@ -13,7 +13,7 @@ from .models import Corporation, Adhesion
class AdhesionsMixin:
def setUp(self):
admin = User.objects.create_user(
User.objects.create_user(
"admin", email="admin@example.net", password="admin", is_superuser=True
)
user = User.objects.create_user(
......@@ -23,13 +23,13 @@ class AdhesionsMixin:
email="user@example.net",
password="user",
)
adh1 = Adhesion.objects.create(
Adhesion.objects.create(
adherent_type=ContentType.objects.get_for_model(User), adherent_id=user.pk
)
corp1 = Corporation.objects.create(social_reason="GoodCorp")
corp1.members.add(user)
corp2 = Corporation.objects.create(social_reason="EvilCorp")
adh2 = Adhesion.objects.create(
Corporation.objects.create(social_reason="EvilCorp")
Adhesion.objects.create(
adherent_type=ContentType.objects.get_for_model(Corporation),
adherent_id=corp1.pk,
)
......
......@@ -2,23 +2,20 @@ from django.conf.urls import url
from django.contrib import admin
from django.core.exceptions import PermissionDenied
from django.db import models
from django.urls import path, reverse
from django.forms import BaseInlineFormSet
from django.http import FileResponse, Http404
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.urls import path, reverse
from django.utils.html import format_html
from django.db.models import F, Sum, ExpressionWrapper, Subquery
from django.db.models import F, Sum, ExpressionWrapper
from django.db.models.functions import Coalesce
from django.utils.safestring import mark_safe
import io
from functools import update_wrapper
from reportlab.pdfgen import canvas
from adhesions.admin import AdhesionAdmin
from djadhere.utils import ActiveFilter
from services.admin import ServiceAdmin
from services.models import Service
......@@ -38,7 +35,7 @@ from .models import (
from .utils import notify_payment_update
### Inlines
# ## Inlines
class PaymentMethodFilter(admin.SimpleListFilter):
......@@ -123,7 +120,7 @@ class PaymentTypeFilter(admin.SimpleListFilter):
return queryset.filter(payment__service__isnull=False)
### Inlines
# ## Inlines
class PendingPaymentUpdateFormSet(BaseInlineFormSet):
......@@ -180,7 +177,7 @@ class ValidatedPaymentUpdateInline(admin.TabularInline):
return super().get_queryset(request).filter(validated=True)
### Helpers
# ## Helpers
def prefix_search_field(prefix, field):
......@@ -190,7 +187,7 @@ def prefix_search_field(prefix, field):
return prefix + "__" + field
### ModelAdmin
# ## ModelAdmin
class RecurringPaymentAdmin(admin.ModelAdmin):
......
......@@ -13,5 +13,5 @@ class PaymentForm(ModelForm):
start = self.cleaned_data["start"]
if self.instance.pk:
if start < self.instance.start:
raise ValidationError(_("Invalid value"), code="invalid")
raise ValidationError("valeur invalide", code="invalid")
return start
from django.core.management.base import BaseCommand, CommandParser, CommandError
from django.utils.timezone import now
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from adhesions.models import Adhesion
from banking.models import Echeance as EcheanceModel
from datetime import timedelta, datetime
from datetime import datetime
from argparse import FileType
from csv import reader as csv_reader
from collections import namedtuple
......
......@@ -21,7 +21,8 @@ class Command(BaseCommand):
if expense.notes:
self.stdout.write("Notes: {}".format(expense.notes))
raise CommandError(
"Expense note will be lost; please save these information elsewhere and empty the field."
"Expense note will be lost; "
"please save these information elsewhere and empty the field."
)
try:
recurring_expense = RecurringExpense.objects.get(
......@@ -41,7 +42,7 @@ class Command(BaseCommand):
reply = strtobool(reply)
except ValueError:
reply = None
if reply == False:
if not reply:
return
RecurringExpensePayment.objects.create(
date=expense.date,
......
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
from django.db.models import Q
from adhesions.models import Adhesion
from services.models import Service, ServiceType, IPResource, Route
from services.models import ServiceType
from banking.models import RecurringPayment, PaymentUpdate
from operator import add
......
from django.test import TestCase
# from django.test import TestCase
# Create your tests here.
from .notifications import notify_payment_update
from .transparence import Transparency
from .notifications import notify_payment_update # noqa: F401
from .transparence import Transparency # noqa: F401
......@@ -2,7 +2,6 @@ from django.urls import reverse
from django.conf import settings
from djadhere.utils import send_notification
from banking.models import PaymentUpdate
def notify_payment_update(request, update, old_update=None):
......@@ -10,11 +9,6 @@ def notify_payment_update(request, update, old_update=None):
message = "Bénévole : " + benevole
message += "\n\nPaiement :\n\n"
try:
last_validated_update = PaymentUpdate.objects.latest("start")
except PaymentUpdate.DoesNotExist:
last_validated_update = None
if old_update:
message += "\t- %s\n" % old_update
message += "\t+ %s\n" % update
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment