Merge pull request #680 from ae-utbm/ruff

Introduct Ruff as formater and linter
This commit is contained in:
thomas girod 2024-06-26 14:11:26 +02:00 committed by GitHub
commit a5cbac1f97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
177 changed files with 883 additions and 1063 deletions

View File

@ -45,7 +45,7 @@ runs:
${{ runner.os }}-poetry- ${{ runner.os }}-poetry-
- name: Install dependencies - name: Install dependencies
run: poetry install -E testing -E docs run: poetry install --with docs,tests
shell: bash shell: bash
- name: Install xapian - name: Install xapian

View File

@ -8,15 +8,17 @@ on:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
black: ruff:
name: Black format name: Ruff lint & format
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out repository - uses: actions/checkout@v4
uses: actions/checkout@v3 - name: ruff format
- name: Setup Project uses: chartboost/ruff-action@v1 # format
uses: ./.github/actions/setup_project with:
- run: poetry run black --check . args: format --diff
- name: ruff check
uses: chartboost/ruff-action@v1 # lint
tests: tests:
name: Run tests and generate coverage report name: Run tests and generate coverage report

View File

@ -18,7 +18,6 @@ from django.contrib import admin
from accounting.models import * from accounting.models import *
admin.site.register(BankAccount) admin.site.register(BankAccount)
admin.site.register(ClubAccount) admin.site.register(ClubAccount)
admin.site.register(GeneralJournal) admin.site.register(GeneralJournal)

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.core.validators import django.core.validators
import accounting.models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
import accounting.models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import phonenumber_field.modelfields import phonenumber_field.modelfields
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -14,19 +14,19 @@
# #
# #
from django.urls import reverse from decimal import Decimal
from django.core.exceptions import ValidationError
from django.core import validators
from django.db import models
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from django.template import defaultfilters
from django.conf import settings
from django.core import validators
from django.core.exceptions import ValidationError
from django.db import models
from django.template import defaultfilters
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField from phonenumber_field.modelfields import PhoneNumberField
from decimal import Decimal
from core.models import User, SithFile
from club.models import Club from club.models import Club
from core.models import SithFile, User
class CurrencyField(models.DecimalField): class CurrencyField(models.DecimalField):

View File

@ -14,19 +14,19 @@
# #
# #
from django.test import TestCase
from django.urls import reverse
from django.core.management import call_command
from datetime import date, timedelta from datetime import date, timedelta
from core.models import User from django.test import TestCase
from django.urls import reverse
from accounting.models import ( from accounting.models import (
GeneralJournal,
Operation,
Label,
AccountingType, AccountingType,
GeneralJournal,
Label,
Operation,
SimplifiedAccountingType, SimplifiedAccountingType,
) )
from core.models import User
class RefoundAccountTest(TestCase): class RefoundAccountTest(TestCase):

View File

@ -14,41 +14,41 @@
# #
# #
from django.views.generic import ListView, DetailView
from django.views.generic.edit import UpdateView, CreateView, DeleteView, FormView
from django.urls import reverse_lazy, reverse
from django.utils.translation import gettext_lazy as _
from django.forms.models import modelform_factory
from django.core.exceptions import PermissionDenied, ValidationError
from django.forms import HiddenInput
from django.db import transaction
from django.db.models import Sum
from django.conf import settings
from django import forms
from django.http import HttpResponse
import collections import collections
from ajax_select.fields import AutoCompleteSelectField from ajax_select.fields import AutoCompleteSelectField
from django import forms
from django.conf import settings
from django.core.exceptions import PermissionDenied, ValidationError
from django.db import transaction
from django.db.models import Sum
from django.forms import HiddenInput
from django.forms.models import modelform_factory
from django.http import HttpResponse
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, ListView
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
from core.views import (
CanViewMixin,
CanEditMixin,
CanEditPropMixin,
CanCreateMixin,
TabedViewMixin,
)
from core.views.forms import SelectFile, SelectDate
from accounting.models import ( from accounting.models import (
AccountingType,
BankAccount, BankAccount,
ClubAccount, ClubAccount,
GeneralJournal,
Operation,
AccountingType,
Company, Company,
SimplifiedAccountingType, GeneralJournal,
Label, Label,
Operation,
SimplifiedAccountingType,
) )
from counter.models import Counter, Selling, Product from core.views import (
CanCreateMixin,
CanEditMixin,
CanEditPropMixin,
CanViewMixin,
TabedViewMixin,
)
from core.views.forms import SelectDate, SelectFile
from counter.models import Counter, Product, Selling
# Main accounting view # Main accounting view
@ -521,14 +521,14 @@ class OperationPDFView(CanViewMixin, DetailView):
pk_url_kwarg = "op_id" pk_url_kwarg = "op_id"
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
from reportlab.pdfgen import canvas
from reportlab.lib.units import cm
from reportlab.platypus import Table, TableStyle
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.pagesizes import letter from reportlab.lib.pagesizes import letter
from reportlab.lib.units import cm
from reportlab.lib.utils import ImageReader from reportlab.lib.utils import ImageReader
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas
from reportlab.platypus import Table, TableStyle
pdfmetrics.registerFont(TTFont("DejaVu", "DejaVuSerif.ttf")) pdfmetrics.registerFont(TTFont("DejaVu", "DejaVuSerif.ttf"))
@ -599,7 +599,7 @@ class OperationPDFView(CanViewMixin, DetailView):
payment_mode = "" payment_mode = ""
for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD: for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD:
if m[0] == mode: if m[0] == mode:
payment_mode += "[\u00D7]" payment_mode += "[\u00d7]"
else: else:
payment_mode += "[ ]" payment_mode += "[ ]"
payment_mode += " %s\n" % (m[1]) payment_mode += " %s\n" % (m[1])

