Upgrade black and format accordingly

This commit is contained in:
Antoine Bartuccio 2020-08-27 15:59:42 +02:00
parent f485178422
commit f34f5fe693
Signed by: klmp200
GPG Key ID: E7245548C53F904B
24 changed files with 88 additions and 91 deletions

View File

@ -33,8 +33,8 @@ from core.views import can_view, can_edit
def check_if(obj, user, test): def check_if(obj, user, test):
""" """
Detect if it's a single object or a queryset Detect if it's a single object or a queryset
aply a given test on individual object and return global permission aply a given test on individual object and return global permission
""" """
if isinstance(obj, QuerySet): if isinstance(obj, QuerySet):
for o in obj: for o in obj:
@ -49,7 +49,7 @@ class ManageModelMixin:
@action(detail=True) @action(detail=True)
def id(self, request, pk=None): def id(self, request, pk=None):
""" """
Get by id (api/v1/router/{pk}/id/) Get by id (api/v1/router/{pk}/id/)
""" """
self.queryset = get_object_or_404(self.queryset.filter(id=pk)) self.queryset = get_object_or_404(self.queryset.filter(id=pk))
serializer = self.get_serializer(self.queryset) serializer = self.get_serializer(self.queryset)

View File

@ -33,7 +33,7 @@ from core.templatetags.renderer import markdown
@renderer_classes((StaticHTMLRenderer,)) @renderer_classes((StaticHTMLRenderer,))
def RenderMarkdown(request): def RenderMarkdown(request):
""" """
Render Markdown Render Markdown
""" """
try: try:
data = markdown(request.POST["text"]) data = markdown(request.POST["text"])

View File

@ -43,7 +43,7 @@ class ClubSerializer(serializers.ModelSerializer):
class ClubViewSet(RightModelViewSet): class ClubViewSet(RightModelViewSet):
""" """
Manage Clubs (api/v1/club/) Manage Clubs (api/v1/club/)
""" """
serializer_class = ClubSerializer serializer_class = ClubSerializer

View File

@ -45,7 +45,7 @@ class CounterSerializer(serializers.ModelSerializer):
class CounterViewSet(RightModelViewSet): class CounterViewSet(RightModelViewSet):
""" """
Manage Counters (api/v1/counter/) Manage Counters (api/v1/counter/)
""" """
serializer_class = CounterSerializer serializer_class = CounterSerializer
@ -54,7 +54,7 @@ class CounterViewSet(RightModelViewSet):
@action(detail=False) @action(detail=False)
def bar(self, request): def bar(self, request):
""" """
Return all bars (api/v1/counter/bar/) Return all bars (api/v1/counter/bar/)
""" """
self.queryset = self.queryset.filter(type="BAR") self.queryset = self.queryset.filter(type="BAR")
serializer = self.get_serializer(self.queryset, many=True) serializer = self.get_serializer(self.queryset, many=True)

View File

@ -36,7 +36,7 @@ class GroupSerializer(serializers.ModelSerializer):
class GroupViewSet(RightModelViewSet): class GroupViewSet(RightModelViewSet):
""" """
Manage Groups (api/v1/group/) Manage Groups (api/v1/group/)
""" """
serializer_class = GroupSerializer serializer_class = GroupSerializer

View File

