From 26c239830640d52adcff574cf87a59d43bbbc9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Fri, 31 Mar 2023 10:45:40 +0200 Subject: [PATCH] run hooks --- contracts/admin.py | 6 +-- ...other_alter_contract_cost_unit_and_more.py | 48 ++++++++++++++----- .../0023_alter_contractfile_is_public.py | 12 +++-- .../0024_alter_contract_is_approved.py | 13 +++-- ...t_amount_other_contract_cost_unit_other.py | 9 ++-- .../0026_alter_contract_is_public_and_more.py | 19 ++++---- .../0027_alter_contractintent_options.py | 10 ++-- ...ractee_role_remove_signee_role_and_more.py | 35 +++++++++----- ...alter_contracteesignature_role_and_more.py | 27 +++++++---- contracts/models.py | 28 +++-------- contracts/views.py | 26 ++++------ static_src/admin/contract_form.js | 2 +- 12 files changed, 133 insertions(+), 102 deletions(-) diff --git a/contracts/admin.py b/contracts/admin.py index 5ca0426..d4edd51 100644 --- a/contracts/admin.py +++ b/contracts/admin.py @@ -304,14 +304,12 @@ class ContractAdmin( if not request.user.has_perm("contracts.view_confidential"): # Allow user to view their own objects, even if not public queryset = queryset.filter( - models.Q(is_public=True) - | models.Q(created_by=request.user) + models.Q(is_public=True) | models.Q(created_by=request.user) ) if not request.user.has_perm("contracts.approve"): queryset = queryset.filter( - models.Q(is_approved=True) - | models.Q(created_by=request.user) + models.Q(is_approved=True) | models.Q(created_by=request.user) ) return queryset diff --git a/contracts/migrations/0022_contract_cost_amount_other_alter_contract_cost_unit_and_more.py b/contracts/migrations/0022_contract_cost_amount_other_alter_contract_cost_unit_and_more.py index 8613bcd..ca0430d 100644 --- a/contracts/migrations/0022_contract_cost_amount_other_alter_contract_cost_unit_and_more.py +++ b/contracts/migrations/0022_contract_cost_amount_other_alter_contract_cost_unit_and_more.py @@ -4,25 +4,51 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0021_contract_updated_on_alter_contractee_address_country_and_more'), + ( + "contracts", + "0021_contract_updated_on_alter_contractee_address_country_and_more", + ), ] operations = [ migrations.AddField( - model_name='contract', - name='cost_amount_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_amount_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='contract', - name='cost_unit', - field=models.CharField(blank=True, choices=[('hour', 'Hodina'), ('month', 'Měsíc'), ('year', 'Rok'), ('total', 'Celkem'), ('other', 'Jiné')], max_length=5, null=True, verbose_name='Jednotka nákladů'), + model_name="contract", + name="cost_unit", + field=models.CharField( + blank=True, + choices=[ + ("hour", "Hodina"), + ("month", "Měsíc"), + ("year", "Rok"), + ("total", "Celkem"), + ("other", "Jiné"), + ], + max_length=5, + null=True, + verbose_name="Jednotka nákladů", + ), ), migrations.AlterField( - model_name='contract', - name='publishing_rejection_comment', - field=models.TextField(blank=True, help_text='Obsah není veřejně přístupný.', max_length=65536, null=True, verbose_name='Důvod nezveřejnění'), + model_name="contract", + name="publishing_rejection_comment", + field=models.TextField( + blank=True, + help_text="Obsah není veřejně přístupný.", + max_length=65536, + null=True, + verbose_name="Důvod nezveřejnění", + ), ), ] diff --git a/contracts/migrations/0023_alter_contractfile_is_public.py b/contracts/migrations/0023_alter_contractfile_is_public.py index b948a41..22c943e 100644 --- a/contracts/migrations/0023_alter_contractfile_is_public.py +++ b/contracts/migrations/0023_alter_contractfile_is_public.py @@ -4,15 +4,17 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0022_contract_cost_amount_other_alter_contract_cost_unit_and_more'), + ( + "contracts", + "0022_contract_cost_amount_other_alter_contract_cost_unit_and_more", + ), ] operations = [ migrations.AlterField( - model_name='contractfile', - name='is_public', - field=models.BooleanField(default=True, verbose_name='Veřejně dostupný'), + model_name="contractfile", + name="is_public", + field=models.BooleanField(default=True, verbose_name="Veřejně dostupný"), ), ] diff --git a/contracts/migrations/0024_alter_contract_is_approved.py b/contracts/migrations/0024_alter_contract_is_approved.py index d3bfc0e..5c873a1 100644 --- a/contracts/migrations/0024_alter_contract_is_approved.py +++ b/contracts/migrations/0024_alter_contract_is_approved.py @@ -4,15 +4,18 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0023_alter_contractfile_is_public'), + ("contracts", "0023_alter_contractfile_is_public"), ] operations = [ migrations.AlterField( - model_name='contract', - name='is_approved', - field=models.BooleanField(default=False, help_text='Mohou měnit jen schvalovatelé. Pokud je smlouva veřejná, schválením se vypustí ven.', verbose_name='Je schválená'), + model_name="contract", + name="is_approved", + field=models.BooleanField( + default=False, + help_text="Mohou měnit jen schvalovatelé. Pokud je smlouva veřejná, schválením se vypustí ven.", + verbose_name="Je schválená", + ), ), ] diff --git a/contracts/migrations/0025_rename_cost_amount_other_contract_cost_unit_other.py b/contracts/migrations/0025_rename_cost_amount_other_contract_cost_unit_other.py index 3a3dd3f..8e749d3 100644 --- a/contracts/migrations/0025_rename_cost_amount_other_contract_cost_unit_other.py +++ b/contracts/migrations/0025_rename_cost_amount_other_contract_cost_unit_other.py @@ -4,15 +4,14 @@ from django.db import migrations class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0024_alter_contract_is_approved'), + ("contracts", "0024_alter_contract_is_approved"), ] operations = [ migrations.RenameField( - model_name='contract', - old_name='cost_amount_other', - new_name='cost_unit_other', + model_name="contract", + old_name="cost_amount_other", + new_name="cost_unit_other", ), ] diff --git a/contracts/migrations/0026_alter_contract_is_public_and_more.py b/contracts/migrations/0026_alter_contract_is_public_and_more.py index 9de3e7b..b6c8e13 100644 --- a/contracts/migrations/0026_alter_contract_is_public_and_more.py +++ b/contracts/migrations/0026_alter_contract_is_public_and_more.py @@ -4,20 +4,23 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0025_rename_cost_amount_other_contract_cost_unit_other'), + ("contracts", "0025_rename_cost_amount_other_contract_cost_unit_other"), ] operations = [ migrations.AlterField( - model_name='contract', - name='is_public', - field=models.BooleanField(default=True, help_text='Neveřejné smlouvy nejsou vidět bez přihlášení jako min. tajný čtenář.', verbose_name='Je veřejná'), + model_name="contract", + name="is_public", + field=models.BooleanField( + default=True, + help_text="Neveřejné smlouvy nejsou vidět bez přihlášení jako min. tajný čtenář.", + verbose_name="Je veřejná", + ), ), migrations.AlterField( - model_name='contractfile', - name='is_public', - field=models.BooleanField(verbose_name='Veřejně dostupný'), + model_name="contractfile", + name="is_public", + field=models.BooleanField(verbose_name="Veřejně dostupný"), ), ] diff --git a/contracts/migrations/0027_alter_contractintent_options.py b/contracts/migrations/0027_alter_contractintent_options.py index c2d25c4..b825c68 100644 --- a/contracts/migrations/0027_alter_contractintent_options.py +++ b/contracts/migrations/0027_alter_contractintent_options.py @@ -4,14 +4,16 @@ from django.db import migrations class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0026_alter_contract_is_public_and_more'), + ("contracts", "0026_alter_contract_is_public_and_more"), ] operations = [ migrations.AlterModelOptions( - name='contractintent', - options={'verbose_name': 'Záměr v Piroplácení', 'verbose_name_plural': 'Záměry v Piroplácení'}, + name="contractintent", + options={ + "verbose_name": "Záměr v Piroplácení", + "verbose_name_plural": "Záměry v Piroplácení", + }, ), ] diff --git a/contracts/migrations/0028_remove_contractee_role_remove_signee_role_and_more.py b/contracts/migrations/0028_remove_contractee_role_remove_signee_role_and_more.py index ec49686..8500ae1 100644 --- a/contracts/migrations/0028_remove_contractee_role_remove_signee_role_and_more.py +++ b/contracts/migrations/0028_remove_contractee_role_remove_signee_role_and_more.py @@ -4,28 +4,39 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0027_alter_contractintent_options'), + ("contracts", "0027_alter_contractintent_options"), ] operations = [ migrations.RemoveField( - model_name='contractee', - name='role', + model_name="contractee", + name="role", ), migrations.RemoveField( - model_name='signee', - name='role', + model_name="signee", + name="role", ), migrations.AddField( - model_name='contracteesignature', - name='role', - field=models.CharField(blank=True, help_text='Např. nájemce', max_length=256, null=True, verbose_name='Role'), + model_name="contracteesignature", + name="role", + field=models.CharField( + blank=True, + help_text="Např. nájemce", + max_length=256, + null=True, + verbose_name="Role", + ), ), migrations.AddField( - model_name='signeesignature', - name='role', - field=models.CharField(blank=True, help_text='Např. nájemce', max_length=256, null=True, verbose_name='Role'), + model_name="signeesignature", + name="role", + field=models.CharField( + blank=True, + help_text="Např. nájemce", + max_length=256, + null=True, + verbose_name="Role", + ), ), ] diff --git a/contracts/migrations/0029_alter_contracteesignature_role_and_more.py b/contracts/migrations/0029_alter_contracteesignature_role_and_more.py index c4fd854..367b938 100644 --- a/contracts/migrations/0029_alter_contracteesignature_role_and_more.py +++ b/contracts/migrations/0029_alter_contracteesignature_role_and_more.py @@ -4,20 +4,31 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0028_remove_contractee_role_remove_signee_role_and_more'), + ("contracts", "0028_remove_contractee_role_remove_signee_role_and_more"), ] operations = [ 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/models.py b/contracts/models.py index 4e95760..1c1ca21 100644 --- a/contracts/models.py +++ b/contracts/models.py @@ -581,33 +581,22 @@ class Contract(NameStrMixin, models.Model): self.save() def clean(self): - if ( - not self.is_public - and not self.publishing_rejection_comment - ): + if not self.is_public and not self.publishing_rejection_comment: raise ValidationError( { "publishing_rejection_comment": "Pokud smlouva není veřejná, toto pole musí být vyplněné." } ) - elif ( - self.is_public - and self.publishing_rejection_comment - ): + elif self.is_public and self.publishing_rejection_comment: raise ValidationError( { "publishing_rejection_comment": "Nemůže být definováno, pokud je smlouva veřejná." } ) - if ( - self.cost_amount is None # 0 is falsy, but a value - and self.cost_unit - ): + if self.cost_amount is None and self.cost_unit: # 0 is falsy, but a value raise ValidationError( - { - "cost_unit": "Nemůže být definováno, pokud nejsou zadány náklady." - } + {"cost_unit": "Nemůže být definováno, pokud nejsou zadány náklady."} ) if ( @@ -615,15 +604,10 @@ class Contract(NameStrMixin, models.Model): and not self.cost_unit ): raise ValidationError( - { - "cost_amount": "Nemůže být definováno bez jednoty nákladů." - } + {"cost_amount": "Nemůže být definováno bez jednoty nákladů."} ) - if ( - self.cost_unit == self.CostUnits.OTHER[1] - and self.cost_unit_other is None - ): + if self.cost_unit == self.CostUnits.OTHER[1] and self.cost_unit_other is None: raise ValidationError( { "cost_unit_other": "Musí být definováno, pokud je vybrána jednotka nákladů 'jiné'." diff --git a/contracts/views.py b/contracts/views.py index 6a4adba..987d43e 100644 --- a/contracts/views.py +++ b/contracts/views.py @@ -92,8 +92,8 @@ def view_contract(request, id: int): if not request.user.has_perm("contracts.view_confidential"): filter = filter & ( - models.Q(is_public=True) | - ( + models.Q(is_public=True) + | ( models.Q(created_by=request.user) if not request.user.is_anonymous else True @@ -101,11 +101,8 @@ def view_contract(request, id: int): ) contract = get_object_or_404( - ( - get_objects_for_user(request.user, "contracts.view_contract") - .filter(filter) - ), - id=id + (get_objects_for_user(request.user, "contracts.view_contract").filter(filter)), + id=id, ) return render( @@ -125,8 +122,7 @@ def view_contract(request, id: int): def view_contract_filing_area(request, id: int): filing_area = get_object_or_404( - get_objects_for_user(request.user, "contracts.view_contractfilingarea"), - id=id + get_objects_for_user(request.user, "contracts.view_contractfilingarea"), id=id ) contracts_page, contracts_paginator = get_paginated_contracts( @@ -152,8 +148,7 @@ def view_contract_filing_area(request, id: int): def view_contract_issue(request, id: int): issue = get_object_or_404( - get_objects_for_user(request.user, "contracts.view_contractissue"), - id=id + get_objects_for_user(request.user, "contracts.view_contractissue"), id=id ) contracts_page, contracts_paginator = get_paginated_contracts( @@ -176,8 +171,7 @@ def view_contract_issue(request, id: int): def view_contract_type(request, id: int): type_ = get_object_or_404( - get_objects_for_user(request.user, "contracts.view_contracttype"), - id=id + get_objects_for_user(request.user, "contracts.view_contracttype"), id=id ) contracts_page, contracts_paginator = get_paginated_contracts( @@ -200,8 +194,7 @@ def view_contract_type(request, id: int): def view_contractee(request, id: int): contractee = get_object_or_404( - get_objects_for_user(request.user, "contracts.view_contractee"), - id=id + get_objects_for_user(request.user, "contracts.view_contractee"), id=id ) contracts_page, contracts_paginator = get_paginated_contracts( @@ -224,8 +217,7 @@ def view_contractee(request, id: int): def view_signee(request, id: int): signee = get_object_or_404( - get_objects_for_user(request.user, "contracts.view_signee"), - id=id + get_objects_for_user(request.user, "contracts.view_signee"), id=id ) contracts_page, contracts_paginator = get_paginated_contracts( diff --git a/static_src/admin/contract_form.js b/static_src/admin/contract_form.js index 2b08c73..791381c 100644 --- a/static_src/admin/contract_form.js +++ b/static_src/admin/contract_form.js @@ -57,7 +57,7 @@ $(window).ready( "block" : "none" ) ); - + if (!otherIsSelected) $(".field-cost_unit_other").val(""); } ); -- GitLab