From c4a1f53e2c70ef6566a594229e8fb25930225366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Tue, 11 Apr 2023 11:07:05 +0200 Subject: [PATCH] run hooks --- ...0_alter_signee_address_country_and_more.py | 70 +++++++++++++------ ...alter_contract_cost_unit_other_and_more.py | 39 ++++++++--- .../0032_alter_signee_address_country.py | 18 +++-- .../0033_alter_contractfile_file.py | 15 ++-- ...4_alter_contract_agreement_url_and_more.py | 54 ++++++++++---- ..._alter_contract_valid_end_date_and_more.py | 25 ++++--- .../0036_alter_contract_tender_url.py | 15 ++-- contracts/models.py | 70 +++++++++++-------- contracts/templates/contracts/index.html | 2 +- contracts/views.py | 1 - registry/settings/base.py | 2 +- shared/middlewares.py | 11 ++- static_src/admin/signee_form.js | 4 +- 13 files changed, 214 insertions(+), 112 deletions(-) diff --git a/contracts/migrations/0030_alter_signee_address_country_and_more.py b/contracts/migrations/0030_alter_signee_address_country_and_more.py index bd6463e..9caa483 100644 --- a/contracts/migrations/0030_alter_signee_address_country_and_more.py +++ b/contracts/migrations/0030_alter_signee_address_country_and_more.py @@ -4,40 +4,70 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0029_alter_contracteesignature_role_and_more'), + ("contracts", "0029_alter_contracteesignature_role_and_more"), ] operations = [ migrations.AlterField( - model_name='signee', - name='address_country', - field=models.CharField(blank=True, default='Česká Republika', max_length=256, null=True, verbose_name='Země'), + model_name="signee", + name="address_country", + field=models.CharField( + blank=True, + default="Česká Republika", + max_length=256, + null=True, + verbose_name="Země", + ), ), migrations.AlterField( - model_name='signee', - name='address_district', - field=models.CharField(blank=True, max_length=256, null=True, verbose_name='Obec'), + model_name="signee", + name="address_district", + field=models.CharField( + blank=True, max_length=256, null=True, verbose_name="Obec" + ), ), migrations.AlterField( - model_name='signee', - name='address_street_with_number', - field=models.CharField(blank=True, help_text='Veřejné pouze, když typ není nastaven na fyzickou osobu.', max_length=256, null=True, verbose_name='Ulice, č.p.'), + model_name="signee", + name="address_street_with_number", + field=models.CharField( + blank=True, + help_text="Veřejné pouze, když typ není nastaven na fyzickou osobu.", + max_length=256, + null=True, + verbose_name="Ulice, č.p.", + ), ), migrations.AlterField( - model_name='signee', - name='address_zip', - field=models.CharField(blank=True, help_text='Veřejné pouze, když typ není nastaven na fyzickou osobu.', max_length=16, null=True, verbose_name='PSČ'), + model_name="signee", + name="address_zip", + field=models.CharField( + blank=True, + help_text="Veřejné pouze, když typ není nastaven na fyzickou osobu.", + max_length=16, + null=True, + verbose_name="PSČ", + ), ), migrations.AlterField( - model_name='signee', - name='date_of_birth', - field=models.DateField(blank=True, help_text='U fyzických osob musí být vyplněno.', null=True, verbose_name='Datum narození'), + model_name="signee", + name="date_of_birth", + field=models.DateField( + blank=True, + help_text="U fyzických osob musí být vyplněno.", + null=True, + verbose_name="Datum narození", + ), ), migrations.AlterField( - model_name='signee', - name='ico_number', - field=models.CharField(blank=True, help_text='U právnických a podnikajících fyzických osob musí být vyplněno. Vyplněním můžeš automaticky načíst data z ARES.', max_length=16, null=True, verbose_name='IČO'), + model_name="signee", + name="ico_number", + field=models.CharField( + blank=True, + help_text="U právnických a podnikajících fyzických osob musí být vyplněno. Vyplněním můžeš automaticky načíst data z ARES.", + max_length=16, + null=True, + verbose_name="IČO", + ), ), ] diff --git a/contracts/migrations/0031_alter_contract_cost_unit_other_and_more.py b/contracts/migrations/0031_alter_contract_cost_unit_other_and_more.py index 75b507b..9e4ac69 100644 --- a/contracts/migrations/0031_alter_contract_cost_unit_other_and_more.py +++ b/contracts/migrations/0031_alter_contract_cost_unit_other_and_more.py @@ -4,25 +4,42 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0030_alter_signee_address_country_and_more'), + ("contracts", "0030_alter_signee_address_country_and_more"), ] operations = [ migrations.AlterField( - model_name='contract', - name='cost_unit_other', - field=models.CharField(blank=True, help_text='Je nutno vyplnit v případě, že máš vybranou možnost "jiné" v jednotce nákladů.', max_length=128, null=True, verbose_name='Jednotka nákladů (jiné)'), + model_name="contract", + name="cost_unit_other", + field=models.CharField( + blank=True, + help_text='Je nutno vyplnit v případě, že máš vybranou možnost "jiné" v jednotce nákladů.', + max_length=128, + null=True, + verbose_name="Jednotka nákladů (jiné)", + ), ), migrations.AlterField( - model_name='contracteesignature', - name='role', - field=models.CharField(blank=True, help_text='Např. "nájemník"', max_length=256, null=True, verbose_name='Role'), + model_name="contracteesignature", + name="role", + field=models.CharField( + blank=True, + help_text='Např. "nájemník"', + max_length=256, + null=True, + verbose_name="Role", + ), ), migrations.AlterField( - model_name='signeesignature', - name='role', - field=models.CharField(blank=True, help_text='Např. "pronajímatel"', max_length=256, null=True, verbose_name='Role'), + model_name="signeesignature", + name="role", + field=models.CharField( + blank=True, + help_text='Např. "pronajímatel"', + max_length=256, + null=True, + verbose_name="Role", + ), ), ] diff --git a/contracts/migrations/0032_alter_signee_address_country.py b/contracts/migrations/0032_alter_signee_address_country.py index a4158bc..a02dcea 100644 --- a/contracts/migrations/0032_alter_signee_address_country.py +++ b/contracts/migrations/0032_alter_signee_address_country.py @@ -1,19 +1,25 @@ # Generated by Django 4.1.4 on 2023-04-03 21:35 -import contracts.models from django.db import migrations, models +import contracts.models + class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0031_alter_contract_cost_unit_other_and_more'), + ("contracts", "0031_alter_contract_cost_unit_other_and_more"), ] operations = [ migrations.AlterField( - model_name='signee', - name='address_country', - field=models.CharField(blank=True, default=contracts.models.get_default_country, max_length=256, null=True, verbose_name='Země'), + model_name="signee", + name="address_country", + field=models.CharField( + blank=True, + default=contracts.models.get_default_country, + max_length=256, + null=True, + verbose_name="Země", + ), ), ] diff --git a/contracts/migrations/0033_alter_contractfile_file.py b/contracts/migrations/0033_alter_contractfile_file.py index bf56c07..c64390c 100644 --- a/contracts/migrations/0033_alter_contractfile_file.py +++ b/contracts/migrations/0033_alter_contractfile_file.py @@ -1,19 +1,22 @@ # Generated by Django 4.1.4 on 2023-04-10 21:45 -import contracts.models from django.db import migrations, models +import contracts.models + class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0032_alter_signee_address_country'), + ("contracts", "0032_alter_signee_address_country"), ] operations = [ migrations.AlterField( - model_name='contractfile', - name='file', - field=models.FileField(upload_to=contracts.models.get_contract_file_loaction, verbose_name='Soubor'), + model_name="contractfile", + name="file", + field=models.FileField( + upload_to=contracts.models.get_contract_file_loaction, + verbose_name="Soubor", + ), ), ] diff --git a/contracts/migrations/0034_alter_contract_agreement_url_and_more.py b/contracts/migrations/0034_alter_contract_agreement_url_and_more.py index dd47ee5..ddbe98a 100644 --- a/contracts/migrations/0034_alter_contract_agreement_url_and_more.py +++ b/contracts/migrations/0034_alter_contract_agreement_url_and_more.py @@ -1,36 +1,60 @@ # Generated by Django 4.1.4 on 2023-04-10 22:26 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): - dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('contracts', '0033_alter_contractfile_file'), + ("contracts", "0033_alter_contractfile_file"), ] operations = [ migrations.AlterField( - model_name='contract', - name='agreement_url', - field=models.URLField(blank=True, help_text='Běžně odkaz na fórum. Využívá se např. u koaličních smluv.', max_length=256, null=True, verbose_name='Odkaz na schválení'), + model_name="contract", + name="agreement_url", + field=models.URLField( + blank=True, + help_text="Běžně odkaz na fórum. Využívá se např. u koaličních smluv.", + max_length=256, + null=True, + verbose_name="Odkaz na schválení", + ), ), migrations.AlterField( - model_name='contract', - name='cost_amount', - field=models.PositiveIntegerField(blank=True, help_text='Pokud se smlouvu nejsou spojené náklady, nevyplňuj vůbec.', null=True, verbose_name='Náklady (Kč)'), + model_name="contract", + name="cost_amount", + field=models.PositiveIntegerField( + blank=True, + help_text="Pokud se smlouvu nejsou spojené náklady, nevyplňuj vůbec.", + null=True, + verbose_name="Náklady (Kč)", + ), ), migrations.AlterField( - model_name='contract', - name='created_by', - field=models.ForeignKey(blank=True, help_text='Pokud vytváříš novou smlouvu, autorem budeš ty.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='uploaded_contracts', to=settings.AUTH_USER_MODEL, verbose_name='Vytvořena uživatelem'), + model_name="contract", + name="created_by", + field=models.ForeignKey( + blank=True, + help_text="Pokud vytváříš novou smlouvu, autorem budeš ty.", + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="uploaded_contracts", + to=settings.AUTH_USER_MODEL, + verbose_name="Vytvořena uživatelem", + ), ), migrations.AlterField( - model_name='contract', - name='tender_url', - field=models.URLField(blank=True, help_text='Běžně odkaz na fórum.', max_length=256, null=True, verbose_name='Odkaz na výběrové řízení'), + model_name="contract", + name="tender_url", + field=models.URLField( + blank=True, + help_text="Běžně odkaz na fórum.", + max_length=256, + null=True, + verbose_name="Odkaz na výběrové řízení", + ), ), ] diff --git a/contracts/migrations/0035_alter_contract_valid_end_date_and_more.py b/contracts/migrations/0035_alter_contract_valid_end_date_and_more.py index 4fb5f37..4b34c39 100644 --- a/contracts/migrations/0035_alter_contract_valid_end_date_and_more.py +++ b/contracts/migrations/0035_alter_contract_valid_end_date_and_more.py @@ -4,20 +4,29 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0034_alter_contract_agreement_url_and_more'), + ("contracts", "0034_alter_contract_agreement_url_and_more"), ] operations = [ migrations.AlterField( - model_name='contract', - name='valid_end_date', - field=models.DateField(blank=True, help_text='<strong>Pokud není konec účinnosti zadán, smlouva je evidována jako na dobu neurčitou.</strong>', null=True, verbose_name='Konec účinnosti'), + model_name="contract", + name="valid_end_date", + field=models.DateField( + blank=True, + help_text="<strong>Pokud není konec účinnosti zadán, smlouva je evidována jako na dobu neurčitou.</strong>", + null=True, + verbose_name="Konec účinnosti", + ), ), migrations.AlterField( - model_name='contract', - name='valid_start_date', - field=models.DateField(blank=True, help_text='<strong>Pokud není začátek účinnosti zadán, vypočítá se automaticky podle posledního data podpisu.</strong>', null=True, verbose_name='Začátek účinnosti'), + model_name="contract", + name="valid_start_date", + field=models.DateField( + blank=True, + help_text="<strong>Pokud není začátek účinnosti zadán, vypočítá se automaticky podle posledního data podpisu.</strong>", + null=True, + verbose_name="Začátek účinnosti", + ), ), ] diff --git a/contracts/migrations/0036_alter_contract_tender_url.py b/contracts/migrations/0036_alter_contract_tender_url.py index 7faca40..25a7b66 100644 --- a/contracts/migrations/0036_alter_contract_tender_url.py +++ b/contracts/migrations/0036_alter_contract_tender_url.py @@ -4,15 +4,20 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0035_alter_contract_valid_end_date_and_more'), + ("contracts", "0035_alter_contract_valid_end_date_and_more"), ] operations = [ migrations.AlterField( - model_name='contract', - name='tender_url', - field=models.URLField(blank=True, help_text='Běžně odkaz na <a href="https://forum.pirati.cz/viewforum.php?f=572">fórum</a>.', max_length=256, null=True, verbose_name='Odkaz na výběrové řízení'), + model_name="contract", + name="tender_url", + field=models.URLField( + blank=True, + help_text='Běžně odkaz na <a href="https://forum.pirati.cz/viewforum.php?f=572">fórum</a>.', + max_length=256, + null=True, + verbose_name="Odkaz na výběrové řízení", + ), ), ] diff --git a/contracts/models.py b/contracts/models.py index 98c1c0d..e876065 100644 --- a/contracts/models.py +++ b/contracts/models.py @@ -1,6 +1,6 @@ import datetime -import os import mimetypes +import os import typing from django.conf import settings @@ -102,7 +102,13 @@ def get_default_country(): return settings.DEFAULT_COUNTRY -class Signee(CreatedByMixin, OwnPermissionsMixin, SignatureCountMixin, InlineNameMixin, models.Model): +class Signee( + CreatedByMixin, + OwnPermissionsMixin, + SignatureCountMixin, + InlineNameMixin, + models.Model, +): name = models.CharField( max_length=256, verbose_name="Jméno", @@ -168,7 +174,7 @@ class Signee(CreatedByMixin, OwnPermissionsMixin, SignatureCountMixin, InlineNam blank=True, null=True, verbose_name="Datum narození", - help_text="U fyzických osob musí být vyplněno." + help_text="U fyzických osob musí být vyplněno.", ) # WARNING: Legal entity status dependent! department = models.CharField( @@ -198,7 +204,7 @@ class Signee(CreatedByMixin, OwnPermissionsMixin, SignatureCountMixin, InlineNam "address_country", ): if getattr(self, field): - return True + return True return False @@ -207,22 +213,22 @@ class Signee(CreatedByMixin, OwnPermissionsMixin, SignatureCountMixin, InlineNam self.entity_type == self.EntityTypes.NATURAL_PERSON and not self.date_of_birth ): - raise ValidationError({ - "date_of_birth": "U fyzických osob musí být definováno." - }) + raise ValidationError( + {"date_of_birth": "U fyzických osob musí být definováno."} + ) if ( - self.entity_type in ( - self.EntityTypes.LEGAL_ENTITY, - self.EntityTypes.BUSINESS_NATURAL_PERSON - ) + self.entity_type + in (self.EntityTypes.LEGAL_ENTITY, self.EntityTypes.BUSINESS_NATURAL_PERSON) and not self.ico_number ): - raise ValidationError({ - "ico_number": "U právnických a podnikajících fyzických osob musí být definováno." - }) + raise ValidationError( + { + "ico_number": "U právnických a podnikajících fyzických osob musí být definováno." + } + ) - if (self.entity_type != self.EntityTypes.OTHER): + if self.entity_type != self.EntityTypes.OTHER: for field in ( "address_street_with_number", "address_district", @@ -230,9 +236,9 @@ class Signee(CreatedByMixin, OwnPermissionsMixin, SignatureCountMixin, InlineNam "address_country", ): if not getattr(self, field): - raise ValidationError({ - field: "Pokud není vybrán typ \"Jiné\", musí být definováno." - }) + raise ValidationError( + {field: 'Pokud není vybrán typ "Jiné", musí být definováno.'} + ) return super().clean() @@ -260,7 +266,11 @@ class Signee(CreatedByMixin, OwnPermissionsMixin, SignatureCountMixin, InlineNam class Contractee( - CreatedByMixin, OwnPermissionsMixin, SignatureCountMixin, InlineNameMixin, models.Model + CreatedByMixin, + OwnPermissionsMixin, + SignatureCountMixin, + InlineNameMixin, + models.Model, ): name = models.CharField( max_length=256, @@ -481,7 +491,7 @@ class Contract(NameStrMixin, models.Model): help_text=mark_safe( "<strong>Pokud není začátek účinnosti zadán, vypočítá se automaticky " "podle posledního data podpisu.</strong>" - ) + ), ) valid_end_date = models.DateField( blank=True, @@ -490,7 +500,7 @@ class Contract(NameStrMixin, models.Model): help_text=mark_safe( "<strong>Pokud není konec účinnosti zadán, smlouva je evidována jako " "na dobu neurčitou.</strong>" - ) + ), ) class LegalStates(models.TextChoices): @@ -541,8 +551,8 @@ class Contract(NameStrMixin, models.Model): null=True, verbose_name="Odkaz na výběrové řízení", help_text=mark_safe( - "Běžně odkaz na <a href=\"https://forum.pirati.cz/viewforum.php?f=572\">fórum</a>." - ) + 'Běžně odkaz na <a href="https://forum.pirati.cz/viewforum.php?f=572">fórum</a>.' + ), ) agreement_url = models.URLField( @@ -550,7 +560,7 @@ class Contract(NameStrMixin, models.Model): blank=True, null=True, verbose_name="Odkaz na schválení", - help_text="Běžně odkaz na fórum. Využívá se např. u koaličních smluv." + help_text="Běžně odkaz na fórum. Využívá se např. u koaličních smluv.", ) # WARNING: Dependent on the type! issues = models.ManyToManyField( @@ -572,7 +582,7 @@ class Contract(NameStrMixin, models.Model): blank=True, null=True, verbose_name="Náklady (Kč)", - help_text="Pokud se smlouvu nejsou spojené náklady, nevyplňuj vůbec." + help_text="Pokud se smlouvu nejsou spojené náklady, nevyplňuj vůbec.", ) cost_unit = models.CharField( @@ -586,7 +596,7 @@ class Contract(NameStrMixin, models.Model): cost_unit_other = models.CharField( max_length=128, verbose_name="Jednotka nákladů (jiné)", - help_text="Je nutno vyplnit v případě, že máš vybranou možnost \"jiné\" v jednotce nákladů.", + help_text='Je nutno vyplnit v případě, že máš vybranou možnost "jiné" v jednotce nákladů.', blank=True, null=True, ) @@ -716,13 +726,13 @@ class Contract(NameStrMixin, models.Model): if self.cost_unit == self.CostUnits.OTHER and not self.cost_unit_other: raise ValidationError( { - "cost_unit_other": "Musí být definováno, pokud je vybrána jednotka nákladů \"jiné\"." + "cost_unit_other": 'Musí být definováno, pokud je vybrána jednotka nákladů "jiné".' } ) elif self.cost_unit != self.CostUnits.OTHER and self.cost_unit_other: raise ValidationError( { - "cost_unit_other": "Nemůže být definováno, pokud není vybrána jednotka nákladů \"jiné\"." + "cost_unit_other": 'Nemůže být definováno, pokud není vybrána jednotka nákladů "jiné".' } ) @@ -843,7 +853,7 @@ class ContracteeSignature(models.Model): blank=True, null=True, verbose_name="Role", - help_text="Např. \"nájemník\"", + help_text='Např. "nájemník"', ) def __str__(self) -> str: @@ -880,7 +890,7 @@ class SigneeSignature(models.Model): blank=True, null=True, verbose_name="Role", - help_text="Např. \"pronajímatel\"", + help_text='Např. "pronajímatel"', ) def __str__(self) -> str: diff --git a/contracts/templates/contracts/index.html b/contracts/templates/contracts/index.html index 772c75b..a28a22f 100644 --- a/contracts/templates/contracts/index.html +++ b/contracts/templates/contracts/index.html @@ -15,7 +15,7 @@ </div> <hr class="mb-6 md:mb-10"> - + <div class="flex gap-2 mb-6 text-lg flex-col md:mb-9 md:gap-6 md:flex-row"> <a class="flex gap-2 items-baseline hover:no-underline" diff --git a/contracts/views.py b/contracts/views.py index 3e71118..27e352a 100644 --- a/contracts/views.py +++ b/contracts/views.py @@ -375,7 +375,6 @@ def get_ares_info(request, ico: int): for result_count in tree.iter("are:Pocet_zaznamu"): if result_count.text == "0": raise HTTPExceptions.NOT_FOUND - return HttpResponse( content=ares_info.content, diff --git a/registry/settings/base.py b/registry/settings/base.py index 380f476..f86b3d6 100644 --- a/registry/settings/base.py +++ b/registry/settings/base.py @@ -77,7 +77,7 @@ MIDDLEWARE = [ "django.middleware.clickjacking.XFrameOptionsMiddleware", "django_http_exceptions.middleware.ExceptionHandlerMiddleware", "django_http_exceptions.middleware.ThreadLocalRequestMiddleware", - "shared.middlewares.ClamAVMiddleware" + "shared.middlewares.ClamAVMiddleware", ] ROOT_URLCONF = "registry.urls" diff --git a/shared/middlewares.py b/shared/middlewares.py index e2ddfea..de3ed27 100644 --- a/shared/middlewares.py +++ b/shared/middlewares.py @@ -1,8 +1,9 @@ -import clamd - from io import BytesIO -from django.http import HttpResponseForbidden + +import clamd from django.conf import settings +from django.http import HttpResponseForbidden + class ClamAVMiddleware: def __init__(self, get_response): @@ -14,9 +15,7 @@ class ClamAVMiddleware: # the view (and later middleware) are called. cd = clamd.ClamdNetworkSocket( - host=settings.CLAMD_TCP_ADDR, - port=settings.CLAMD_TCP_SOCKET, - timeout=120 + host=settings.CLAMD_TCP_ADDR, port=settings.CLAMD_TCP_SOCKET, timeout=120 ) if request.method == "POST" and len(request.FILES) > 0: diff --git a/static_src/admin/signee_form.js b/static_src/admin/signee_form.js index 2dc4acc..473b4c0 100644 --- a/static_src/admin/signee_form.js +++ b/static_src/admin/signee_form.js @@ -11,7 +11,7 @@ const fieldDepartmentValues = new Set([ $(window).ready( () => { let selectedValue = $("#id_entity_type").find(":selected").val(); - + let isNaturalPerson = (selectedValue === "natural_person"); let isOther = (selectedValue === "other"); let isEmpty = (selectedValue === ""); @@ -51,7 +51,7 @@ $(window).ready( "change", event => { selectedValue = $(event.target).val(); - + isEmpty = (selectedValue === ""); isOther = (selectedValue === "other"); isNaturalPerson = (selectedValue === "natural_person"); -- GitLab