diff --git a/creme/activities/forms/mass_import.py b/creme/activities/forms/mass_import.py index e514cdbad0..c11e83fb03 100644 --- a/creme/activities/forms/mass_import.py +++ b/creme/activities/forms/mass_import.py @@ -602,12 +602,13 @@ class ActivityMassImportForm(ImportForm4CremeEntity): class Meta: exclude = ('type', 'sub_type', 'busy') - blocks = ImportForm4CremeEntity.blocks.new( - ( - 'participants', _('Participants & subjects'), - ['my_participation', 'participating_users', 'participants', 'subjects'] - ), - ) + blocks = ImportForm4CremeEntity.blocks.new({ + 'id': 'participants', + 'label': _('Participants & subjects'), + 'fields': [ + 'my_participation', 'participating_users', 'participants', 'subjects', + ], + }) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/billing/forms/line.py b/creme/billing/forms/line.py index dd49b83f2c..555f83f6a5 100644 --- a/creme/billing/forms/line.py +++ b/creme/billing/forms/line.py @@ -88,12 +88,15 @@ class ProductLineMultipleAddForm(_LineMultipleAddForm): items = MultiCreatorEntityField(label=_('Products'), model=products.get_product_model()) blocks = core_forms.FieldBlockManager( - ('general', _('Products choice'), ['items']), - ( - 'additional', - _('Optional global information applied to your selected products'), - ['quantity', 'vat', 'discount_value'], - ) + { + 'id': 'general', + 'label': _('Products choice'), + 'fields': ['items'], + }, { + 'id': 'additional', + 'label': _('Optional global information applied to your selected products'), + 'fields': ['quantity', 'vat', 'discount_value'], + }, ) def _get_line_class(self): @@ -104,12 +107,15 @@ class ServiceLineMultipleAddForm(_LineMultipleAddForm): items = MultiCreatorEntityField(label=_('Services'), model=products.get_service_model()) blocks = core_forms.FieldBlockManager( - ('general', _('Services choice'), ['items']), - ( - 'additional', - _('Optional global information applied to your selected services'), - ['quantity', 'vat', 'discount_value'], - ) + { + 'id': 'general', + 'label': _('Services choice'), + 'fields': ['items'], + }, { + 'id': 'additional', + 'label': _('Optional global information applied to your selected services'), + 'fields': ['quantity', 'vat', 'discount_value'], + }, ) def _get_line_class(self): diff --git a/creme/commercial/forms/strategy.py b/creme/commercial/forms/strategy.py index 9872b11621..3d8ddd99e9 100644 --- a/creme/commercial/forms/strategy.py +++ b/creme/commercial/forms/strategy.py @@ -90,9 +90,11 @@ class _SegmentForm(_AuxForm): 'duplicated_property': _('A property with the name «%(name)s» already exists'), } - blocks = FieldBlockManager( - ('general', _('General information'), ['name', 'product', 'place', 'price', 'promotion']), - ) + blocks = FieldBlockManager({ + 'id': 'general', + 'label': _('General information'), + 'fields': ['name', 'product', 'place', 'price', 'promotion'], + }) class Meta: model = MarketSegmentDescription diff --git a/creme/creme_config/forms/bricks.py b/creme/creme_config/forms/bricks.py index 0d8e9270e1..1501c86d18 100644 --- a/creme/creme_config/forms/bricks.py +++ b/creme/creme_config/forms/bricks.py @@ -226,9 +226,11 @@ class BrickDetailviewLocationsAddForm(_BrickDetailviewLocationsForm): ) # TODO: manage Meta.fields in '*' - blocks = base.FieldBlockManager( - ('general', _('Configuration'), ('role', 'hat', 'top', 'left', 'right', 'bottom')), - ) + blocks = base.FieldBlockManager({ + 'id': 'general', + 'label': _('Configuration'), + 'fields': ('role', 'hat', 'top', 'left', 'right', 'bottom'), + }) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -255,7 +257,7 @@ def __init__(self, *args, **kwargs): hat_f.initial = hat_f.choices[0][0] def save(self, *args, **kwargs): - self.role = role = self.cleaned_data['role'] + self.role = role = self.cleaned_data['role'] self.superuser = (role is None) super().save(*args, **kwargs) @@ -263,7 +265,7 @@ def save(self, *args, **kwargs): class BrickDetailviewLocationsEditForm(_BrickDetailviewLocationsForm): def __init__(self, role, superuser, *args, **kwargs): super().__init__(*args, **kwargs) - self.role = role + self.role = role self.superuser = superuser self.locations = locations = BrickDetailviewLocation.objects.filter( @@ -328,7 +330,7 @@ class BrickHomeLocationsEditionForm(_BrickLocationsForm): def __init__(self, role, superuser, *args, **kwargs): super().__init__(*args, **kwargs) - self.role = role + self.role = role self.superuser = superuser self.locations = locations = BrickHomeLocation.objects.filter( @@ -529,9 +531,9 @@ def clean(self, *args, **kwargs): class CustomBrickConfigItemEditForm(_CustomBrickConfigItemBaseForm): cells = EntityCellsField(label=_('Lines')) - blocks = base.CremeModelForm.blocks.new( - ('cells', 'Columns', ['cells']), - ) + blocks = base.CremeModelForm.blocks.new({ + 'id': 'cells', 'label': 'Columns', 'fields': ['cells'], + }) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/creme_config/forms/custom_form.py b/creme/creme_config/forms/custom_form.py index e2215d81cf..834205747a 100644 --- a/creme/creme_config/forms/custom_form.py +++ b/creme/creme_config/forms/custom_form.py @@ -191,8 +191,15 @@ class CustomFormGroupForm(CremeModelForm): cells = CustomFormCellsField(label=_('Fields')) blocks = FieldBlockManager( - ('name', 'Name', ('name',)), - ('cells', 'Fields', ('cells',)), + { + 'id': 'name', + 'label': 'Name', + 'fields': ('name',), + }, { + 'id': 'cells', + 'label': 'Fields', + 'fields': ('cells',), + }, ) class Meta: diff --git a/creme/creme_config/forms/generics.py b/creme/creme_config/forms/generics.py index 86303f9807..65ef2f704e 100644 --- a/creme/creme_config/forms/generics.py +++ b/creme/creme_config/forms/generics.py @@ -331,7 +331,9 @@ def replacer(self, new_value): class DeletionForm(CremeModelForm): - blocks = FieldBlockManager(('general', _('Replacement'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Replacement'), 'fields': '*', + }) # TODO: what about deletion.DO_NOTHING ?! fk_handler_classes = { diff --git a/creme/creme_config/forms/relation_type.py b/creme/creme_config/forms/relation_type.py index 5459734a66..f1d3214dbf 100644 --- a/creme/creme_config/forms/relation_type.py +++ b/creme/creme_config/forms/relation_type.py @@ -2,7 +2,7 @@ ################################################################################ # Creme is a free/open-source Customer Relationship Management software -# Copyright (C) 2009-2020 Hybird +# Copyright (C) 2009-2021 Hybird # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -38,14 +38,18 @@ SemiFixedRelationType, ) -_CTypesField = partial(MultiEntityCTypeChoiceField, required=False, - label=_('Type constraint'), - help_text=_('No constraint means that all types are accepted.'), - ) -_PropertyTypesField = partial(ModelMultipleChoiceField, required=False, - label=_('Properties constraint'), - queryset=CremePropertyType.objects.all(), - ) +_CTypesField = partial( + MultiEntityCTypeChoiceField, + required=False, + label=_('Type constraint'), + help_text=_('No constraint means that all types are accepted.'), +) +_PropertyTypesField = partial( + ModelMultipleChoiceField, + required=False, + label=_('Properties constraint'), + queryset=CremePropertyType.objects.all(), +) class RelationTypeCreateForm(CremeForm): @@ -90,16 +94,22 @@ class RelationTypeCreateForm(CremeForm): ) blocks = FieldBlockManager( - ('subject', _('Subject'), ['subject_ctypes', 'subject_properties']), - ( - 'predicate', - _('Verb/Predicate'), - [ + { + 'id': 'subject', + 'label': _('Subject'), + 'fields': ['subject_ctypes', 'subject_properties'], + }, { + 'id': 'predicate', + 'label': _('Verb/Predicate'), + 'fields': [ 'subject_predicate', 'subject_is_copiable', 'subject_min_display', - 'object_predicate', 'object_is_copiable', 'object_min_display', + 'object_predicate', 'object_is_copiable', 'object_min_display', ], - ), - ('object', _('Object'), ['object_ctypes', 'object_properties']), + }, { + 'id': 'object', + 'label': _('Object'), + 'fields': ['object_ctypes', 'object_properties'], + }, ) def __init__(self, instance=None, *args, **kwargs): diff --git a/creme/creme_config/forms/transfer.py b/creme/creme_config/forms/transfer.py index 16ccf62173..169ed4e323 100644 --- a/creme/creme_config/forms/transfer.py +++ b/creme/creme_config/forms/transfer.py @@ -2,7 +2,7 @@ ################################################################################ # Creme is a free/open-source Customer Relationship Management software -# Copyright (C) 2017-2020 Hybird +# Copyright (C) 2017-2021 Hybird # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -35,12 +35,14 @@ class ImportForm(CremeForm): - config = FileField(label=_('Configuration file'), - help_text=_('A JSON file created with the export button ' - '(generally in another Creme instance).' - ), - # max_length= - ) + config = FileField( + label=_('Configuration file'), + help_text=_( + 'A JSON file created with the export button ' + '(generally in another Creme instance).' + ), + # max_length= + ) error_messages = { 'invalid_json': _('File content is not valid JSON.'), @@ -48,7 +50,9 @@ class ImportForm(CremeForm): 'invalid_version': _('The file has an unsupported version.'), } - blocks = FieldBlockManager(('general', _('Configuration file'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Configuration file'), 'fields': '*', + }) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -61,9 +65,9 @@ def clean_config(self): deserialized_data = json_load('\n'.join(line.decode() for line in config)) except Exception as e: logger.warning('ImportForm: invalid JSON (%s)', e) - raise ValidationError(self.error_messages['invalid_json'], - code='invalid_json', - ) + raise ValidationError( + self.error_messages['invalid_json'], code='invalid_json', + ) else: if not isinstance(deserialized_data, dict): raise ValidationError( @@ -73,25 +77,26 @@ def clean_config(self): ) if deserialized_data.get('version') != '1.0': - raise ValidationError(self.error_messages['invalid_version'], - code='invalid_version', - ) + raise ValidationError( + self.error_messages['invalid_version'], code='invalid_version', + ) validated_data = defaultdict(set) try: for importer in self._importers: - importer.validate(deserialized_data=deserialized_data, - validated_data=validated_data, - ) + importer.validate( + deserialized_data=deserialized_data, + validated_data=validated_data, + ) except ValidationError: raise except Exception as e: logger.exception('Error in ImportForm.clean_config()') - raise ValidationError(self.error_messages['invalid_data'], - params={'error': e}, - code='invalid_data', - ) + raise ValidationError( + self.error_messages['invalid_data'], + params={'error': e}, code='invalid_data', + ) return config diff --git a/creme/creme_config/forms/user_role.py b/creme/creme_config/forms/user_role.py index 4b3770fa45..1895b339f0 100644 --- a/creme/creme_config/forms/user_role.py +++ b/creme/creme_config/forms/user_role.py @@ -106,8 +106,15 @@ class CredentialsGeneralStep(CremeModelForm): ]) blocks = FieldBlockManager( - ('general', _('General information'), '*'), - ('actions', _('Actions'), [*PERM_FIELDS.keys()]), + { + 'id': 'general', + 'label': _('General information'), + 'fields': '*', + }, { + 'id': 'actions', + 'label': _('Actions'), + 'fields': [*PERM_FIELDS.keys()], + }, ) class Meta: @@ -169,8 +176,15 @@ class Meta: } blocks = FieldBlockManager( - ('general', _('Filter'), ('name', 'use_or')), - ('conditions', _('Conditions'), '*'), + { + 'id': 'general', + 'label': _('Filter'), + 'fields': ('name', 'use_or'), + }, { + 'id': 'conditions', + 'label': _('Conditions'), + 'fields': '*', + }, ) step_help_message = _( @@ -536,11 +550,17 @@ def save(self, commit=True, *args, **kwargs): class UserRoleCredentialsGeneralStep(CredentialsGeneralStep): blocks = FieldBlockManager( - ('general', _('First credentials: main information'), '*'), - ( - 'actions', _('First credentials: actions'), - ['can_view', 'can_change', 'can_delete', 'can_link', 'can_unlink'], - ), + { + 'id': 'general', + 'label': _('First credentials: main information'), + 'fields': '*', + }, { + 'id': 'actions', + 'label': _('First credentials: actions'), + 'fields': [ + 'can_view', 'can_change', 'can_delete', 'can_link', 'can_unlink', + ], + }, ) def __init__(self, role, *args, **kwargs): @@ -567,8 +587,15 @@ def save(self, commit=False, *args, **kwargs): class UserRoleCredentialsFilterStep(CredentialsFilterStep): blocks = FieldBlockManager( - ('general', _('First credentials: filter'), ('name', 'use_or')), - ('conditions', _('First credentials: conditions'), '*'), + { + 'id': 'general', + 'label': _('First credentials: filter'), + 'fields': ('name', 'use_or'), + }, { + 'id': 'conditions', + 'label': _('First credentials: conditions'), + 'fields': '*', + }, ) def __init__(self, role, *args, **kwargs): diff --git a/creme/creme_core/forms/base.py b/creme/creme_core/forms/base.py index bd892165de..500cf07e25 100644 --- a/creme/creme_core/forms/base.py +++ b/creme/creme_core/forms/base.py @@ -464,7 +464,9 @@ def as_span(self) -> str: # TODO: in another base class class CremeForm(HookableFormMixin, forms.Form): - blocks = FieldBlockManager(('general', _('General information'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('General information'), 'fields': '*', + }) def __init__(self, user, *args, **kwargs): """Constructor. @@ -493,7 +495,9 @@ def save(self, *args, **kwargs): class CremeModelForm(HookableFormMixin, forms.ModelForm): - blocks = FieldBlockManager(('general', _('General information'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('General information'), 'fields': '*', + }) class Meta: fields: Union[str, Tuple[str, ...]] = '__all__' @@ -599,13 +603,19 @@ class CremeEntityForm(CustomFieldsMixin, CremeModelForm): } blocks = CremeModelForm.blocks.new( - ('description', _('Description'), ('description',)), - ('properties', _('Properties'), ('property_types',)), - ( - 'relationships', - _('Relationships'), - ('rtypes_info', 'relation_types', 'semifixed_rtypes'), - ), + { + 'id': 'description', + 'label': _('Description'), + 'fields': ['description'], + }, { + 'id': 'properties', + 'label': _('Properties'), + 'fields': ['property_types'], + }, { + 'id': 'relationships', + 'label': _('Relationships'), + 'fields': ['rtypes_info', 'relation_types', 'semifixed_rtypes'], + }, ) class Meta: diff --git a/creme/creme_core/forms/entity_filter/forms.py b/creme/creme_core/forms/entity_filter/forms.py index f7bd348425..621bcf582d 100644 --- a/creme/creme_core/forms/entity_filter/forms.py +++ b/creme/creme_core/forms/entity_filter/forms.py @@ -2,7 +2,7 @@ ################################################################################ # Creme is a free/open-source Customer Relationship Management software -# Copyright (C) 2009-2020 Hybird +# Copyright (C) 2009-2021 Hybird # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -35,8 +35,15 @@ class _EntityFilterForm(CremeModelForm): } blocks = FieldBlockManager( - ('general', _('General information'), ('name', 'user', 'is_private', 'use_or')), - ('conditions', _('Conditions'), '*'), + { + 'id': 'general', + 'label': _('General information'), + 'fields': ('name', 'user', 'is_private', 'use_or'), + }, { + 'id': 'conditions', + 'label': _('Conditions'), + 'fields': '*', + }, ) class Meta(CremeModelForm.Meta): @@ -82,9 +89,9 @@ def clean(self): if not self._errors: if not any(cdata[f] for f in self.conditions_field_names): - raise ValidationError(self.error_messages['no_condition'], - code='no_condition', - ) + raise ValidationError( + self.error_messages['no_condition'], code='no_condition', + ) is_private = cdata.get('is_private', False) owner = cdata.get('user') diff --git a/creme/creme_core/forms/header_filter.py b/creme/creme_core/forms/header_filter.py index db8aed22ae..185979b15a 100644 --- a/creme/creme_core/forms/header_filter.py +++ b/creme/creme_core/forms/header_filter.py @@ -569,7 +569,9 @@ class Meta(CremeModelForm.Meta): ), } - blocks = CremeModelForm.blocks.new(('cells', _('Columns'), ['cells'])) + blocks = CremeModelForm.blocks.new({ + 'id': 'cells', 'label': _('Columns'), 'fields': ['cells'], + }) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/creme_core/forms/mass_import.py b/creme/creme_core/forms/mass_import.py index eedd6b2ec1..c4bdbb43c2 100644 --- a/creme/creme_core/forms/mass_import.py +++ b/creme/creme_core/forms/mass_import.py @@ -1182,8 +1182,15 @@ class ImportForm(CremeModelForm): header_dict: Dict[str, int] = {} # Idem blocks = FieldBlockManager( - ('general', _('Update mode'), ('step', 'document', 'has_header', 'key_fields')), - ('fields', _('Field values'), '*'), + { + 'id': 'general', + 'label': _('Update mode'), + 'fields': ('step', 'document', 'has_header', 'key_fields') + }, { + 'id': 'fields', + 'label': _('Field values'), + 'fields': '*', + }, ) def __init__(self, *args, **kwargs): @@ -1411,14 +1418,24 @@ class ImportForm4CremeEntity(ImportForm): ) blocks = FieldBlockManager( - ( - 'general', - _('General'), - ('step', 'document', 'has_header', 'user', 'key_fields') - ), - ('fields', _('Field values'), '*'), - ('properties', _('Related properties'), ('property_types',)), - ('relations', _('Associated relationships'), ('fixed_relations', 'dyn_relations')), + { + 'id': 'general', + 'label': _('General'), + 'fields': ('step', 'document', 'has_header', 'user', 'key_fields'), + }, { + 'id': 'fields', + 'label': _('Field values'), + 'fields': '*', + }, + { + 'id': 'properties', + 'label': _('Related properties'), + 'fields': ('property_types',), + }, { + 'id': 'relations', + 'label': _('Associated relationships'), + 'fields': ('fixed_relations', 'dyn_relations') + }, ) error_messages = { diff --git a/creme/creme_core/forms/relation.py b/creme/creme_core/forms/relation.py index 4335989fc0..c3ae8a9d5a 100644 --- a/creme/creme_core/forms/relation.py +++ b/creme/creme_core/forms/relation.py @@ -251,13 +251,11 @@ class MultiEntitiesRelationCreateForm(_RelationsCreateForm): entities_lbl = core_fields.ReadonlyMessageField(label=_('Related entities')) # TODO: use Meta.fields ?? (beware to bad_entities_lbl) - blocks = FieldBlockManager( - ( - 'general', - _('General information'), - ['entities_lbl', 'relations', 'semifixed_rtypes'], - ), - ) + blocks = FieldBlockManager({ + 'id': 'general', + 'label': _('General information'), + 'fields': ['entities_lbl', 'relations', 'semifixed_rtypes'], + }) def __init__(self, subjects, forbidden_subjects, relations_types=None, *args, **kwargs): first_subject = subjects[0] if subjects else forbidden_subjects[0] diff --git a/creme/emails/forms/campaign.py b/creme/emails/forms/campaign.py index 6e46f23b31..5fb0bcf78a 100644 --- a/creme/emails/forms/campaign.py +++ b/creme/emails/forms/campaign.py @@ -56,7 +56,9 @@ class CampaignAddMLForm(CremeForm): label=_('Lists'), required=False, model=emails.get_mailinglist_model(), ) - blocks = FieldBlockManager(('general', _('Mailing lists'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Mailing lists'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/emails/forms/mail.py b/creme/emails/forms/mail.py index 44082af7e3..da15092634 100644 --- a/creme/emails/forms/mail.py +++ b/creme/emails/forms/mail.py @@ -73,10 +73,23 @@ class EntityEmailForm(base_forms.CremeEntityQuickForm): } blocks = base_forms.FieldBlockManager( - ('recipients', _('Who'), ['user', 'sender', 'send_me', 'c_recipients', 'o_recipients']), - ('content', _('What'), ['subject', 'body', 'body_html']), - ('extra', _('With'), ['signature', 'attachments']), - ('required_cfields', _('Required custom fields'), '*'), + { + 'id': 'recipients', + 'label': _('Who'), + 'fields': ['user', 'sender', 'send_me', 'c_recipients', 'o_recipients'], + }, { + 'id': 'content', + 'label': _('What'), + 'fields': ['subject', 'body', 'body_html'], + }, { + 'id': 'extra', + 'label': _('With'), + 'fields': ['signature', 'attachments'] + }, { + 'id': 'required_cfields', + 'label': _('Required custom fields'), + 'fields': '*', + }, ) class Meta: diff --git a/creme/emails/forms/mailing_list.py b/creme/emails/forms/mailing_list.py index ac5204e63b..961f9d4303 100644 --- a/creme/emails/forms/mailing_list.py +++ b/creme/emails/forms/mailing_list.py @@ -56,7 +56,9 @@ class AddContactsForm(CremeForm): label=_('Contacts'), required=False, model=Contact, ) # other filter (name + email)?? - blocks = FieldBlockManager(('general', _('Contacts recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Contacts recipients'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) @@ -75,7 +77,9 @@ class AddOrganisationsForm(CremeForm): # TODO: factorise label=_('Organisations'), required=False, model=Organisation, ) # other filter (name + email)?? - blocks = FieldBlockManager(('general', _('Organisations recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Organisations recipients'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) @@ -124,7 +128,9 @@ def save(self): class AddContactsFromFilterForm(_AddPersonsFromFilterForm): - blocks = FieldBlockManager(('general', _('Contacts recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Contacts recipients'), 'fields': '*', + }) person_model = Contact @@ -133,7 +139,9 @@ def get_persons_m2m(self): class AddOrganisationsFromFilterForm(_AddPersonsFromFilterForm): - blocks = FieldBlockManager(('general', _('Organisations recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Organisations recipients'), 'fields': '*', + }) person_model = Organisation @@ -150,7 +158,9 @@ class AddChildForm(CremeForm): 'in_children': _('List already in the children'), } - blocks = FieldBlockManager(('general', _('Child mailing list'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Child mailing list'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) @@ -158,7 +168,7 @@ def __init__(self, entity, *args, **kwargs): def clean_child(self): child = self.cleaned_data['child'] - ml = self.ml + ml = self.ml if ml.id == child.id: raise ValidationError(self.error_messages['own_child'], code='own_child') diff --git a/creme/emails/forms/recipient.py b/creme/emails/forms/recipient.py index 449d7b20ba..f6e54f1e52 100644 --- a/creme/emails/forms/recipient.py +++ b/creme/emails/forms/recipient.py @@ -2,7 +2,7 @@ ################################################################################ # Creme is a free/open-source Customer Relationship Management software -# Copyright (C) 2009-2020 Hybird +# Copyright (C) 2009-2021 Hybird # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -61,7 +61,9 @@ class MailingListAddRecipientsForm(CremeForm): help_text=_('Write a valid e-mail address per line.'), ) - blocks = FieldBlockManager(('general', _('Recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Recipients'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) @@ -70,7 +72,7 @@ def __init__(self, entity, *args, **kwargs): def save(self): ml = self.ml recipients = self.cleaned_data['recipients'] - existing = frozenset( + existing = frozenset( EmailRecipient.objects.filter(ml=ml, address__in=recipients) .values_list('address', flat=True) ) @@ -91,7 +93,9 @@ class MailingListAddCSVForm(CremeForm): ) ) - blocks = FieldBlockManager(('general', _('CSV file'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('CSV file'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) @@ -124,7 +128,7 @@ def addresses(): for recipients in chunktools.iter_as_chunk(addresses(), 256): recipients = frozenset(recipients) - existing = frozenset( + existing = frozenset( filter_(ml=ml, address__in=recipients).values_list('address', flat=True) ) diff --git a/creme/emails/forms/sending.py b/creme/emails/forms/sending.py index bd5dab570b..1dbf6176b0 100644 --- a/creme/emails/forms/sending.py +++ b/creme/emails/forms/sending.py @@ -2,7 +2,7 @@ ################################################################################ # Creme is a free/open-source Customer Relationship Management software -# Copyright (C) 2009-2020 Hybird +# Copyright (C) 2009-2021 Hybird # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -62,16 +62,19 @@ class SendingCreateForm(CremeModelForm): error_messages = { 'forbidden': _( - 'You are not allowed to modify the sender address, please contact your administrator.' + 'You are not allowed to modify the sender address, ' + 'please contact your administrator.' ), } - blocks = CremeModelForm.blocks.new( - ('sending_date', _('Sending date'), ['type', 'sending_date', 'hour', 'minute']), - ) + blocks = CremeModelForm.blocks.new({ + 'id': 'sending_date', + 'label': _('Sending date'), + 'fields': ['type', 'sending_date', 'hour', 'minute'], + }) class Meta: - model = EmailSending + model = EmailSending exclude = () def __init__(self, entity, *args, **kwargs): @@ -90,11 +93,14 @@ def __init__(self, entity, *args, **kwargs): if not sender_setting.value: if not can_admin_emails: - sender_field.initial = _('No sender email address has been configured, ' - 'please contact your administrator.' - ) + sender_field.initial = _( + 'No sender email address has been configured, ' + 'please contact your administrator.' + ) else: - sender_field.help_text = _('Only an administrator can modify the sender address.') + sender_field.help_text = _( + 'Only an administrator can modify the sender address.' + ) sender_field.initial = sender_setting.value self.sender_setting = sender_setting @@ -103,7 +109,9 @@ def clean_sender(self): sender_value = self.cleaned_data.get('sender') if not self.can_edit_sender_value and sender_value != self.sender_setting.value: - raise ValidationError(self.error_messages['forbidden'], code='forbidden') + raise ValidationError( + self.error_messages['forbidden'], code='forbidden', + ) return sender_value diff --git a/creme/emails/forms/template.py b/creme/emails/forms/template.py index 17d44d1315..90cd664672 100644 --- a/creme/emails/forms/template.py +++ b/creme/emails/forms/template.py @@ -55,7 +55,9 @@ class EmailTemplateAddAttachment(CremeForm): label=_('Attachments'), required=False, model=get_document_model(), ) - blocks = FieldBlockManager(('general', _('Attachments'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Attachments'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/persons/apps.py b/creme/persons/apps.py index 7cbd8d70f1..167c274667 100644 --- a/creme/persons/apps.py +++ b/creme/persons/apps.py @@ -354,13 +354,11 @@ class ContactUserCreationForm(UserCreation.form_class): initial=constants.REL_SUB_EMPLOYED_BY, ) - blocks = UserCreation.form_class.blocks.new( - { - 'id': 'contact', - 'label': _('Related Contact'), - 'fields': ('organisation', 'relation'), - }, - ) + blocks = UserCreation.form_class.blocks.new({ + 'id': 'contact', + 'label': _('Related Contact'), + 'fields': ('organisation', 'relation'), + }) def __init__(this, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/reports/forms/graph.py b/creme/reports/forms/graph.py index 39dcfaec33..4be27a17eb 100644 --- a/creme/reports/forms/graph.py +++ b/creme/reports/forms/graph.py @@ -662,8 +662,8 @@ class ReportGraphForm(CremeModelForm): ordinate = OrdinateField(label=_('Y axis')) blocks = CremeModelForm.blocks.new( - ('abscissa', _('X axis'), ['abscissa']), - ('ordinate', _('Y axis'), ['ordinate']), + {'id': 'abscissa', 'label': _('X axis'), 'fields': ['abscissa']}, + {'id': 'ordinate', 'label': _('Y axis'), 'fields': ['ordinate']}, ) class Meta(CremeModelForm.Meta): diff --git a/creme/sms/forms/campaign.py b/creme/sms/forms/campaign.py index 6ff2b89cc9..aa21fec5db 100644 --- a/creme/sms/forms/campaign.py +++ b/creme/sms/forms/campaign.py @@ -56,7 +56,9 @@ class CampaignAddListForm(CremeForm): label=_('Lists'), required=False, model=MessagingList, ) - blocks = FieldBlockManager(('general', _('Messaging lists'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Messaging lists'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/sms/forms/messaging_list.py b/creme/sms/forms/messaging_list.py index 0a0e9a7a0e..ed327df448 100644 --- a/creme/sms/forms/messaging_list.py +++ b/creme/sms/forms/messaging_list.py @@ -50,7 +50,9 @@ class AddContactsForm(CremeForm): label=_('Contacts'), required=False, model=Contact, ) - blocks = FieldBlockManager(('general', _('Contacts recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Contacts recipients'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) @@ -100,7 +102,9 @@ def save(self): class AddContactsFromFilterForm(AddPersonsFromFilterForm): - blocks = FieldBlockManager(('general', _('Contacts recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Contacts recipients'), 'fields': '*', + }) person_model = Contact diff --git a/creme/sms/forms/recipient.py b/creme/sms/forms/recipient.py index b316a82bc6..f17c077244 100644 --- a/creme/sms/forms/recipient.py +++ b/creme/sms/forms/recipient.py @@ -36,7 +36,9 @@ class MessagingListAddRecipientsForm(CremeForm): help_text=_('One phone number per line'), ) - blocks = FieldBlockManager(('general', _('Recipients'), '*')) + blocks = FieldBlockManager({ + 'id': 'general', 'label': _('Recipients'), 'fields': '*', + }) def __init__(self, entity, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/creme/vcfs/forms/vcf.py b/creme/vcfs/forms/vcf.py index e64b5e8460..979fa8b625 100644 --- a/creme/vcfs/forms/vcf.py +++ b/creme/vcfs/forms/vcf.py @@ -2,7 +2,7 @@ ################################################################################ # Creme is a free/open-source Customer Relationship Management software -# Copyright (C) 2009-2020 Hybird +# Copyright (C) 2009-2021 Hybird # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -89,9 +89,10 @@ def clean_vcf_file(self): vcf_data = read_vcf(file_obj) except Exception as e: logger.exception('VcfForm -> error when reading file') - raise ValidationError(self.error_messages['invalid_file'], - params={'error': e}, code='invalid_file', - ) from e + raise ValidationError( + self.error_messages['invalid_file'], + params={'error': e}, code='invalid_file', + ) from e return vcf_data @@ -124,16 +125,19 @@ class Meta: homeaddr_region = CharField(label=_('Region'), required=False) # Related Organisation - create_or_attach_orga = BooleanField(label=_('Create or attach organisation'), - required=False, initial=False, - ) - organisation = CreatorEntityField(label=_('Organisation'), required=False, model=Organisation) - relation = ModelChoiceField(label=_('Position in the organisation'), - queryset=RelationType.objects.none(), - initial=REL_SUB_EMPLOYED_BY, required=False, - empty_label='', - widget=DynamicSelect(attrs={'autocomplete': True}), - ) + create_or_attach_orga = BooleanField( + label=_('Create or attach organisation'), required=False, initial=False, + ) + organisation = CreatorEntityField( + label=_('Organisation'), required=False, model=Organisation, + ) + relation = ModelChoiceField( + label=_('Position in the organisation'), + queryset=RelationType.objects.none(), + initial=REL_SUB_EMPLOYED_BY, required=False, + empty_label='', + widget=DynamicSelect(attrs={'autocomplete': True}), + ) # TODO: Composite field update_work_name = BooleanField( @@ -190,47 +194,64 @@ class Meta: orga_fields = ['name', 'phone', 'email', 'fax', 'url_site'] # Correspondence between VCF field types & form-field names. - phone_dict = {'HOME': 'phone', - 'CELL': 'mobile', - 'FAX': 'fax', - 'WORK': 'work_phone', - } - email_dict = {'HOME': 'email', - 'INTERNET': 'email', - 'WORK': 'work_email', - } - url_dict = {'HOME': 'url_site', - 'INTERNET': 'url_site', - 'WORK': 'work_url_site', - } + phone_dict = { + 'HOME': 'phone', + 'CELL': 'mobile', + 'FAX': 'fax', + 'WORK': 'work_phone', + } + email_dict = { + 'HOME': 'email', + 'INTERNET': 'email', + 'WORK': 'work_email', + } + url_dict = { + 'HOME': 'url_site', + 'INTERNET': 'url_site', + 'WORK': 'work_url_site', + } # Form-field names prefix for address + correspondence with VCF field types. - address_prefixes = {'HOME': HOME_ADDR_PREFIX, - 'WORK': WORK_ADDR_PREFIX, - } + address_prefixes = { + 'HOME': HOME_ADDR_PREFIX, + 'WORK': WORK_ADDR_PREFIX, + } # Mapping between form fields names (which use vcf lib names) & Address fields names. - address_mapping = [('name', 'name'), - ('address', 'address'), - ('city', 'city'), - ('country', 'country'), - ('code', 'zipcode'), - ('region', 'department'), - ] - - # blocks = CremeModelWithUserForm.blocks.new( + address_mapping = [ + ('name', 'name'), + ('address', 'address'), + ('city', 'city'), + ('country', 'country'), + ('code', 'zipcode'), + ('region', 'department'), + ] + blocks = CremeModelForm.blocks.new( - ('details', _('Details'), contact_details), - ('contact_address', _('Billing address'), - [HOME_ADDR_PREFIX + n[0] for n in address_mapping] - ), - ('organisation', _('Organisation'), - ['create_or_attach_orga', 'organisation', 'relation', - *chain.from_iterable(('update_work_' + fn, 'work_' + fn) for fn in orga_fields) - ] - ), - ('organisation_address', _('Organisation billing address'), - ['update_work_address', *(WORK_ADDR_PREFIX + n[0] for n in address_mapping)] - ), + { + 'id': 'details', + 'label': _('Details'), + 'fields': contact_details, + }, { + 'id': 'contact_address', + 'label': _('Billing address'), + 'fields': [HOME_ADDR_PREFIX + n[0] for n in address_mapping], + }, { + 'id': 'organisation', + 'label': _('Organisation'), + 'fields': [ + 'create_or_attach_orga', 'organisation', 'relation', + *chain.from_iterable( + (f'update_work_{fn}', f'work_{fn}') for fn in orga_fields + ), + ], + }, { + 'id': 'organisation_address', + 'label': _('Organisation billing address'), + 'fields': [ + 'update_work_address', + *(WORK_ADDR_PREFIX + n[0] for n in address_mapping), + ] + }, ) type_help_text = _('Read in VCF File without type : ') @@ -385,12 +406,13 @@ def _init_addresses_fields(self, vcf_data): fields[prefix + 'code'].initial = value.code fields[prefix + 'region'].initial = value.region else: - self._generate_help_text('homeaddr_address', - ', '.join([value.box, value.street, value.city, - value.region, value.code, value.country, - ] - ), - ) + self._generate_help_text( + 'homeaddr_address', + ', '.join([ + value.box, value.street, value.city, + value.region, value.code, value.country, + ]), + ) def _generate_help_text(self, field_name, value): field = self.fields[field_name] @@ -406,9 +428,9 @@ def _clean_orga_field(self, field_name): cleaned = cleaned_data.get(field_name) if cleaned_data['create_or_attach_orga'] and not cleaned: - raise ValidationError(self.error_messages['required4orga'], - code='required4orga', - ) + raise ValidationError( + self.error_messages['required4orga'], code='required4orga', + ) return cleaned @@ -424,13 +446,15 @@ def _clean_update_checkbox(self, checkbox_name): if checked: if not cleaned_data['create_or_attach_orga']: - raise ValidationError(self.error_messages['no_orga_creation'], - code='no_orga_creation', - ) + raise ValidationError( + self.error_messages['no_orga_creation'], + code='no_orga_creation', + ) elif not cleaned_data['organisation']: - raise ValidationError(self.error_messages['orga_not_selected'], - code='orga_not_selected', - ) + raise ValidationError( + self.error_messages['orga_not_selected'], + code='orga_not_selected', + ) return checked @@ -520,7 +544,9 @@ def _create_image(self, contact): image_encoded = cleaned_data['image_encoded'] if image_encoded: - img_name = secure_filename(f'{contact.last_name}_{contact.first_name}_{contact.id}') + img_name = secure_filename( + f'{contact.last_name}_{contact.first_name}_{contact.id}' + ) img_path = None if image_encoded.startswith(URL_START): @@ -608,9 +634,9 @@ def _create_orga(self, contact): organisation = Organisation.objects.create(user=user, **orga_kwargs) - orga_addr = self._create_address(cleaned_data, owner=organisation, - data_prefix=addr_prefix, - ) + orga_addr = self._create_address( + cleaned_data, owner=organisation, data_prefix=addr_prefix, + ) if orga_addr is not None: organisation.billing_address = orga_addr save_orga = True @@ -618,11 +644,12 @@ def _create_orga(self, contact): if save_orga: organisation.save() - Relation.objects.create(user=user, - subject_entity=contact, - type=cleaned_data['relation'], - object_entity=organisation, - ) + Relation.objects.create( + user=user, + subject_entity=contact, + type=cleaned_data['relation'], + object_entity=organisation, + ) @atomic def save(self, *args, **kwargs): @@ -635,9 +662,9 @@ def save(self, *args, **kwargs): contact.image = image save_contact = True - contact_addr = self._create_address(cleaned_data, owner=contact, - data_prefix=HOME_ADDR_PREFIX, - ) + contact_addr = self._create_address( + cleaned_data, owner=contact, data_prefix=HOME_ADDR_PREFIX, + ) if contact_addr is not None: contact.billing_address = contact_addr save_contact = True