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):
"""
Detect if it's a single object or a queryset
aply a given test on individual object and return global permission
Detect if it's a single object or a queryset
aply a given test on individual object and return global permission
"""
if isinstance(obj, QuerySet):
for o in obj:
@ -49,7 +49,7 @@ class ManageModelMixin:
@action(detail=True)
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))
serializer = self.get_serializer(self.queryset)

View File

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

View File

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

View File

@ -45,7 +45,7 @@ class CounterSerializer(serializers.ModelSerializer):
class CounterViewSet(RightModelViewSet):
"""
Manage Counters (api/v1/counter/)
Manage Counters (api/v1/counter/)
"""
serializer_class = CounterSerializer
@ -54,7 +54,7 @@ class CounterViewSet(RightModelViewSet):
@action(detail=False)
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")
serializer = self.get_serializer(self.queryset, many=True)

View File

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

View File

@ -72,7 +72,7 @@ class LaunderetteTokenSerializer(serializers.ModelSerializer):
class LaunderettePlaceViewSet(RightModelViewSet):
"""
Manage Launderette (api/v1/launderette/place/)
Manage Launderette (api/v1/launderette/place/)
"""
serializer_class = LaunderettePlaceSerializer
@ -81,7 +81,7 @@ class LaunderettePlaceViewSet(RightModelViewSet):
class LaunderetteMachineViewSet(RightModelViewSet):
"""
Manage Washing Machines (api/v1/launderette/machine/)
Manage Washing Machines (api/v1/launderette/machine/)
"""
serializer_class = LaunderetteMachineSerializer
@ -90,7 +90,7 @@ class LaunderetteMachineViewSet(RightModelViewSet):
class LaunderetteTokenViewSet(RightModelViewSet):
"""
Manage Launderette's tokens (api/v1/launderette/token/)
Manage Launderette's tokens (api/v1/launderette/token/)
"""
serializer_class = LaunderetteTokenSerializer
@ -99,7 +99,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False)
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")
serializer = self.get_serializer(self.queryset, many=True)
@ -108,7 +108,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False)
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")
serializer = self.get_serializer(self.queryset, many=True)
@ -117,7 +117,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False)
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(
borrow_date__isnull=True, user__isnull=True
@ -128,7 +128,7 @@ class LaunderetteTokenViewSet(RightModelViewSet):
@action(detail=False)
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(
borrow_date__isnull=False, user__isnull=False

View File

@ -50,8 +50,8 @@ class UserSerializer(serializers.ModelSerializer):
class UserViewSet(RightModelViewSet):
"""
Manage Users (api/v1/user/)
Only show active users
Manage Users (api/v1/user/)
Only show active users
"""
serializer_class = UserSerializer
@ -60,7 +60,7 @@ class UserViewSet(RightModelViewSet):
@action(detail=False)
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()
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):
"""
Uses the UTBM API to find an UV.
short_uv is the UV entry in the UV list. It is returned as it contains
information which are not in full_uv.
full_uv is the detailed representation of 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
information which are not in full_uv.
full_uv is the detailed representation of an UV.
"""
# query the UV list
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):
"""
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 = {}

View File

@ -252,8 +252,8 @@ class ClubMemberForm(forms.Form):
def clean_users(self):
"""
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
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
"""
cleaned_data = super(ClubMemberForm, self).clean()
users = []
@ -276,7 +276,7 @@ class ClubMemberForm(forms.Form):
def clean(self):
"""
Check user rights for adding an user
Check user rights for adding an user
"""
cleaned_data = super(ClubMemberForm, self).clean()

View File

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

View File

@ -31,7 +31,7 @@ from django.conf import settings
class Command(BaseCommand):
"""
Compiles scss in static folder for production
Compiles scss in static folder for production
"""
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
)
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):

View File

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

View File

@ -35,9 +35,9 @@ from core.scss.storage import ScssFileStorage, find_file
class ScssProcessor(object):
"""
If DEBUG mode enabled : compile the scss file
Else : give the path of the corresponding css supposed to already be compiled
Don't forget to use compilestatics to compile scss for production
If DEBUG mode enabled : compile the scss file
Else : give the path of the corresponding css supposed to already be compiled
Don't forget to use compilestatics to compile scss for production
"""
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()
def scss(path):
"""
Return path of the corresponding css file after compilation
Return path of the corresponding css file after compilation
"""
processor = ScssProcessor(path)
return processor.get_converted_scss()

View File

@ -344,19 +344,19 @@ class QuickNotifMixin:
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):
"""
Get current group from id in url
Get current group from id in url
"""
return self.cached_object
@cached_property
def cached_object(self):
"""
Optimisation on group retrieval
Optimisation on group retrieval
"""
return super(DetailFormView, self).get_object()

View File

@ -114,14 +114,11 @@ class SelectFile(TextInput):
attrs["class"] = "select_file"
else:
attrs = {"class": "select_file"}
output = (
'%(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"),
"name": name,
}
)
output = '%(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"),
"name": name,
}
output += (
'<span name="'
+ name
@ -138,14 +135,11 @@ class SelectUser(TextInput):
attrs["class"] = "select_user"
else:
attrs = {"class": "select_user"}
output = (
'%(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"),
"name": name,
}
)
output = '%(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"),
"name": name,
}
output += (
'<span name="'
+ name

View File

@ -44,7 +44,7 @@ from core.views import CanEditMixin, DetailFormView
class EditMembersForm(forms.Form):
"""
Add and remove members from a Group
Add and remove members from a Group
"""
def __init__(self, *args, **kwargs):
@ -66,7 +66,7 @@ class EditMembersForm(forms.Form):
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()
users_added = cleaned_data.get("users_added", None)
@ -100,7 +100,7 @@ class GroupListView(CanEditMixin, ListView):
class GroupEditView(CanEditMixin, UpdateView):
"""
Edit infos of a Group
Edit infos of a Group
"""
model = RealGroup
@ -111,7 +111,7 @@ class GroupEditView(CanEditMixin, UpdateView):
class GroupCreateView(CanEditMixin, CreateView):
"""
Add a new Group
Add a new Group
"""
model = RealGroup
@ -121,8 +121,8 @@ class GroupCreateView(CanEditMixin, CreateView):
class GroupTemplateView(CanEditMixin, DetailFormView):
"""
Display all users in a given Group
Allow adding and removing users from it
Display all users in a given Group
Allow adding and removing users from it
"""
model = RealGroup
@ -156,7 +156,7 @@ class GroupTemplateView(CanEditMixin, DetailFormView):
class GroupDeleteView(CanEditMixin, DeleteView):
"""
Delete a Group
Delete a Group
"""
model = RealGroup

View File

@ -89,9 +89,9 @@ class Customer(models.Model):
def save(self, allow_negative=False, is_selling=False, *args, **kwargs):
"""
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
Those two parameters avoid blocking the save method of a customer if his account is negative
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
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):
raise ValidationError(_("Not enough money"))
@ -527,7 +527,7 @@ class Selling(models.Model):
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:
self.date = timezone.now()

View File

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

View File

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

View File

@ -31,7 +31,7 @@ from rootplace.views import delete_all_forum_user_messages
class Command(BaseCommand):
"""
Delete all forum messages from a user
Delete all forum messages from a user
"""
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):
"""
Create a ForumMessageMeta that says a forum
message is deleted on every forum message of an user
user: the user to delete messages from
moderator: the one marked as the moderator
Create a ForumMessageMeta that says a forum
message is deleted on every forum message of an user
user: the user to delete messages from
moderator: the one marked as the moderator
"""
for message in user.forum_messages.all():
if message.is_deleted():
@ -144,9 +144,9 @@ class MergeUsersView(FormView):
class DeleteAllForumUserMessagesView(FormView):
"""
Delete all forum messages from an user
Messages are soft deleted and are still visible from admins
GUI frontend to the dedicated command
Delete all forum messages from an user
Messages are soft deleted and are still visible from admins
GUI frontend to the dedicated command
"""
template_name = "rootplace/delete_user_messages.jinja"

View File

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