@ -72,7 +72,7 @@ class LaunderetteTokenSerializer(serializers.ModelSerializer):
class LaunderettePlaceViewSet(RightModelViewSet): class LaunderettePlaceViewSet(RightModelViewSet):
""" """
Manage Launderette (api/v1/launderette/place/) Manage Launderette (api/v1/launderette/place/)
""" """
serializer_class = LaunderettePlaceSerializer serializer_class = LaunderettePlaceSerializer
@ -81,7 +81,7 @@ class LaunderettePlaceViewSet(RightModelViewSet):
class LaunderetteMachineViewSet(RightModelViewSet): class LaunderetteMachineViewSet(RightModelViewSet):
""" """
Manage Washing Machines (api/v1/launderette/machine/) Manage Washing Machines (api/v1/launderette/machine/)
""" """
serializer_class = LaunderetteMachineSerializer serializer_class = LaunderetteMachineSerializer
@ -90,7 +90,7 @@ class LaunderetteMachineViewSet(RightModelViewSet):
class LaunderetteTokenViewSet(RightModelViewSet): class LaunderetteTokenViewSet(RightModelViewSet):
""" """
Manage Launderette's tokens (api/v1/launderette/token/) Manage Launderette's tokens (api/v1/launderette/token/)
""" """
serializer_class = LaunderetteTokenSerializer serializer_class = LaunderetteTokenSerializer
@ -99,7 +99,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False) @action(detail=False)
def washing(self, request): def washing(self, request):
""" """
Return all washing tokens (api/v1/launderette/token/washing) Return all washing tokens (api/v1/launderette/token/washing)
""" """
self.queryset = self.queryset.filter(type="WASHING") self.queryset = self.queryset.filter(type="WASHING")
serializer = self.get_serializer(self.queryset, many=True) serializer = self.get_serializer(self.queryset, many=True)
@ -108,7 +108,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False) @action(detail=False)
def drying(self, request): def drying(self, request):
""" """
Return all drying tokens (api/v1/launderette/token/drying) Return all drying tokens (api/v1/launderette/token/drying)
""" """
self.queryset = self.queryset.filter(type="DRYING") self.queryset = self.queryset.filter(type="DRYING")
serializer = self.get_serializer(self.queryset, many=True) serializer = self.get_serializer(self.queryset, many=True)
@ -117,7 +117,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False) @action(detail=False)
def avaliable(self, request): def avaliable(self, request):
""" """
Return all avaliable tokens (api/v1/launderette/token/avaliable) Return all avaliable tokens (api/v1/launderette/token/avaliable)
""" """
self.queryset = self.queryset.filter( self.queryset = self.queryset.filter(
borrow_date__isnull=True, user__isnull=True borrow_date__isnull=True, user__isnull=True
@ -128,7 +128,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False) @action(detail=False)
def unavaliable(self, request): def unavaliable(self, request):
""" """
Return all unavaliable tokens (api/v1/launderette/token/unavaliable) Return all unavaliable tokens (api/v1/launderette/token/unavaliable)
""" """
self.queryset = self.queryset.filter( self.queryset = self.queryset.filter(
borrow_date__isnull=False, user__isnull=False borrow_date__isnull=False, user__isnull=False

View File

@ -50,8 +50,8 @@ class UserSerializer(serializers.ModelSerializer):
class UserViewSet(RightModelViewSet): class UserViewSet(RightModelViewSet):
""" """
Manage Users (api/v1/user/) Manage Users (api/v1/user/)
Only show active users Only show active users
""" """
serializer_class = UserSerializer serializer_class = UserSerializer
@ -60,7 +60,7 @@ class UserViewSet(RightModelViewSet):
@action(detail=False) @action(detail=False)
def birthday(self, request): def birthday(self, request):
""" """
Return all users born today (api/v1/user/birstdays) Return all users born today (api/v1/user/birstdays)
""" """
date = datetime.datetime.today() date = datetime.datetime.today()
self.queryset = self.queryset.filter(date_of_birth=date) self.queryset = self.queryset.filter(date_of_birth=date)

View File

@ -29,10 +29,10 @@ def uv_endpoint(request):
def find_uv(lang, year, code): def find_uv(lang, year, code):
""" """
Uses the UTBM API to find an UV. Uses the UTBM API to find an UV.
short_uv is the UV entry in the UV list. It is returned as it contains short_uv is the UV entry in the UV list. It is returned as it contains
information which are not in full_uv. information which are not in full_uv.
full_uv is the detailed representation of an UV. full_uv is the detailed representation of an UV.
""" """
# query the UV list # query the UV list
uvs_url = settings.SITH_PEDAGOGY_UTBM_API + "/uvs/{}/{}".format(lang, year) uvs_url = settings.SITH_PEDAGOGY_UTBM_API + "/uvs/{}/{}".format(lang, year)
@ -57,7 +57,7 @@ def find_uv(lang, year, code):
def make_clean_uv(short_uv, full_uv): def make_clean_uv(short_uv, full_uv):
""" """
Cleans the data up so that it corresponds to our data representation. Cleans the data up so that it corresponds to our data representation.
""" """
res = {} res = {}

View File

@ -252,8 +252,8 @@ class ClubMemberForm(forms.Form):
def clean_users(self): def clean_users(self):
""" """
Check that the user is not trying to add an user already in the club Check that the user is not trying to add an user already in the club
Also check that the user is valid and has a valid subscription Also check that the user is valid and has a valid subscription
""" """
cleaned_data = super(ClubMemberForm, self).clean() cleaned_data = super(ClubMemberForm, self).clean()
users = [] users = []
@ -276,7 +276,7 @@ class ClubMemberForm(forms.Form):
def clean(self): def clean(self):
""" """
Check user rights for adding an user Check user rights for adding an user
""" """
cleaned_data = super(ClubMemberForm, self).clean() cleaned_data = super(ClubMemberForm, self).clean()

View File

@ -290,7 +290,7 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, DetailFormView):
def form_valid(self, form): def form_valid(self, form):
""" """
Check user rights Check user rights
""" """
resp = super(ClubMembersView, self).form_valid(form) resp = super(ClubMembersView, self).form_valid(form)

View File

@ -31,7 +31,7 @@ from django.conf import settings
class Command(BaseCommand): class Command(BaseCommand):
""" """
Compiles scss in static folder for production Compiles scss in static folder for production
""" """
help = "Compile scss files from static folder" help = "Compile scss files from static folder"

View File

@ -1490,7 +1490,9 @@ class OperationLog(models.Model):
User, related_name="logs", on_delete=models.SET_NULL, null=True User, related_name="logs", on_delete=models.SET_NULL, null=True
) )
operation_type = models.CharField( operation_type = models.CharField(
_("operation type"), max_length=40, choices=settings.SITH_LOG_OPERATION_TYPE, _("operation type"),
max_length=40,
choices=settings.SITH_LOG_OPERATION_TYPE,
) )
def is_owned_by(self, user): def is_owned_by(self, user):