View File

@ -14,6 +14,4 @@
# #
# #
from django.contrib import admin
# Register your models here. # Register your models here.

View File

@ -14,6 +14,4 @@
# #
# #
from django.db import models
# Create your models here. # Create your models here.

View File

@ -14,6 +14,4 @@
# #
# #
from django.test import TestCase
# Create your tests here. # Create your tests here.

View File

@ -14,10 +14,10 @@
# #
# #
from django.urls import re_path, path, include from django.urls import include, path, re_path
from rest_framework import routers
from api.views import * from api.views import *
from rest_framework import routers
# Router config # Router config
router = routers.DefaultRouter() router = routers.DefaultRouter()

View File

@ -14,13 +14,13 @@
# #
# #
from rest_framework.response import Response
from rest_framework import viewsets
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from rest_framework.decorators import action
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from core.views import can_view, can_edit from core.views import can_edit, can_view
def check_if(obj, user, test): def check_if(obj, user, test):
@ -64,10 +64,10 @@ class RightModelViewSet(ManageModelMixin, viewsets.ModelViewSet):
from .api import * from .api import *
from .counter import *
from .user import *
from .club import * from .club import *
from .counter import *
from .group import * from .group import *
from .launderette import * from .launderette import *
from .uv import *
from .sas import * from .sas import *
from .user import *
from .uv import *

View File

@ -14,9 +14,9 @@
# #
# #
from rest_framework.response import Response
from rest_framework.decorators import api_view, renderer_classes from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import StaticHTMLRenderer from rest_framework.renderers import StaticHTMLRenderer
from rest_framework.response import Response
from core.templatetags.renderer import markdown from core.templatetags.renderer import markdown

View File

@ -14,17 +14,15 @@
# #
# #
from rest_framework.response import Response from django.conf import settings
from django.core.exceptions import PermissionDenied
from rest_framework import serializers from rest_framework import serializers
from rest_framework.decorators import api_view, renderer_classes from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import StaticHTMLRenderer from rest_framework.renderers import StaticHTMLRenderer
from rest_framework.response import Response
from django.conf import settings
from django.core.exceptions import PermissionDenied
from club.models import Club, Mailing
from api.views import RightModelViewSet from api.views import RightModelViewSet
from club.models import Club, Mailing
class ClubSerializer(serializers.ModelSerializer): class ClubSerializer(serializers.ModelSerializer):

View File

@ -15,12 +15,11 @@
# #
from rest_framework import serializers from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.response import Response
from counter.models import Counter
from api.views import RightModelViewSet from api.views import RightModelViewSet
from counter.models import Counter
class CounterSerializer(serializers.ModelSerializer): class CounterSerializer(serializers.ModelSerializer):

View File

@ -16,9 +16,8 @@
from rest_framework import serializers from rest_framework import serializers
from core.models import RealGroup
from api.views import RightModelViewSet from api.views import RightModelViewSet
from core.models import RealGroup
class GroupSerializer(serializers.ModelSerializer): class GroupSerializer(serializers.ModelSerializer):

View File

@ -15,12 +15,11 @@
# #
from rest_framework import serializers from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.response import Response
from launderette.models import Launderette, Machine, Token
from api.views import RightModelViewSet from api.views import RightModelViewSet
from launderette.models import Launderette, Machine, Token
class LaunderettePlaceSerializer(serializers.ModelSerializer): class LaunderettePlaceSerializer(serializers.ModelSerializer):

View File

@ -1,4 +1,5 @@
from typing import List from typing import List
from rest_framework.decorators import api_view, renderer_classes from rest_framework.decorators import api_view, renderer_classes
from rest_framework.exceptions import PermissionDenied from rest_framework.exceptions import PermissionDenied
from rest_framework.generics import get_object_or_404 from rest_framework.generics import get_object_or_404
@ -6,8 +7,8 @@ from rest_framework.renderers import JSONRenderer
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from core.views import can_edit
from core.models import User from core.models import User
from core.views import can_edit
from sas.models import Picture from sas.models import Picture

View File

@ -17,12 +17,11 @@
import datetime import datetime
from rest_framework import serializers from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.response import Response
from core.models import User
from api.views import RightModelViewSet from api.views import RightModelViewSet
from core.models import User
class UserSerializer(serializers.ModelSerializer): class UserSerializer(serializers.ModelSerializer):

View File

@ -1,11 +1,12 @@
from rest_framework.response import Response import json
import urllib.request
from django.conf import settings
from django.core.exceptions import PermissionDenied
from rest_framework import serializers
from rest_framework.decorators import api_view, renderer_classes from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import JSONRenderer from rest_framework.renderers import JSONRenderer
from django.core.exceptions import PermissionDenied from rest_framework.response import Response
from django.conf import settings
from rest_framework import serializers
import urllib.request
import json
from pedagogy.views import CanCreateUVFunctionMixin from pedagogy.views import CanCreateUVFunctionMixin

View File

