Commit cb58b00b authored by Sli's avatar Sli

All: Apply Black coding rules

parent 0581c667
...@@ -8,11 +8,12 @@ setup: ...@@ -8,11 +8,12 @@ setup:
- apt-get update - apt-get update
- apt-get install -y gettext - apt-get install -y gettext
- pip install -r requirements.txt - pip install -r requirements.txt
- pip install coverage
- pip install black
test: test:
stage: test stage: test
script: script:
- pip install coverage
- ./manage.py compilemessages - ./manage.py compilemessages
- coverage run ./manage.py test - coverage run ./manage.py test
- coverage html - coverage html
...@@ -24,5 +25,4 @@ test: ...@@ -24,5 +25,4 @@ test:
black: black:
stage: test stage: test
script: script:
- pip install black
- black --check . - black --check .
[![pipeline status](https://ae-dev.utbm.fr/ae/Sith/badges/master/pipeline.svg)](https://ae-dev.utbm.fr/ae/Sith/commits/master) [![pipeline status](https://ae-dev.utbm.fr/ae/Sith/badges/master/pipeline.svg)](https://ae-dev.utbm.fr/ae/Sith/commits/master)
[![coverage report](https://ae-dev.utbm.fr/ae/Sith/badges/master/coverage.svg)](https://ae-dev.utbm.fr/ae/Sith/commits/master) [![coverage report](https://ae-dev.utbm.fr/ae/Sith/badges/master/coverage.svg)](https://ae-dev.utbm.fr/ae/Sith/commits/master)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
## Sith AE ## Sith AE
......
...@@ -21,4 +21,3 @@ ...@@ -21,4 +21,3 @@
# Place - Suite 330, Boston, MA 02111-1307, USA. # Place - Suite 330, Boston, MA 02111-1307, USA.
# #
# #
This diff is collapsed.
...@@ -7,54 +7,88 @@ from django.db import migrations, models ...@@ -7,54 +7,88 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('club', '0001_initial'), ("club", "0001_initial"),
('accounting', '0001_initial'), ("accounting", "0001_initial"),
('core', '0001_initial'), ("core", "0001_initial"),
] ]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='operation', model_name="operation",
name='invoice', name="invoice",
field=models.ForeignKey(null=True, related_name='operations', verbose_name='invoice', to='core.SithFile', blank=True), field=models.ForeignKey(
null=True,
related_name="operations",
verbose_name="invoice",
to="core.SithFile",
blank=True,
),
), ),
migrations.AddField( migrations.AddField(
model_name='operation', model_name="operation",
name='journal', name="journal",
field=models.ForeignKey(verbose_name='journal', to='accounting.GeneralJournal', related_name='operations'), field=models.ForeignKey(
verbose_name="journal",
to="accounting.GeneralJournal",
related_name="operations",
),
), ),
migrations.AddField( migrations.AddField(
model_name='operation', model_name="operation",
name='linked_operation', name="linked_operation",
field=models.OneToOneField(blank=True, to='accounting.Operation', null=True, related_name='operation_linked_to', verbose_name='linked operation', default=None), field=models.OneToOneField(
blank=True,
to="accounting.Operation",
null=True,
related_name="operation_linked_to",
verbose_name="linked operation",
default=None,
),
), ),
migrations.AddField( migrations.AddField(
model_name='operation', model_name="operation",
name='simpleaccounting_type', name="simpleaccounting_type",
field=models.ForeignKey(null=True, related_name='operations', verbose_name='simple type', to='accounting.SimplifiedAccountingType', blank=True), field=models.ForeignKey(
null=True,
related_name="operations",
verbose_name="simple type",
to="accounting.SimplifiedAccountingType",
blank=True,
),
), ),
migrations.AddField( migrations.AddField(
model_name='generaljournal', model_name="generaljournal",
name='club_account', name="club_account",
field=models.ForeignKey(verbose_name='club account', to='accounting.ClubAccount', related_name='journals'), field=models.ForeignKey(
verbose_name="club account",
to="accounting.ClubAccount",
related_name="journals",
),
), ),
migrations.AddField( migrations.AddField(
model_name='clubaccount', model_name="clubaccount",
name='bank_account', name="bank_account",
field=models.ForeignKey(verbose_name='bank account', to='accounting.BankAccount', related_name='club_accounts'), field=models.ForeignKey(
verbose_name="bank account",
to="accounting.BankAccount",
related_name="club_accounts",
),
), ),
migrations.AddField( migrations.AddField(
model_name='clubaccount', model_name="clubaccount",
name='club', name="club",
field=models.ForeignKey(verbose_name='club', to='club.Club', related_name='club_account'), field=models.ForeignKey(
verbose_name="club", to="club.Club", related_name="club_account"
),
), ),
migrations.AddField( migrations.AddField(
model_name='bankaccount', model_name="bankaccount",
name='club', name="club",
field=models.ForeignKey(verbose_name='club', to='club.Club', related_name='bank_accounts'), field=models.ForeignKey(
verbose_name="club", to="club.Club", related_name="bank_accounts"
),
), ),
migrations.AlterUniqueTogether( migrations.AlterUniqueTogether(
name='operation', name="operation", unique_together=set([("number", "journal")])
unique_together=set([('number', 'journal')]),
), ),
] ]
...@@ -7,44 +7,44 @@ import phonenumber_field.modelfields ...@@ -7,44 +7,44 @@ import phonenumber_field.modelfields
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [("accounting", "0002_auto_20160824_2152")]
('accounting', '0002_auto_20160824_2152'),
]
operations = [ operations = [
migrations.AddField( migrations.AddField(
model_name='company', model_name="company",
name='city', name="city",
field=models.CharField(blank=True, verbose_name='city', max_length=60), field=models.CharField(blank=True, verbose_name="city", max_length=60),
), ),
migrations.AddField( migrations.AddField(
model_name='company', model_name="company",
name='country', name="country",
field=models.CharField(blank=True, verbose_name='country', max_length=32), field=models.CharField(blank=True, verbose_name="country", max_length=32),
), ),
migrations.AddField( migrations.AddField(
model_name='company', model_name="company",
name='email', name="email",
field=models.EmailField(blank=True, verbose_name='email', max_length=254), field=models.EmailField(blank=True, verbose_name="email", max_length=254),
), ),
migrations.AddField( migrations.AddField(
model_name='company', model_name="company",
name='phone', name="phone",
field=phonenumber_field.modelfields.PhoneNumberField(blank=True, verbose_name='phone', max_length=128), field=phonenumber_field.modelfields.PhoneNumberField(
blank=True, verbose_name="phone", max_length=128
),
), ),
migrations.AddField( migrations.AddField(
model_name='company', model_name="company",
name='postcode', name="postcode",
field=models.CharField(blank=True, verbose_name='postcode', max_length=10), field=models.CharField(blank=True, verbose_name="postcode", max_length=10),
), ),
migrations.AddField( migrations.AddField(
model_name='company', model_name="company",
name='street', name="street",
field=models.CharField(blank=True, verbose_name='street', max_length=60), field=models.CharField(blank=True, verbose_name="street", max_length=60),
), ),
migrations.AddField( migrations.AddField(
model_name='company', model_name="company",
name='website', name="website",
field=models.CharField(blank=True, verbose_name='website', max_length=64), field=models.CharField(blank=True, verbose_name="website", max_length=64),
), ),
] ]
...@@ -7,26 +7,45 @@ import django.db.models.deletion ...@@ -7,26 +7,45 @@ import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [("accounting", "0003_auto_20160824_2203")]
('accounting', '0003_auto_20160824_2203'),
]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Label', name="Label",
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)), (
('name', models.CharField(max_length=64, verbose_name='label')), "id",
('club_account', models.ForeignKey(related_name='labels', verbose_name='club account', to='accounting.ClubAccount')), models.AutoField(
verbose_name="ID",
primary_key=True,
auto_created=True,
serialize=False,
),
),
("name", models.CharField(max_length=64, verbose_name="label")),
(
"club_account",
models.ForeignKey(
related_name="labels",
verbose_name="club account",
to="accounting.ClubAccount",
),
),
], ],
), ),
migrations.AddField( migrations.AddField(
model_name='operation', model_name="operation",
name='label', name="label",
field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, related_name='operations', null=True, blank=True, verbose_name='label', to='accounting.Label'), field=models.ForeignKey(
on_delete=django.db.models.deletion.SET_NULL,
related_name="operations",
null=True,
blank=True,
verbose_name="label",
to="accounting.Label",
),
), ),
migrations.AlterUniqueTogether( migrations.AlterUniqueTogether(
name='label', name="label", unique_together=set([("name", "club_account")])
unique_together=set([('name', 'club_account')]),
), ),
] ]
...@@ -6,14 +6,14 @@ from django.db import migrations, models ...@@ -6,14 +6,14 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [("accounting", "0004_auto_20161005_1505")]
('accounting', '0004_auto_20161005_1505'),
]
operations = [ operations = [
migrations.AlterField( migrations.AlterField(
model_name='operation', model_name="operation",
name='remark', name="remark",
field=models.CharField(null=True, max_length=128, blank=True, verbose_name='comment'), field=models.CharField(
), null=True, max_length=128, blank=True, verbose_name="comment"
),
)
] ]
This diff is collapsed.
This diff is collapsed.
...@@ -28,46 +28,125 @@ from accounting.views import * ...@@ -28,46 +28,125 @@ from accounting.views import *
urlpatterns = [ urlpatterns = [
# Accounting types # Accounting types
url(r'^simple_type$', SimplifiedAccountingTypeListView.as_view(), name='simple_type_list'), url(
url(r'^simple_type/create$', SimplifiedAccountingTypeCreateView.as_view(), name='simple_type_new'), r"^simple_type$",
url(r'^simple_type/(?P<type_id>[0-9]+)/edit$', SimplifiedAccountingTypeEditView.as_view(), name='simple_type_edit'), SimplifiedAccountingTypeListView.as_view(),
name="simple_type_list",
),
url(
r"^simple_type/create$",
SimplifiedAccountingTypeCreateView.as_view(),
name="simple_type_new",
),
url(
r"^simple_type/(?P<type_id>[0-9]+)/edit$",
SimplifiedAccountingTypeEditView.as_view(),
name="simple_type_edit",
),
# Accounting types # Accounting types
url(r'^type$', AccountingTypeListView.as_view(), name='type_list'), url(r"^type$", AccountingTypeListView.as_view(), name="type_list"),
url(r'^type/create$', AccountingTypeCreateView.as_view(), name='type_new'), url(r"^type/create$", AccountingTypeCreateView.as_view(), name="type_new"),
url(r'^type/(?P<type_id>[0-9]+)/edit$', AccountingTypeEditView.as_view(), name='type_edit'), url(
r"^type/(?P<type_id>[0-9]+)/edit$",
AccountingTypeEditView.as_view(),
name="type_edit",
),
# Bank accounts # Bank accounts
url(r'^$', BankAccountListView.as_view(), name='bank_list'), url(r"^$", BankAccountListView.as_view(), name="bank_list"),
url(r'^bank/create$', BankAccountCreateView.as_view(), name='bank_new'), url(r"^bank/create$", BankAccountCreateView.as_view(), name="bank_new"),
url(r'^bank/(?P<b_account_id>[0-9]+)$', BankAccountDetailView.as_view(), name='bank_details'), url(
url(r'^bank/(?P<b_account_id>[0-9]+)/edit$', BankAccountEditView.as_view(), name='bank_edit'), r"^bank/(?P<b_account_id>[0-9]+)$",
url(r'^bank/(?P<b_account_id>[0-9]+)/delete$', BankAccountDeleteView.as_view(), name='bank_delete'), BankAccountDetailView.as_view(),
name="bank_details",
),
url(
r"^bank/(?P<b_account_id>[0-9]+)/edit$",
BankAccountEditView.as_view(),
name="bank_edit",
),
url(
r"^bank/(?P<b_account_id>[0-9]+)/delete$",
BankAccountDeleteView.as_view(),
name="bank_delete",
),
# Club accounts # Club accounts
url(r'^club/create$', ClubAccountCreateView.as_view(), name='club_new'), url(r"^club/create$", ClubAccountCreateView.as_view(), name="club_new"),
url(r'^club/(?P<c_account_id>[0-9]+)$', ClubAccountDetailView.as_view(), name='club_details'), url(
url(r'^club/(?P<c_account_id>[0-9]+)/edit$', ClubAccountEditView.as_view(), name='club_edit'), r"^club/(?P<c_account_id>[0-9]+)$",
url(r'^club/(?P<c_account_id>[0-9]+)/delete$', ClubAccountDeleteView.as_view(), name='club_delete'), ClubAccountDetailView.as_view(),
name="club_details",
),
url(
r"^club/(?P<c_account_id>[0-9]+)/edit$",
ClubAccountEditView.as_view(),
name="club_edit",
),
url(
r"^club/(?P<c_account_id>[0-9]+)/delete$",
ClubAccountDeleteView.as_view(),
name="club_delete",
),
# Journals # Journals
url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'), url(r"^journal/create$", JournalCreateView.as_view(), name="journal_new"),
url(r'^journal/(?P<j_id>[0-9]+)$', JournalDetailView.as_view(), name='journal_details'), url(
url(r'^journal/(?P<j_id>[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'), r"^journal/(?P<j_id>[0-9]+)$",
url(r'^journal/(?P<j_id>[0-9]+)/delete$', JournalDeleteView.as_view(), name='journal_delete'), JournalDetailView.as_view(),
url(r'^journal/(?P<j_id>[0-9]+)/statement/nature$', JournalNatureStatementView.as_view(), name='journal_nature_statement'), name="journal_details",
url(r'^journal/(?P<j_id>[0-9]+)/statement/person$', JournalPersonStatementView.as_view(), name='journal_person_statement'), ),
url(r'^journal/(?P<j_id>[0-9]+)/statement/accounting$', JournalAccountingStatementView.as_view(), name='journal_accounting_statement'), url(
r"^journal/(?P<j_id>[0-9]+)/edit$",
JournalEditView.as_view(),
name="journal_edit",
),
url(
r"^journal/(?P<j_id>[0-9]+)/delete$",
JournalDeleteView.as_view(),
name="journal_delete",
),
url(
r"^journal/(?P<j_id>[0-9]+)/statement/nature$",
JournalNatureStatementView.as_view(),
name="journal_nature_statement",
),
url(
r"^journal/(?P<j_id>[0-9]+)/statement/person$",
JournalPersonStatementView.as_view(),
name="journal_person_statement",
),
url(
r"^journal/(?P<j_id>[0-9]+)/statement/accounting$",
JournalAccountingStatementView.as_view(),
name="journal_accounting_statement",
),
# Operations # Operations
url(r'^operation/create/(?P<j_id>[0-9]+)$', OperationCreateView.as_view(), name='op_new'), url(
url(r'^operation/(?P<op_id>[0-9]+)$', OperationEditView.as_view(), name='op_edit'), r"^operation/create/(?P<j_id>[0-9]+)$",
url(r'^operation/(?P<op_id>[0-9]+)/pdf$', OperationPDFView.as_view(), name='op_pdf'), OperationCreateView.as_view(),
name="op_new",
),
url(r"^operation/(?P<op_id>[0-9]+)$", OperationEditView.as_view(), name="op_edit"),
url(
r"^operation/(?P<op_id>[0-9]+)/pdf$", OperationPDFView.as_view(), name="op_pdf"
),
# Companies # Companies
url(r'^company/list$', CompanyListView.as_view(), name='co_list'), url(r"^company/list$", CompanyListView.as_view(), name="co_list"),
url(r'^company/create$', CompanyCreateView.as_view(), name='co_new'), url(r"^company/create$", CompanyCreateView.as_view(), name="co_new"),
url(r'^company/(?P<co_id>[0-9]+)$', CompanyEditView.as_view(), name='co_edit'), url(r"^company/(?P<co_id>[0-9]+)$", CompanyEditView.as_view(), name="co_edit"),
# Labels # Labels
url(r'^label/new$', LabelCreateView.as_view(), name='label_new'), url(r"^label/new$", LabelCreateView.as_view(), name="label_new"),
url(r'^label/(?P<clubaccount_id>[0-9]+)$', LabelListView.as_view(), name='label_list'), url(
url(r'^label/(?P<label_id>[0-9]+)/edit$', LabelEditView.as_view(), name='label_edit'), r"^label/(?P<clubaccount_id>[0-9]+)$",
url(r'^label/(?P<label_id>[0-9]+)/delete$', LabelDeleteView.as_view(), name='label_delete'), LabelListView.as_view(),
name="label_list",
),
url(
r"^label/(?P<label_id>[0-9]+)/edit$", LabelEditView.as_view(), name="label_edit"
),
url(
r"^label/(?P<label_id>[0-9]+)/delete$",
LabelDeleteView.as_view(),
name="label_delete",
),
# User account # User account
url(r'^refound/account$', RefoundAccountView.as_view(), name='refound_account'), url(r"^refound/account$", RefoundAccountView.as_view(), name="refound_account"),
] ]
This diff is collapsed.
...@@ -21,4 +21,3 @@ ...@@ -21,4 +21,3 @@
# Place - Suite 330, Boston, MA 02111-1307, USA. # Place - Suite 330, Boston, MA 02111-1307, USA.
# #
# #
...@@ -29,25 +29,28 @@ from rest_framework import routers ...@@ -29,25 +29,28 @@ from rest_framework import routers
# Router config # Router config
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'counter', CounterViewSet, base_name='api_counter') router.register(r"counter", CounterViewSet, base_name="api_counter")
router.register(r'user', UserViewSet, base_name='api_user') router.register(r"user", UserViewSet, base_name="api_user")
router.register(r'club', ClubViewSet, base_name='api_club') router.register(r"club", ClubViewSet, base_name="api_club")
router.register(r'group', GroupViewSet, base_name='api_group') router.register(r"group", GroupViewSet, base_name="api_group")
# Launderette # Launderette
router.register(r'launderette/place', LaunderettePlaceViewSet, router.register(
base_name='api_launderette_place') r"launderette/place", LaunderettePlaceViewSet, base_name="api_launderette_place"
router.register(r'launderette/machine', LaunderetteMachineViewSet, )
base_name='api_launderette_machine') router.register(
router.register(r'launderette/token', LaunderetteTokenViewSet, r"launderette/machine",
base_name='api_launderette_token') LaunderetteMachineViewSet,
base_name="api_launderette_machine",
)
router.register(
r"launderette/token", LaunderetteTokenViewSet, base_name="api_launderette_token"
)
urlpatterns = [ urlpatterns = [
# API # API
url(r'^', include(router.urls)), url(r"^", include(router.urls)),
url(r'^login/', include('rest_framework.urls', namespace='rest_framework')), url(r"^login/", include("rest_framework.urls", namespace="rest_framework")),
url(r'^markdown$', RenderMarkdown, name='api_markdown'), url(r"^markdown$", RenderMarkdown, name="api_markdown"),
url(r'^mailings$', FetchMailingLists, name='mailings_fetch') url(r"^mailings$", FetchMailingLists, name="mailings_fetch"),
] ]
...@@ -30,19 +30,21 @@ from django.db.models.query import QuerySet ...@@ -30,19 +30,21 @@ from django.db.models.query import QuerySet
from core.views import can_view, can_edit 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:
if (test(o, user) is False): if test(o, user) is False:
return False return False
return True return True
else: else:
return test(obj, user) return test(obj, user)
class ManageModelMixin: class ManageModelMixin:
@detail_route() @detail_route()
def id(self, request, pk=None): def id(self, request, pk=None):
...@@ -53,19 +55,19 @@ class ManageModelMixin: ...@@ -53,19 +55,19 @@ class ManageModelMixin:
serializer = self.get_serializer(self.queryset) serializer = self.get_serializer(self.queryset)
return Response(serializer.data)