diff --git a/contracts/admin.py b/contracts/admin.py index 5ca0426dda33ecdbf59fef291d5abc8b325cad45..d4edd51491c0cd63e81c5c875cf6ddce09cbb3f4 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 8613bcd4977df848f8a38a947ce112acc9b30720..ca0430daed2baf201a4a8c33fe332a3f8a0be5eb 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 b948a41a0d7c347cecf68ed9c298846b34804115..22c943e1cbcd26f710e483eed363bf2b94612cd3 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 d3bfc0e3025e8f0147743f1ca35f88aa773b9dd8..5c873a147af81215877512471b9f103636bd5ddb 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 3a3dd3f491bbddf20d9a72d0db6ffdc9c5b6ea25..8e749d36b9bb9fca1b0a670bbdd012795f9f02bb 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 9de3e7b5a20a6f3923a4b40fd6641220ed92ac75..b6c8e13533a156b0a225a152a3661f56790a9536 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 c2d25c498b22b8f20bf58c3b14bf73e266ea0381..b825c68277fca3ce951519f2b3b23520c7b378e0 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 ec4968662e511e774514406ca8a6460e94679352..8500ae17c9c4b56aabadcad3dc7090faef9063a9 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 c4fd8548dc78bf6fafb4ae927ceca8dbe8523fe9..367b938e2f412236db6b8a469db98ff3b03b5471 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 4e95760325d08d6b5280e4c09e690c98a3da7795..1c1ca21b41261f43ddabe2ae3680cc2d1d70ae47 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 6a4adba7570de32d35fdc4c62c00e680dc9a4fd8..987d43eb061b5f192ab6a92ef921c087f6216838 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 2b08c732c7ee4bf0d31cc3d65b8c7b20d8d09a6c..791381c9eab1ed190d36b85db3a5c5b4ba8a4c22 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(""); } );