@ -23,18 +23,15 @@
# #
# #
from django.conf import settings from ajax_select.fields import AutoCompleteSelectMultipleField
from django import forms from django import forms
from django.conf import settings
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField from club.models import Club, Mailing, MailingSubscription, Membership
from club.models import Mailing, MailingSubscription, Club, Membership
from core.models import User from core.models import User
from core.views.forms import SelectDate, SelectDateTime from core.views.forms import SelectDate, TzAwareDateTimeField
from counter.models import Counter from counter.models import Counter
from core.views.forms import TzAwareDateTimeField
class ClubEditForm(forms.ModelForm): class ClubEditForm(forms.ModelForm):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.core.validators import django.core.validators
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import re import re
import django.core.validators import django.core.validators
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import django.db.models.deletion
from django.db import migrations, models from django.db import migrations, models
from club.models import Club from club.models import Club
from core.operations import PsqlRunOnly from core.operations import PsqlRunOnly
import django.db.models.deletion
def generate_club_pages(apps, schema_editor): def generate_club_pages(apps, schema_editor):

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import club.models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
import club.models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -24,21 +24,19 @@
# #
from typing import Optional from typing import Optional
from django.core.cache import cache
from django.db import models
from django.core import validators
from django.conf import settings from django.conf import settings
from django.core import validators
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.validators import RegexValidator, validate_email
from django.db import models, transaction
from django.db.models import Q from django.db.models import Q
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.db import transaction
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.core.validators import RegexValidator, validate_email
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from core.models import User, MetaGroup, Group, SithFile, RealGroup, Notification, Page from core.models import Group, MetaGroup, Notification, Page, RealGroup, SithFile, User
# Create your models here. # Create your models here.

View File