View File

@ -33,16 +33,16 @@ from django.db import connection, migrations
class PsqlRunOnly(migrations.RunSQL): class PsqlRunOnly(migrations.RunSQL):
""" """
This is an SQL runner that will launch the given command only if This is an SQL runner that will launch the given command only if
the used DBMS is PostgreSQL. the used DBMS is PostgreSQL.
It may be useful to run Postgres' specific SQL, or to take actions It may be useful to run Postgres' specific SQL, or to take actions
that would be non-senses with backends other than Postgre, such that would be non-senses with backends other than Postgre, such
as disabling particular constraints that would prevent the migration as disabling particular constraints that would prevent the migration
to run successfully. to run successfully.
See `club/migrations/0010_auto_20170912_2028.py` as an example. See `club/migrations/0010_auto_20170912_2028.py` as an example.
Some explanations can be found here too: Some explanations can be found here too:
https://stackoverflow.com/questions/28429933/django-migrations-using-runpython-to-commit-changes https://stackoverflow.com/questions/28429933/django-migrations-using-runpython-to-commit-changes
""" """
def _run_sql(self, schema_editor, sqls): def _run_sql(self, schema_editor, sqls):

View File

@ -35,9 +35,9 @@ from core.scss.storage import ScssFileStorage, find_file
class ScssProcessor(object): class ScssProcessor(object):
""" """
If DEBUG mode enabled : compile the scss file If DEBUG mode enabled : compile the scss file
Else : give the path of the corresponding css supposed to already be compiled Else : give the path of the corresponding css supposed to already be compiled
Don't forget to use compilestatics to compile scss for production Don't forget to use compilestatics to compile scss for production
""" """
prefix = iri_to_uri(getattr(settings, "STATIC_URL", "/static/")) prefix = iri_to_uri(getattr(settings, "STATIC_URL", "/static/"))

View File

@ -94,7 +94,7 @@ def datetime_format_python_to_PHP(python_format_string):
@register.simple_tag() @register.simple_tag()
def scss(path): def scss(path):
""" """
Return path of the corresponding css file after compilation Return path of the corresponding css file after compilation
""" """
processor = ScssProcessor(path) processor = ScssProcessor(path)
return processor.get_converted_scss() return processor.get_converted_scss()

View File

@ -344,19 +344,19 @@ class QuickNotifMixin:
class DetailFormView(SingleObjectMixin, FormView): class DetailFormView(SingleObjectMixin, FormView):
""" """
Class that allow both a detail view and a form view Class that allow both a detail view and a form view
""" """
def get_object(self): def get_object(self):
""" """
Get current group from id in url Get current group from id in url
""" """
return self.cached_object return self.cached_object
@cached_property @cached_property
def cached_object(self): def cached_object(self):
""" """
Optimisation on group retrieval Optimisation on group retrieval
""" """
return super(DetailFormView, self).get_object() return super(DetailFormView, self).get_object()

View File