@ -18,15 +18,14 @@ from datetime import timedelta
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from django.test import TestCase from django.test import TestCase
from django.utils import timezone, html
from django.utils.timezone import now, localtime
from django.utils.translation import gettext as _
from django.urls import reverse from django.urls import reverse
from django.core.management import call_command from django.utils import html, timezone
from django.utils.timezone import localtime, now
from django.utils.translation import gettext as _
from core.models import User, AnonymousUser
from club.models import Club, Membership, Mailing
from club.forms import MailingForm from club.forms import MailingForm
from club.models import Club, Mailing, Membership
from core.models import AnonymousUser, User
from sith.settings import SITH_BAR_MANAGER, SITH_MAIN_CLUB_ID from sith.settings import SITH_BAR_MANAGER, SITH_MAIN_CLUB_ID
@ -861,8 +860,7 @@ class MailingFormTest(TestCase):
reverse("club:mailing", kwargs={"club_id": self.bdf.id}), reverse("club:mailing", kwargs={"club_id": self.bdf.id}),
{ {
"action": MailingForm.ACTION_REMOVE_SUBSCRIPTION, "action": MailingForm.ACTION_REMOVE_SUBSCRIPTION,
"removal_%d" "removal_%d" % mde.id: [
% mde.id: [
user.id user.id
for user in mde.subscriptions.filter( for user in mde.subscriptions.filter(
user__in=[self.rbatsbak, self.comunity] user__in=[self.rbatsbak, self.comunity]

View File

@ -26,50 +26,42 @@
import csv import csv
from django.conf import settings from django.conf import settings
from django import forms from django.core.exceptions import NON_FIELD_ERRORS, PermissionDenied, ValidationError
from django.views.generic import ListView, DetailView, TemplateView, View from django.core.paginator import InvalidPage, Paginator
from django.views.generic.edit import DeleteView from django.db.models import Sum
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import UpdateView, CreateView
from django.http import ( from django.http import (
HttpResponseRedirect,
HttpResponse,
Http404, Http404,
HttpResponseRedirect,
StreamingHttpResponse, StreamingHttpResponse,
) )
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext as _t from django.utils.translation import gettext as _t
from django.core.exceptions import PermissionDenied, ValidationError, NON_FIELD_ERRORS from django.utils.translation import gettext_lazy as _
from django.core.paginator import Paginator, InvalidPage from django.views.generic import DetailView, ListView, TemplateView, View
from django.shortcuts import get_object_or_404, redirect from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.db.models import Sum
from club.forms import ClubEditForm, ClubMemberForm, MailingForm, SellingsForm
from core.views import ( from club.models import Club, Mailing, MailingSubscription, Membership
CanCreateMixin, from com.views import (
CanViewMixin, PosterCreateBaseView,
CanEditMixin, PosterDeleteBaseView,
CanEditPropMixin, PosterEditBaseView,
UserIsRootMixin, PosterListBaseView,
TabedViewMixin,
PageEditViewBase,
DetailFormView,
) )
from core.models import PageRev from core.models import PageRev
from core.views import (
from counter.models import Selling CanCreateMixin,
CanEditMixin,
from com.views import ( CanEditPropMixin,
PosterListBaseView, CanViewMixin,
PosterCreateBaseView, DetailFormView,
PosterEditBaseView, PageEditViewBase,
PosterDeleteBaseView, TabedViewMixin,
UserIsRootMixin,
) )
from counter.models import Selling
from club.models import Club, Membership, Mailing, MailingSubscription
from club.forms import MailingForm, ClubEditForm, ClubMemberForm, SellingsForm
class ClubTabsMixin(TabedViewMixin): class ClubTabsMixin(TabedViewMixin):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models import django.db.models.deletion
import django.utils.timezone import django.utils.timezone
from django.conf import settings from django.conf import settings
import django.db.models.deletion from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -23,22 +23,20 @@
# #
# #
from django.shortcuts import render from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.mail import EmailMultiAlternatives
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Q from django.db.models import Q
from django.utils.translation import gettext_lazy as _ from django.shortcuts import render
from django.utils import timezone
from django.urls import reverse
from django.conf import settings
from django.templatetags.static import static from django.templatetags.static import static
from django.core.mail import EmailMultiAlternatives from django.urls import reverse
from django.core.exceptions import ValidationError
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from core import utils
from core.models import User, Preferences, RealGroup, Notification, SithFile
from club.models import Club from club.models import Club
from core import utils
from core.models import Notification, Preferences, RealGroup, User
class Sith(models.Model): class Sith(models.Model):

View File

@ -13,18 +13,17 @@
# OR WITHIN THE LOCAL FILE "LICENSE" # OR WITHIN THE LOCAL FILE "LICENSE"
# #
# #
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase from django.test import TestCase
from django.conf import settings
from django.urls import reverse from django.urls import reverse
from django.core.management import call_command
from django.utils import html from django.utils import html
from django.utils.timezone import localtime, now from django.utils.timezone import localtime, now
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from club.models import Club, Membership from club.models import Club, Membership
from com.models import Sith, News, Weekmail, WeekmailArticle, Poster from com.models import News, Poster, Sith, Weekmail, WeekmailArticle
from core.models import User, RealGroup, AnonymousUser from core.models import AnonymousUser, RealGroup, User
class ComAlertTest(TestCase): class ComAlertTest(TestCase):

View File

@ -23,38 +23,35 @@
# #
# #
from django.shortcuts import redirect, get_object_or_404
from django.http import HttpResponseRedirect
from django.views.generic import ListView, DetailView, View
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.views.generic.detail import SingleObjectMixin
from django.utils.translation import gettext_lazy as _
from django.urls import reverse, reverse_lazy
from django.core.exceptions import ValidationError
from django.utils import timezone
from django.conf import settings
from django.db.models import Max
from django.forms.models import modelform_factory
from django.core.exceptions import PermissionDenied
from django import forms
from datetime import timedelta from datetime import timedelta
from smtplib import SMTPRecipientsRefused from smtplib import SMTPRecipientsRefused
from com.models import Sith, News, NewsDate, Weekmail, WeekmailArticle, Screen, Poster from django import forms
from django.conf import settings
from django.core.exceptions import PermissionDenied, ValidationError
from django.db.models import Max
from django.forms.models import modelform_factory
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse, reverse_lazy
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, ListView, View
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from club.models import Club, Mailing
from com.models import News, NewsDate, Poster, Screen, Sith, Weekmail, WeekmailArticle
from core.models import Notification, RealGroup, User
from core.views import ( from core.views import (
CanViewMixin, CanCreateMixin,
CanEditMixin, CanEditMixin,
CanEditPropMixin, CanEditPropMixin,
TabedViewMixin, CanViewMixin,
CanCreateMixin,
QuickNotifMixin, QuickNotifMixin,
TabedViewMixin,
) )
from core.views.forms import SelectDateTime, MarkdownInput from core.views.forms import MarkdownInput, TzAwareDateTimeField
from core.models import Notification, RealGroup, User
from club.models import Club, Mailing
from core.views.forms import TzAwareDateTimeField
# Sith object # Sith object

View File

@ -14,12 +14,12 @@
# #
# #
from django.contrib import admin
from ajax_select import make_ajax_form from ajax_select import make_ajax_form
from core.models import User, Page, RealGroup, MetaGroup, SithFile from django.contrib import admin
from django.contrib.auth.models import Group as AuthGroup from django.contrib.auth.models import Group as AuthGroup
from haystack.admin import SearchModelAdmin from haystack.admin import SearchModelAdmin
from core.models import MetaGroup, Page, RealGroup, SithFile, User
admin.site.unregister(AuthGroup) admin.site.unregister(AuthGroup)
admin.site.register(MetaGroup) admin.site.register(MetaGroup)

View File

@ -34,8 +34,8 @@ class SithConfig(AppConfig):
verbose_name = "Core app of the Sith" verbose_name = "Core app of the Sith"
def ready(self): def ready(self):
import core.signals # noqa F401
from forum.models import Forum from forum.models import Forum
import core.signals
cache.clear() cache.clear()

View File

@ -1,6 +1,3 @@
from core.models import Page
class FourDigitYearConverter: class FourDigitYearConverter:
regex = "[0-9]{4}" regex = "[0-9]{4}"

View File

@ -14,15 +14,14 @@
# #
# #
from ajax_select import LookupChannel, register
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from ajax_select import register, LookupChannel
from core.views.site import search_user
from core.models import User, Group, SithFile
from club.models import Club
from counter.models import Product, Counter, Customer
from accounting.models import ClubAccount, Company from accounting.models import ClubAccount, Company
from eboutic.models import BasketItem from club.models import Club
from core.models import Group, SithFile, User
from core.views.site import search_user
from counter.models import Counter, Customer, Product
def check_token(request): def check_token(request):

View File

@ -23,8 +23,8 @@
# #
import os import os
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.management import call_command
from core.models import SithFile from core.models import SithFile

View File

@ -25,6 +25,7 @@
import os import os
from django.core.management.commands import compilemessages from django.core.management.commands import compilemessages

View File

@ -24,9 +24,10 @@
# #
import os import os
import sass import sass
from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):

View File

@ -24,10 +24,9 @@
# #
import os import os
import sys
import signal import signal
import sys
from http.server import test, CGIHTTPRequestHandler from http.server import CGIHTTPRequestHandler, test
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils import autoreload from django.utils import autoreload

View File

@ -15,11 +15,12 @@
# #
import os import os
import tomli
import subprocess import subprocess
from django.core.management.base import BaseCommand, CommandParser
from pathlib import Path from pathlib import Path
import tomli
from django.core.management.base import BaseCommand, CommandParser
class Command(BaseCommand): class Command(BaseCommand):
help = "Install xapian" help = "Install xapian"

View File

@ -23,6 +23,7 @@
# #
import os import os
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from core.markdown import markdown from core.markdown import markdown

View File

@ -24,38 +24,37 @@
import os import os
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
from io import StringIO, BytesIO from io import BytesIO, StringIO
from pathlib import Path from pathlib import Path
from django.contrib.auth.models import Permission
from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.conf import settings from django.conf import settings
from django.db import connection from django.contrib.auth.models import Permission
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.db import connection
from django.utils import timezone from django.utils import timezone
from PIL import Image from PIL import Image
from core.models import Group, User, Page, PageRev, SithFile
from accounting.models import ( from accounting.models import (
GeneralJournal, AccountingType,
BankAccount, BankAccount,
ClubAccount, ClubAccount,
Operation,
AccountingType,
SimplifiedAccountingType,
Company, Company,
GeneralJournal,
Operation,
SimplifiedAccountingType,
) )
from core.utils import resize_image
from club.models import Club, Membership from club.models import Club, Membership
from subscription.models import Subscription from com.models import News, NewsDate, Sith, Weekmail
from counter.models import Customer, ProductType, Product, Counter, Selling, StudentCard from core.models import Group, Page, PageRev, SithFile, User
from com.models import Sith, Weekmail, News, NewsDate from core.utils import resize_image
from election.models import Election, Role, Candidature, ElectionList from counter.models import Counter, Customer, Product, ProductType, Selling, StudentCard
from election.models import Candidature, Election, ElectionList, Role
from forum.models import Forum, ForumTopic from forum.models import Forum, ForumTopic
from pedagogy.models import UV from pedagogy.models import UV
from sas.models import Album, Picture, PeoplePictureRelation from sas.models import Album, PeoplePictureRelation, Picture
from subscription.models import Subscription
class Command(BaseCommand): class Command(BaseCommand):

View File

@ -23,8 +23,8 @@
# #
import os import os
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.management import call_command
from core.models import SithFile from core.models import SithFile

View File

@ -15,8 +15,9 @@
# #
import os import os
from django.core.management.base import BaseCommand
from django.core.management import call_command from django.core.management import call_command
from django.core.management.base import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):

View File

@ -16,8 +16,9 @@
import os import os
import re import re
from mistune import Renderer, InlineGrammar, InlineLexer, Markdown, escape, escape_link
from django.urls import reverse from django.urls import reverse
from mistune import InlineGrammar, InlineLexer, Markdown, Renderer, escape, escape_link
class SithRenderer(Renderer): class SithRenderer(Renderer):

View File

@ -16,12 +16,13 @@
import importlib import importlib
import threading import threading
from django.conf import settings from django.conf import settings
from django.utils.functional import SimpleLazyObject
from django.contrib.auth import get_user from django.contrib.auth import get_user
from django.contrib.auth.middleware import ( from django.contrib.auth.middleware import (
AuthenticationMiddleware as DjangoAuthenticationMiddleware, AuthenticationMiddleware as DjangoAuthenticationMiddleware,
) )
from django.utils.functional import SimpleLazyObject
module, klass = settings.AUTH_ANONYMOUS_MODEL.rsplit(".", 1) module, klass = settings.AUTH_ANONYMOUS_MODEL.rsplit(".", 1)
AnonymousUser = getattr(importlib.import_module(module), klass) AnonymousUser = getattr(importlib.import_module(module), klass)

View File

@ -1,14 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.contrib.auth.models import django.contrib.auth.models
import django.db.models.deletion
import django.core.validators import django.core.validators
import core.models import django.db.models.deletion
import phonenumber_field.modelfields import phonenumber_field.modelfields
from django.conf import settings from django.conf import settings
import django.db.models.deletion from django.db import migrations, models
import core.models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.core.validators import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
import core.models import core.models

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone import django.utils.timezone
from django.db import migrations, models
import core.models import core.models

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.utils.timezone
import django.db.models.deletion import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.core.validators import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.core.validators import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import django.utils.timezone
import django.db.models.deletion import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,9 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import core.models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
import core.models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# Generated by Django 2.2.6 on 2019-11-14 15:10 # Generated by Django 2.2.6 on 2019-11-14 15:10
import django.db.models.deletion
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -23,36 +23,39 @@
# #
# #
import importlib import importlib
from typing import Union, Optional, List import os
import unicodedata
from datetime import date, timedelta
from typing import List, Optional, Union
from django.core.cache import cache from django.conf import settings
from django.core.mail import send_mail
from django.contrib.auth.models import ( from django.contrib.auth.models import (
AbstractBaseUser, AbstractBaseUser,
UserManager, UserManager,
Group as AuthGroup, )
GroupManager as AuthGroupManager, from django.contrib.auth.models import (
AnonymousUser as AuthAnonymousUser, AnonymousUser as AuthAnonymousUser,
) )
from django.utils.translation import gettext_lazy as _ from django.contrib.auth.models import (
from django.utils import timezone Group as AuthGroup,
from django.core import validators )
from django.core.exceptions import ValidationError, PermissionDenied from django.contrib.auth.models import (
from django.urls import reverse GroupManager as AuthGroupManager,
from django.conf import settings )
from django.db import models, transaction
from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.storage import staticfiles_storage
from django.utils.html import escape from django.core import validators
from django.core.cache import cache
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.mail import send_mail
from django.db import models, transaction
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.html import escape
import os from django.utils.translation import gettext_lazy as _
from core import utils
from phonenumber_field.modelfields import PhoneNumberField from phonenumber_field.modelfields import PhoneNumberField
from datetime import timedelta, date from core import utils
import unicodedata
class RealGroupManager(AuthGroupManager): class RealGroupManager(AuthGroupManager):
@ -698,9 +701,11 @@ class User(AbstractBaseUser):
<em>%s</em> <em>%s</em>
</a> </a>
""" % ( """ % (
(
self.profile_pict.get_download_url() self.profile_pict.get_download_url()
if self.profile_pict if self.profile_pict
else staticfiles_storage.url("core/img/unknown.jpg"), else staticfiles_storage.url("core/img/unknown.jpg")
),
_("Profile"), _("Profile"),
escape(self.get_display_name()), escape(self.get_display_name()),
) )

View File

@ -25,6 +25,7 @@
import os import os
from collections import OrderedDict from collections import OrderedDict
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.finders import FileSystemFinder from django.contrib.staticfiles.finders import FileSystemFinder
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage

View File

@ -24,12 +24,14 @@
# #
import os import os
import sass
from urllib.parse import urljoin from urllib.parse import urljoin
from django.utils.encoding import force_bytes, iri_to_uri
import sass
from django.conf import settings
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.templatetags.static import static from django.templatetags.static import static
from django.conf import settings from django.utils.encoding import force_bytes, iri_to_uri
from core.scss.storage import ScssFileStorage, find_file from core.scss.storage import ScssFileStorage, find_file

View File

@ -24,7 +24,6 @@
# #
from django.db import models from django.db import models
from haystack import indexes, signals from haystack import indexes, signals
from core.models import User from core.models import User

View File

@ -8,10 +8,10 @@ from core.models import User
@receiver(m2m_changed, sender=User.groups.through, dispatch_uid="user_groups_changed") @receiver(m2m_changed, sender=User.groups.through, dispatch_uid="user_groups_changed")
def user_groups_changed(sender, instance: User, **kwargs): def user_groups_changed(sender, instance: User, **kwargs):
""" """
Clear the cached clubs of the user Clear the cached groups of the user
""" """
# As a m2m relationship doesn't live within the model # As a m2m relationship doesn't live within the model
# but rather on an intermediary table, there is no # but rather on an intermediary table, there is no
# model method to override, meaning we must use # model method to override, meaning we must use
# a signal to invalidate the cache when a user is removed from a club # a signal to invalidate the cache when a user is removed from a group
cache.delete(f"user_{instance.id}_groups") cache.delete(f"user_{instance.pk}_groups")

View File

@ -24,15 +24,15 @@
# #
import datetime import datetime
import phonenumbers
import phonenumbers
from django import template from django import template
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ngettext from django.utils.translation import ngettext
from core.scss.processor import ScssProcessor
from core.markdown import markdown as md from core.markdown import markdown as md
from core.scss.processor import ScssProcessor
register = template.Library() register = template.Library()

View File

@ -1,6 +1,6 @@
from django.template.exceptions import TemplateSyntaxError
from django import template from django import template
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from django.template.exceptions import TemplateSyntaxError
register = template.Library() register = template.Library()

View File

@ -25,12 +25,12 @@
from django.urls import path, re_path, register_converter from django.urls import path, re_path, register_converter
from core.views import *
from core.converters import ( from core.converters import (
BooleanStringConverter,
FourDigitYearConverter, FourDigitYearConverter,
TwoDigitMonthConverter, TwoDigitMonthConverter,
BooleanStringConverter,
) )
from core.views import *
register_converter(FourDigitYearConverter, "yyyy") register_converter(FourDigitYearConverter, "yyyy")
register_converter(TwoDigitMonthConverter, "mm") register_converter(TwoDigitMonthConverter, "mm")

View File

@ -26,8 +26,8 @@ from typing import Optional
import PIL import PIL
from django.conf import settings from django.conf import settings
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from PIL import ExifTags
from django.utils import timezone from django.utils import timezone
from PIL import ExifTags
def get_git_revision_short_hash() -> str: def get_git_revision_short_hash() -> str:

View File

@ -25,26 +25,21 @@
import types import types
from sentry_sdk import last_event_id from django.core.exceptions import (
from django.shortcuts import render ImproperlyConfigured,
PermissionDenied,
)
from django.http import ( from django.http import (
HttpResponseForbidden, HttpResponseForbidden,
HttpResponseNotFound, HttpResponseNotFound,
HttpResponseServerError, HttpResponseServerError,
) )
from django.template import RequestContext
from django.core.exceptions import (
PermissionDenied,
ObjectDoesNotExist,
ImproperlyConfigured,
)
from django.views.generic.base import View
from django.views.generic.edit import FormView
from django.views.generic.detail import SingleObjectMixin
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.db.models import Count from django.views.generic.base import View
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import FormView
from sentry_sdk import last_event_id
from core.models import Group
from core.views.forms import LoginForm from core.views.forms import LoginForm
@ -314,9 +309,8 @@ class QuickNotifMixin:
quick_notif_list = [] quick_notif_list = []
def dispatch(self, request, *arg, **kwargs): def dispatch(self, request, *arg, **kwargs):
self.quick_notif_list = ( # In some cases, the class can stay instanciated, so we need to reset the list
[] self.quick_notif_list = []
) # In some cases, the class can stay instanciated, so we need to reset the list
return super(QuickNotifMixin, self).dispatch(request, *arg, **kwargs) return super(QuickNotifMixin, self).dispatch(request, *arg, **kwargs)
def get_success_url(self): def get_success_url(self):
@ -362,8 +356,8 @@ class DetailFormView(SingleObjectMixin, FormView):
return super(DetailFormView, self).get_object() return super(DetailFormView, self).get_object()
from .user import *
from .page import *
from .files import * from .files import *
from .site import *
from .group import * from .group import *
from .page import *
from .site import *
from .user import *

View File

@ -15,29 +15,28 @@
# #
# This file contains all the views that concern the page model # This file contains all the views that concern the page model
from django.shortcuts import redirect, get_object_or_404
from django.utils.http import http_date
from django.views.generic import ListView, DetailView, TemplateView
from django.views.generic.edit import UpdateView, FormMixin, DeleteView
from django.views.generic.detail import SingleObjectMixin
from django.forms.models import modelform_factory
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from django.http import Http404, HttpResponse
from wsgiref.util import FileWrapper
from django.urls import reverse
from django.core.exceptions import PermissionDenied
from django import forms
import os import os
from wsgiref.util import FileWrapper
from ajax_select import make_ajax_field from ajax_select import make_ajax_field
from django import forms
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.forms.models import modelform_factory
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.utils.http import http_date
from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, ListView, TemplateView
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import DeleteView, FormMixin, UpdateView
from core.models import SithFile, RealGroup, Notification from core.models import Notification, RealGroup, SithFile
from core.views import ( from core.views import (
CanViewMixin,
CanEditMixin, CanEditMixin,
CanEditPropMixin, CanEditPropMixin,
CanViewMixin,
can_view, can_view,
) )
from counter.models import Counter from counter.models import Counter
@ -97,12 +96,10 @@ class _MultipleFieldMixin:
return result return result
class MultipleFileField(_MultipleFieldMixin, forms.FileField): class MultipleFileField(_MultipleFieldMixin, forms.FileField): ...
...
class MultipleImageField(_MultipleFieldMixin, forms.ImageField): class MultipleImageField(_MultipleFieldMixin, forms.ImageField): ...
...
class AddFilesForm(forms.Form): class AddFilesForm(forms.Form):

View File

@ -21,40 +21,37 @@
# Place - Suite 330, Boston, MA 02111-1307, USA. # Place - Suite 330, Boston, MA 02111-1307, USA.
# #
# #
import datetime
import re
from io import BytesIO
from ajax_select import make_ajax_field
from ajax_select.fields import AutoCompleteSelectField
from captcha.fields import CaptchaField from captcha.fields import CaptchaField
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.db import transaction from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
from django.templatetags.static import static
from django.urls import reverse
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import transaction
from django.forms import ( from django.forms import (
CheckboxSelectMultiple, CheckboxSelectMultiple,
Select,
DateInput, DateInput,
TextInput,
DateTimeInput, DateTimeInput,
Textarea, Textarea,
TextInput,
) )
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext
from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget
from ajax_select.fields import AutoCompleteSelectField
from ajax_select import make_ajax_field
from django.utils.dateparse import parse_datetime
from django.utils import timezone
import datetime
from django.forms.utils import to_current_timezone from django.forms.utils import to_current_timezone
from django.templatetags.static import static
import re from django.urls import reverse
from django.utils import timezone
from core.models import User, Page, SithFile, Gift from django.utils.dateparse import parse_datetime
from django.utils.translation import gettext
from core.utils import resize_image from django.utils.translation import gettext_lazy as _
from io import BytesIO from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget
from PIL import Image from PIL import Image
from core.models import Gift, Page, SithFile, User
from core.utils import resize_image
# Widgets # Widgets

View File

@ -18,15 +18,12 @@
This module contains views to manage Groups This module contains views to manage Groups
""" """
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.views.generic import ListView
from django.views.generic.edit import FormView
from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _
from django import forms
from ajax_select.fields import AutoCompleteSelectMultipleField from ajax_select.fields import AutoCompleteSelectMultipleField
from django import forms
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import ListView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from core.models import RealGroup, User from core.models import RealGroup, User
from core.views import CanCreateMixin, CanEditMixin, DetailFormView from core.views import CanCreateMixin, CanEditMixin, DetailFormView

View File

@ -15,16 +15,16 @@
# #
# This file contains all the views that concern the page model # This file contains all the views that concern the page model
from django.urls import reverse_lazy
from django.views.generic import ListView, DetailView
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.forms.models import modelform_factory from django.forms.models import modelform_factory
from django.http import Http404 from django.http import Http404
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.views.generic import DetailView, ListView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from core.models import Page, PageRev, LockError from core.models import LockError, Page, PageRev
from core.views import CanCreateMixin, CanEditMixin, CanEditPropMixin, CanViewMixin
from core.views.forms import MarkdownInput, PageForm, PagePropForm from core.views.forms import MarkdownInput, PageForm, PagePropForm
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
class CanEditPagePropMixin(CanEditPropMixin): class CanEditPagePropMixin(CanEditPropMixin):

View File

@ -23,23 +23,22 @@
# #
# #
from django.shortcuts import render, redirect
from django.http import JsonResponse
from django.core import serializers
from django.contrib.auth.decorators import login_required
from django.utils import html
from django.views.generic import ListView, TemplateView
from django.conf import settings
from django.utils.text import slugify
from django.db.models.query import QuerySet
import json import json
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core import serializers
from django.db.models.query import QuerySet
from django.http import JsonResponse
from django.shortcuts import redirect, render
from django.utils import html
from django.utils.text import slugify
from django.views.generic import ListView, TemplateView
from haystack.query import SearchQuerySet from haystack.query import SearchQuerySet
from core.models import User, Notification
from core.utils import doku_to_markdown, bbcode_to_markdown
from club.models import Club from club.models import Club
from core.models import Notification, User
from core.utils import bbcode_to_markdown, doku_to_markdown
def index(request, context=None): def index(request, context=None):
@ -100,9 +99,8 @@ def search_club(query, as_json=False):
if query: if query:
clubs = Club.objects.filter(name__icontains=query).all() clubs = Club.objects.filter(name__icontains=query).all()
clubs = clubs[:5] clubs = clubs[:5]
if ( if as_json:
as_json # Re-loads json to avoid double encoding by JsonResponse, but still benefit from serializers
): # Re-loads json to avoid double encoding by JsonResponse, but still benefit from serializers
clubs = json.loads(serializers.serialize("json", clubs, fields=("name"))) clubs = json.loads(serializers.serialize("json", clubs, fields=("name")))
else: else:
clubs = list(clubs) clubs = list(clubs)

View File

@ -24,50 +24,49 @@
# #
# This file contains all the views that concern the user model # This file contains all the views that concern the user model
from django.shortcuts import render, redirect, get_object_or_404 import logging
from datetime import date, timedelta
from django.conf import settings
from django.contrib.auth import views from django.contrib.auth import views
from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.forms import PasswordChangeForm
from django.utils.translation import gettext as _
from django.urls import reverse
from django.core.exceptions import PermissionDenied, ValidationError from django.core.exceptions import PermissionDenied, ValidationError
from django.forms import CheckboxSelectMultiple
from django.forms.models import modelform_factory
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.views.generic.edit import UpdateView from django.shortcuts import get_object_or_404, redirect, render
from django.template.response import TemplateResponse
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext as _
from django.views.generic import ( from django.views.generic import (
ListView,
DetailView,
TemplateView,
CreateView, CreateView,
DeleteView, DeleteView,
DetailView,
ListView,
TemplateView,
) )
from django.forms.models import modelform_factory from django.views.generic.dates import MonthMixin, YearMixin
from django.forms import CheckboxSelectMultiple from django.views.generic.edit import UpdateView
from django.urls import reverse_lazy
from django.template.response import TemplateResponse
from django.conf import settings
from django.views.generic.dates import YearMixin, MonthMixin
from datetime import timedelta, date
import logging
from api.views.sas import all_pictures_of_user from api.views.sas import all_pictures_of_user
from core.models import Gift, Preferences, SithFile, User
from core.views import ( from core.views import (
CanViewMixin,
CanEditMixin, CanEditMixin,
CanEditPropMixin, CanEditPropMixin,
UserIsLoggedMixin, CanViewMixin,
TabedViewMixin,
QuickNotifMixin, QuickNotifMixin,
TabedViewMixin,
UserIsLoggedMixin,
) )
from core.views.forms import ( from core.views.forms import (
RegisteringForm,
UserProfileForm,
LoginForm,
UserGodfathersForm,
GiftForm, GiftForm,
LoginForm,
RegisteringForm,
UserGodfathersForm,
UserProfileForm,
) )
from core.models import User, SithFile, Preferences, Gift
from subscription.models import Subscription
from counter.forms import StudentCardForm from counter.forms import StudentCardForm
from subscription.models import Subscription
from trombi.views import UserTrombiForm from trombi.views import UserTrombiForm
@ -501,9 +500,10 @@ class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs = super(UserStatsView, self).get_context_data(**kwargs) kwargs = super(UserStatsView, self).get_context_data(**kwargs)
from counter.models import Counter
from django.db.models import Sum from django.db.models import Sum
from counter.models import Counter
foyer = Counter.objects.filter(name="Foyer").first() foyer = Counter.objects.filter(name="Foyer").first()
mde = Counter.objects.filter(name="MDE").first() mde = Counter.objects.filter(name="MDE").first()
gommette = Counter.objects.filter(name="La Gommette").first() gommette = Counter.objects.filter(name="La Gommette").first()
@ -601,10 +601,12 @@ class UserUploadProfilePictView(CanEditMixin, DetailView):
template_name = "core/user_edit.jinja" template_name = "core/user_edit.jinja"
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
from core.utils import resize_image
from io import BytesIO from io import BytesIO
from PIL import Image from PIL import Image
from core.utils import resize_image
self.object = self.get_object() self.object = self.get_object()
if self.object.profile_pict: if self.object.profile_pict:
raise ValidationError(_("User already has a profile picture")) raise ValidationError(_("User already has a profile picture"))

View File

@ -31,4 +31,4 @@ class CounterConfig(AppConfig):
verbose_name = _("counter") verbose_name = _("counter")
def ready(self): def ready(self):
import counter.signals import counter.signals # noqa F401

View File

@ -3,15 +3,15 @@ from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultip
from django import forms from django import forms
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from core.views.forms import TzAwareDateTimeField, SelectDate from core.views.forms import SelectDate, TzAwareDateTimeField
from counter.models import ( from counter.models import (
BillingInfo, BillingInfo,
StudentCard,
Customer,
Refilling,
Counter, Counter,
Product, Customer,
Eticket, Eticket,
Product,
Refilling,
StudentCard,
) )

View File

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import accounting.models
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings from django.conf import settings
import django.db.models.deletion from django.db import migrations, models
import accounting.models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import accounting.models
import django.db.models.deletion import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import accounting.models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import datetime import datetime
from django.db import migrations, models
from django.utils.timezone import utc from django.utils.timezone import utc

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils.translation import gettext_lazy as _
from django.db import migrations, models
from django.conf import settings from django.conf import settings
from django.db import migrations, models
from django.utils.translation import gettext_lazy as _
from core.models import User from core.models import User
from counter.models import Customer, Product, Selling, Counter from counter.models import Counter, Customer, Product, Selling
def balance_ecocups(apps, schema_editor): def balance_ecocups(apps, schema_editor):

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -3,8 +3,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import django.core.validators import django.core.validators
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,8 @@
# Generated by Django 3.2.16 on 2023-01-08 12:49 # Generated by Django 3.2.16 on 2023-01-08 12:49
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import django_countries.fields import django_countries.fields
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -1,8 +1,9 @@
# Generated by Django 3.2.16 on 2022-12-15 16:09 # Generated by Django 3.2.16 on 2022-12-15 16:09
import accounting.models
from django.db import migrations from django.db import migrations
import accounting.models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [

Some files were not shown because too many files have changed in this diff Show More