@ -114,14 +114,11 @@ class SelectFile(TextInput):
attrs["class"] = "select_file" attrs["class"] = "select_file"
else: else:
attrs = {"class": "select_file"} attrs = {"class": "select_file"}
output = ( output = '%(content)s<div name="%(name)s" class="choose_file_widget" title="%(title)s"></div>' % {
'%(content)s<div name="%(name)s" class="choose_file_widget" title="%(title)s"></div>' "content": super(SelectFile, self).render(name, value, attrs, renderer),
% { "title": _("Choose file"),
"content": super(SelectFile, self).render(name, value, attrs, renderer), "name": name,
"title": _("Choose file"), }
"name": name,
}
)
output += ( output += (
'<span name="' '<span name="'
+ name + name
@ -138,14 +135,11 @@ class SelectUser(TextInput):
attrs["class"] = "select_user" attrs["class"] = "select_user"
else: else:
attrs = {"class": "select_user"} attrs = {"class": "select_user"}
output = ( output = '%(content)s<div name="%(name)s" class="choose_user_widget" title="%(title)s"></div>' % {
'%(content)s<div name="%(name)s" class="choose_user_widget" title="%(title)s"></div>' "content": super(SelectUser, self).render(name, value, attrs, renderer),
% { "title": _("Choose user"),
"content": super(SelectUser, self).render(name, value, attrs, renderer), "name": name,
"title": _("Choose user"), }
"name": name,
}
)
output += ( output += (
'<span name="' '<span name="'
+ name + name

View File

@ -44,7 +44,7 @@ from core.views import CanEditMixin, DetailFormView
class EditMembersForm(forms.Form): class EditMembersForm(forms.Form):
""" """
Add and remove members from a Group Add and remove members from a Group
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -66,7 +66,7 @@ class EditMembersForm(forms.Form):
def clean_users_added(self): def clean_users_added(self):
""" """
Check that the user is not trying to add an user already in the group Check that the user is not trying to add an user already in the group
""" """
cleaned_data = super(EditMembersForm, self).clean() cleaned_data = super(EditMembersForm, self).clean()
users_added = cleaned_data.get("users_added", None) users_added = cleaned_data.get("users_added", None)
@ -100,7 +100,7 @@ class GroupListView(CanEditMixin, ListView):
class GroupEditView(CanEditMixin, UpdateView): class GroupEditView(CanEditMixin, UpdateView):
""" """
Edit infos of a Group Edit infos of a Group
""" """
model = RealGroup model = RealGroup
@ -111,7 +111,7 @@ class GroupEditView(CanEditMixin, UpdateView):
class GroupCreateView(CanEditMixin, CreateView): class GroupCreateView(CanEditMixin, CreateView):
""" """
Add a new Group Add a new Group
""" """
model = RealGroup model = RealGroup
@ -121,8 +121,8 @@ class GroupCreateView(CanEditMixin, CreateView):
class GroupTemplateView(CanEditMixin, DetailFormView): class GroupTemplateView(CanEditMixin, DetailFormView):
""" """
Display all users in a given Group Display all users in a given Group
Allow adding and removing users from it Allow adding and removing users from it
""" """
model = RealGroup model = RealGroup
@ -156,7 +156,7 @@ class GroupTemplateView(CanEditMixin, DetailFormView):
class GroupDeleteView(CanEditMixin, DeleteView): class GroupDeleteView(CanEditMixin, DeleteView):
""" """
Delete a Group Delete a Group
""" """
model = RealGroup model = RealGroup

View File

@ -89,9 +89,9 @@ class Customer(models.Model):
def save(self, allow_negative=False, is_selling=False, *args, **kwargs): def save(self, allow_negative=False, is_selling=False, *args, **kwargs):
""" """
is_selling : tell if the current action is a selling is_selling : tell if the current action is a selling
allow_negative : ignored if not a selling. Allow a selling to put the account in negative allow_negative : ignored if not a selling. Allow a selling to put the account in negative
Those two parameters avoid blocking the save method of a customer if his account is negative Those two parameters avoid blocking the save method of a customer if his account is negative
""" """
if self.amount < 0 and (is_selling and not allow_negative): if self.amount < 0 and (is_selling and not allow_negative):
raise ValidationError(_("Not enough money")) raise ValidationError(_("Not enough money"))
@ -527,7 +527,7 @@ class Selling(models.Model):
def save(self, allow_negative=False, *args, **kwargs): def save(self, allow_negative=False, *args, **kwargs):
""" """
allow_negative : Allow this selling to use more money than available for this user allow_negative : Allow this selling to use more money than available for this user
""" """
if not self.date: if not self.date:
self.date = timezone.now() self.date = timezone.now()

View File

@ -55,7 +55,9 @@ def write_log(instance, operation_type):
return None return None
log = OperationLog( log = OperationLog(
label=str(instance), operator=get_user(), operation_type=operation_type, label=str(instance),
operator=get_user(),
operation_type=operation_type,
).save() ).save()

View File

@ -24,8 +24,8 @@ from ajax_select import make_ajax_field
class LimitedCheckboxField(forms.ModelMultipleChoiceField): class LimitedCheckboxField(forms.ModelMultipleChoiceField):
""" """
Used to replace ModelMultipleChoiceField but with Used to replace ModelMultipleChoiceField but with
automatic backend verification automatic backend verification
""" """
def __init__(self, queryset, max_choice, **kwargs): def __init__(self, queryset, max_choice, **kwargs):
@ -308,7 +308,7 @@ class VoteFormView(CanCreateMixin, FormView):
def form_valid(self, form): def form_valid(self, form):
""" """
Verify that the user is part in a vote group Verify that the user is part in a vote group
""" """
data = form.clean() data = form.clean()
res = super(FormView, self).form_valid(form) res = super(FormView, self).form_valid(form)
@ -360,7 +360,7 @@ class CandidatureCreateView(CanCreateMixin, CreateView):
def form_valid(self, form): def form_valid(self, form):
""" """
Verify that the selected user is in candidate group Verify that the selected user is in candidate group
""" """
obj = form.instance obj = form.instance
obj.election = Election.objects.get(id=self.election.id) obj.election = Election.objects.get(id=self.election.id)
@ -391,8 +391,8 @@ class ElectionCreateView(CanCreateMixin, CreateView):
def form_valid(self, form): def form_valid(self, form):
""" """
Allow every users that had passed the dispatch Allow every users that had passed the dispatch
to create an election to create an election
""" """
return super(CreateView, self).form_valid(form) return super(CreateView, self).form_valid(form)
@ -418,7 +418,7 @@ class RoleCreateView(CanCreateMixin, CreateView):
def form_valid(self, form): def form_valid(self, form):
""" """
Verify that the user can edit proprely Verify that the user can edit proprely
""" """
obj = form.instance obj = form.instance
if obj.election: if obj.election:
@ -461,7 +461,7 @@ class ElectionListCreateView(CanCreateMixin, CreateView):
def form_valid(self, form): def form_valid(self, form):
""" """
Verify that the user can vote on this election Verify that the user can vote on this election
""" """
obj = form.instance obj = form.instance
if obj.election: if obj.election:

View File

@ -31,7 +31,7 @@ from rootplace.views import delete_all_forum_user_messages
class Command(BaseCommand): class Command(BaseCommand):
""" """
Delete all forum messages from a user Delete all forum messages from a user
""" """
help = "Delete all user's forum message" help = "Delete all user's forum message"

View File

@ -93,10 +93,10 @@ def merge_users(u1, u2):
def delete_all_forum_user_messages(user, moderator, verbose=False): def delete_all_forum_user_messages(user, moderator, verbose=False):
""" """
Create a ForumMessageMeta that says a forum Create a ForumMessageMeta that says a forum
message is deleted on every forum message of an user message is deleted on every forum message of an user
user: the user to delete messages from user: the user to delete messages from
moderator: the one marked as the moderator moderator: the one marked as the moderator
""" """
for message in user.forum_messages.all(): for message in user.forum_messages.all():
if message.is_deleted(): if message.is_deleted():
@ -144,9 +144,9 @@ class MergeUsersView(FormView):
class DeleteAllForumUserMessagesView(FormView): class DeleteAllForumUserMessagesView(FormView):
""" """
Delete all forum messages from an user Delete all forum messages from an user
Messages are soft deleted and are still visible from admins Messages are soft deleted and are still visible from admins
GUI frontend to the dedicated command GUI frontend to the dedicated command
""" """
template_name = "rootplace/delete_user_messages.jinja" template_name = "rootplace/delete_user_messages.jinja"

View File

@ -120,8 +120,7 @@ class ShoppingList(models.Model):
class ShoppingListItem(models.Model): class ShoppingListItem(models.Model):
""" """"""
"""
shopping_lists = models.ManyToManyField( shopping_lists = models.ManyToManyField(
ShoppingList, ShoppingList,