From 13b9ef1c26bb89349a15be94db7d01512e270d5a Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 12 Feb 2021 15:43:15 +0100 Subject: Refactor - clean --- archaeological_context_records/admin.py | 4 +- archaeological_context_records/forms.py | 135 +++---- archaeological_context_records/ishtar_menu.py | 10 +- archaeological_context_records/lookups.py | 2 +- archaeological_context_records/models.py | 18 +- archaeological_context_records/views.py | 14 +- archaeological_files/forms.py | 114 +++--- archaeological_files/ishtar_menu.py | 38 +- archaeological_files/lookups.py | 2 +- archaeological_files/models.py | 88 ++--- archaeological_files/views.py | 18 +- archaeological_files/wizards.py | 4 +- archaeological_files_pdl/forms.py | 46 +-- archaeological_files_pdl/views.py | 4 +- archaeological_operations/admin.py | 4 +- archaeological_operations/forms.py | 424 ++++++++++----------- archaeological_operations/ishtar_menu.py | 40 +- archaeological_operations/lookups.py | 4 +- archaeological_operations/models.py | 12 +- archaeological_operations/utils.py | 6 +- archaeological_operations/views.py | 20 +- archaeological_operations/widgets.py | 6 +- archaeological_operations/wizards.py | 5 +- archaeological_warehouse/ishtar_menu.py | 30 +- archaeological_warehouse/lookups.py | 4 +- example_project/__init__.py.base.sample | 16 +- example_project/__init__.py.celery.sample | 16 +- example_project/settings.py | 8 +- ishtar_common/__init__.py | 6 +- ishtar_common/admin.py | 91 +++-- ishtar_common/forms.py | 77 ++-- ishtar_common/forms_common.py | 6 +- ishtar_common/ishtar_menu.py | 60 +-- .../commands/fix_missing_cached_labels.py | 6 +- ishtar_common/management/commands/ishtar_import.py | 2 +- .../management/commands/process_pending_update.py | 6 +- .../commands/reassociate_similar_images.py | 16 +- .../management/commands/regenerate_external_id.py | 4 +- .../management/commands/regenerate_qrcodes.py | 6 +- .../regenerate_search_vector_cached_label.py | 6 +- ishtar_common/models.py | 37 +- 41 files changed, 694 insertions(+), 721 deletions(-) diff --git a/archaeological_context_records/admin.py b/archaeological_context_records/admin.py index 9bd2f5c05..abee0a6d0 100644 --- a/archaeological_context_records/admin.py +++ b/archaeological_context_records/admin.py @@ -47,9 +47,9 @@ class AdminContextRecordForm(forms.ModelForm): class Meta: model = models.ContextRecord exclude = [] - point_2d = PointField(label=_(u"Point"), required=False, + point_2d = PointField(label=_("Point"), required=False, widget=OSMWidget) - multi_polygon = MultiPolygonField(label=_(u"Multi polygon"), required=False, + multi_polygon = MultiPolygonField(label=_("Multi polygon"), required=False, widget=OSMWidget) operation = AutoCompleteSelectField('operation') parcel = AutoCompleteSelectField('parcel', required=False) diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 357f5ce13..c4fa6f8fe 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -49,12 +49,12 @@ from ishtar_common import widgets class OperationFormSelection(CustomForm, forms.Form): form_label = _("Operation") - form_admin_name = _(u"Context record - 010 - Operation choice") + form_admin_name = _("Context record - 010 - Operation choice") form_slug = "contextrecord-010-operationchoice" associated_models = {'operation': Operation} currents = {'operation': Operation} operation = forms.IntegerField( - label=_(u"Operation"), required=False, + label=_("Operation"), required=False, widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-operation'), associated_model=Operation), @@ -200,9 +200,12 @@ def get_init_parcel(form, operation, prefix=""): parcels = sorted(parcels, key=sort) for key, gparcels in groupby(parcels, sort): form.fields[prefix + 'parcel'].choices.append( - (" - ".join([k for k in key if k]), - [(parcel.pk, parcel.short_label) for parcel in gparcels]) + ( + " - ".join(k for k in key if k), + [(parcel.pk, parcel.short_label) for parcel in gparcels], + ) ) + if len(form.fields[prefix + 'parcel'].choices) == 1 and \ (prefix + 'town') in form.fields: # only the empty choice is available @@ -218,7 +221,7 @@ def get_init_parcel(form, operation, prefix=""): class RecordFormGeneral(CustomForm, ManageOldType): HEADERS = {} form_label = _("General") - form_admin_name = _(u"Context record - 020 - General") + form_admin_name = _("Context record - 020 - General") form_slug = "contextrecord-020-general" file_upload = True base_models = ["documentation"] @@ -230,58 +233,58 @@ class RecordFormGeneral(CustomForm, ManageOldType): 'excavation_technic': models.ExcavationTechnicType} pk = forms.IntegerField(required=False, widget=forms.HiddenInput) operation_id = forms.IntegerField(widget=forms.HiddenInput) - parcel = forms.ChoiceField(label=_(u"Parcel"), choices=[]) - town = forms.ChoiceField(label=_(u"Town"), choices=[], required=False) + parcel = forms.ChoiceField(label=_("Parcel"), choices=[]) + town = forms.ChoiceField(label=_("Town"), choices=[], required=False) archaeological_site = forms.ChoiceField( label=" ", choices=[], required=False, - help_text=_(u"Only the items associated to the operation can be " - u"selected.") + help_text=_("Only the items associated to the operation can be " + "selected.") ) - label = forms.CharField(label=_(u"ID"), + label = forms.CharField(label=_("ID"), validators=[validators.MaxLengthValidator(200)]) - unit = forms.ChoiceField(label=_(u"Context record type"), required=False, + unit = forms.ChoiceField(label=_("Context record type"), required=False, choices=[]) - description = forms.CharField(label=_(u"Description"), + description = forms.CharField(label=_("Description"), widget=forms.Textarea, required=False) - comment = forms.CharField(label=_(u"General comment"), + comment = forms.CharField(label=_("General comment"), widget=forms.Textarea, required=False) excavation_technic = forms.ChoiceField( - label=_(u"Excavation technique"), choices=[], required=False) + label=_("Excavation technique"), choices=[], required=False) surface = forms.IntegerField( required=False, widget=widgets.AreaWidget, - label=_(u"Total surface (m2)"), + label=_("Total surface (m2)"), validators=[validators.MinValueValidator(0), validators.MaxValueValidator(999999999)]) - length = forms.FloatField(label=_(u"Length (m)"), required=False) - width = forms.FloatField(label=_(u"Width (m)"), required=False) - thickness = forms.FloatField(label=_(u"Thickness (m)"), required=False) - diameter = forms.FloatField(label=_(u"Diameter (m)"), required=False) - depth = forms.FloatField(label=_(u"Depth (m)"), required=False) + length = forms.FloatField(label=_("Length (m)"), required=False) + width = forms.FloatField(label=_("Width (m)"), required=False) + thickness = forms.FloatField(label=_("Thickness (m)"), required=False) + diameter = forms.FloatField(label=_("Diameter (m)"), required=False) + depth = forms.FloatField(label=_("Depth (m)"), required=False) depth_of_appearance = forms.FloatField( - label=_(u"Depth of appearance (m)"), required=False) - opening_date = forms.DateField(label=_(u"Opening date"), + label=_("Depth of appearance (m)"), required=False) + opening_date = forms.DateField(label=_("Opening date"), widget=DatePicker, required=False) - closing_date = forms.DateField(label=_(u"Closing date"), + closing_date = forms.DateField(label=_("Closing date"), widget=DatePicker, required=False) documentation = forms.MultipleChoiceField( label=_("Documentation"), choices=[], required=False, widget=widgets.Select2Multiple) location = forms.CharField( - label=_(u"Location"), widget=forms.Textarea, + label=_("Location"), widget=forms.Textarea, required=False, validators=[validators.MaxLengthValidator(200)]) - HEADERS['x'] = FormHeader(_(u"Coordinates")) - x = forms.FloatField(label=_(u"X"), required=False) - estimated_error_x = forms.FloatField(label=_(u"Estimated error for X"), + HEADERS['x'] = FormHeader(_("Coordinates")) + x = forms.FloatField(label=_("X"), required=False) + estimated_error_x = forms.FloatField(label=_("Estimated error for X"), required=False) - y = forms.FloatField(label=_(u"Y"), required=False) - estimated_error_y = forms.FloatField(label=_(u"Estimated error for Y"), + y = forms.FloatField(label=_("Y"), required=False) + estimated_error_y = forms.FloatField(label=_("Estimated error for Y"), required=False) - z = forms.FloatField(label=_(u"Z"), required=False) - estimated_error_z = forms.FloatField(label=_(u"Estimated error for Z"), + z = forms.FloatField(label=_("Z"), required=False) + estimated_error_z = forms.FloatField(label=_("Estimated error for Z"), required=False) spatial_reference_system = forms.ChoiceField( - label=_(u"Spatial Reference System"), required=False, choices=[]) + label=_("Spatial Reference System"), required=False, choices=[]) TYPES = [ FieldType('unit', models.Unit), @@ -368,12 +371,12 @@ class RecordFormGeneral(CustomForm, ManageOldType): if 'pk' in cleaned_data and cleaned_data['pk']: cr = cr.exclude(pk=int(cleaned_data['pk'])) if cr.count(): - raise forms.ValidationError(_(u"This ID already exists for " - u"this operation.")) + raise forms.ValidationError(_("This ID already exists for " + "this operation.")) if not self.cleaned_data.get('parcel', None) and not \ self.cleaned_data.get('town', None): - raise forms.ValidationError(_(u"You have to choose a town or a " - u"parcel.")) + raise forms.ValidationError(_("You have to choose a town or a " + "parcel.")) return cleaned_data @@ -384,8 +387,8 @@ class DatingForm(ManageOldType, forms.Form): 'quality': models.DatingQuality, 'period': models.Period} period = forms.ChoiceField(label=_("Period"), choices=[]) - start_date = forms.IntegerField(label=_(u"Start date"), required=False) - end_date = forms.IntegerField(label=_(u"End date"), required=False) + start_date = forms.IntegerField(label=_("Start date"), required=False) + end_date = forms.IntegerField(label=_("End date"), required=False) quality = forms.ChoiceField(label=_("Quality"), required=False, choices=[]) dating_type = forms.ChoiceField(label=_("Dating type"), required=False, choices=[]) @@ -402,7 +405,7 @@ class DatingForm(ManageOldType, forms.Form): DatingFormSet = formset_factory(DatingForm, can_delete=True, formset=FormSet) DatingFormSet.form_label = _("Dating") -DatingFormSet.form_admin_name = _(u"Context record - 030 - Dating") +DatingFormSet.form_admin_name = _("Context record - 030 - Dating") DatingFormSet.form_slug = "contextrecord-030-datings" @@ -412,7 +415,7 @@ class RecordRelationsForm(OpeRecordRelationsForm): associated_models = {'right_record': models.ContextRecord, 'relation_type': models.RelationType} right_record = forms.ChoiceField( - label=_(u"Context record"), choices=[], required=False) + label=_("Context record"), choices=[], required=False) def __init__(self, *args, **kwargs): crs = None @@ -428,34 +431,34 @@ class RecordRelationsForm(OpeRecordRelationsForm): RecordRelationsFormSet = formset_factory( RecordRelationsForm, can_delete=True, formset=RecordRelationsFormSetBase) -RecordRelationsFormSet.form_label = _(u"Relations") -RecordRelationsFormSet.form_admin_name = _(u"Context record - 050 - Relations") +RecordRelationsFormSet.form_label = _("Relations") +RecordRelationsFormSet.form_admin_name = _("Context record - 050 - Relations") RecordRelationsFormSet.form_slug = "contextrecord-050-recordrelations" class RecordFormInterpretation(CustomForm, ManageOldType, forms.Form): - form_label = _(u"Interpretation") - form_admin_name = _(u"Context record - 040 - Interpretation") + form_label = _("Interpretation") + form_admin_name = _("Context record - 040 - Interpretation") form_slug = "contextrecord-040-interpretation" associated_models = {'activity': models.ActivityType, 'identification': models.IdentificationType} datings_comment = forms.CharField( - label=_(u"Comments on dating"), required=False, + label=_("Comments on dating"), required=False, widget=forms.Textarea) - filling = forms.CharField(label=_(u"Filling"), + filling = forms.CharField(label=_("Filling"), widget=forms.Textarea, required=False) - interpretation = forms.CharField(label=_(u"Interpretation"), + interpretation = forms.CharField(label=_("Interpretation"), widget=forms.Textarea, required=False) - activity = forms.ChoiceField(label=_(u"Activity"), required=False, + activity = forms.ChoiceField(label=_("Activity"), required=False, choices=[]) identification = forms.ChoiceField(label=_("Identification"), required=False, choices=[]) - taq = forms.IntegerField(label=_(u"TAQ"), required=False) - taq_estimated = forms.IntegerField(label=_(u"Estimated TAQ"), + taq = forms.IntegerField(label=_("TAQ"), required=False) + taq_estimated = forms.IntegerField(label=_("Estimated TAQ"), required=False) - tpq = forms.IntegerField(label=_(u"TPQ"), required=False) - tpq_estimated = forms.IntegerField(label=_(u"Estimated TPQ"), + tpq = forms.IntegerField(label=_("TPQ"), required=False) + tpq_estimated = forms.IntegerField(label=_("Estimated TPQ"), required=False) TYPES = [ @@ -465,27 +468,27 @@ class RecordFormInterpretation(CustomForm, ManageOldType, forms.Form): OperationRecordFormSelection = get_form_selection( - 'OperationRecordFormSelection', _(u"Operation search"), 'operation_id', + 'OperationRecordFormSelection', _("Operation search"), 'operation_id', Operation, OperationSelect, 'get-operation', - _(u"You should select an operation.")) + _("You should select an operation.")) class RecordDeletionForm(FinalForm): confirm_msg = " " - confirm_end_msg = _(u"Would you like to delete this context record?") + confirm_end_msg = _("Would you like to delete this context record?") class QAOperationCR(IshtarForm): - town = forms.ChoiceField(label=_(u"Town"), choices=[]) + town = forms.ChoiceField(label=_("Town"), choices=[]) archaeological_site = forms.ChoiceField( label=" ", choices=[], required=False, - help_text=_(u"Only the items associated to the operation can be " - u"selected.") + help_text=_("Only the items associated to the operation can be " + "selected.") ) - label = forms.CharField(label=_(u"ID"), + label = forms.CharField(label=_("ID"), validators=[validators.MaxLengthValidator(200)]) - parcel = forms.ChoiceField(label=_(u"Parcel"), choices=[], required=False) - unit = forms.ChoiceField(label=_(u"Context record type"), required=False, + parcel = forms.ChoiceField(label=_("Parcel"), choices=[], required=False) + unit = forms.ChoiceField(label=_("Context record type"), required=False, choices=[]) TYPES = [ @@ -517,8 +520,8 @@ class QAOperationCR(IshtarForm): ] if self.profil.parcel_mandatory: self.fields['parcel'].choices += [('', '--')] + [ - (str(parcel.pk), u"{} - {}".format(parcel.short_label, - parcel.town)) + (str(parcel.pk), "{} - {}".format(parcel.short_label, + parcel.town)) for parcel in operation.parcels.all()] def save(self, items): @@ -539,9 +542,9 @@ class QAOperationCR(IshtarForm): class QAContextRecordDuplicateForm(IshtarForm): qa_label = forms.CharField(label=_("ID"), max_length=None, required=True) - qa_parcel = forms.ChoiceField(label=_(u"Parcel"), choices=[]) - qa_town = forms.ChoiceField(label=_(u"Town"), choices=[], required=False) - qa_unit = forms.ChoiceField(label=_(u"Context record type"), required=False, + qa_parcel = forms.ChoiceField(label=_("Parcel"), choices=[]) + qa_town = forms.ChoiceField(label=_("Town"), choices=[], required=False) + qa_unit = forms.ChoiceField(label=_("Context record type"), required=False, choices=[]) TYPES = [ diff --git a/archaeological_context_records/ishtar_menu.py b/archaeological_context_records/ishtar_menu.py index fc02c5eef..a7efd8da4 100644 --- a/archaeological_context_records/ishtar_menu.py +++ b/archaeological_context_records/ishtar_menu.py @@ -26,22 +26,22 @@ from . import models # be carreful: each access_controls must be relevant with check_rights in urls MENU_SECTIONS = [ - (40, SectionItem('record_management', _(u"Context record"), + (40, SectionItem('record_management', _("Context record"), profile_restriction='context_record', css='menu-context-record', - childs=[MenuItem('record_search', _(u"Search"), + childs=[MenuItem('record_search', _("Search"), model=models.ContextRecord, access_controls=['view_contextrecord', 'view_own_contextrecord']), - MenuItem('record_creation', _(u"Creation"), + MenuItem('record_creation', _("Creation"), model=models.ContextRecord, access_controls=['add_contextrecord', 'add_own_contextrecord']), - MenuItem('record_modification', _(u"Modification"), + MenuItem('record_modification', _("Modification"), model=models.ContextRecord, access_controls=['change_contextrecord', 'change_own_contextrecord']), - MenuItem('record_deletion', _(u"Deletion"), + MenuItem('record_deletion', _("Deletion"), model=models.ContextRecord, access_controls=['delete_contextrecord', 'delete_own_contextrecord']), diff --git a/archaeological_context_records/lookups.py b/archaeological_context_records/lookups.py index 8356f5e12..7b7d5b85d 100644 --- a/archaeological_context_records/lookups.py +++ b/archaeological_context_records/lookups.py @@ -22,4 +22,4 @@ class ContextRecordLookup(LookupChannel): return self.model.objects.filter(query).order_by('cached_label')[:20] def format_item_display(self, item): - return u"%s" % item.cached_label + return "%s" % item.cached_label diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index ff5f937e3..1576088ed 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -217,16 +217,12 @@ class Dating(models.Model): return True def context_records_lbl(self): - return " - ".join( - [cr.cached_label for cr in self.context_records.all()] - ) + return " - ".join(cr.cached_label for cr in self.context_records.all()) context_records_lbl.short_description = _("Context record") context_records_lbl.admin_order_field = "context_records__cached_label" def finds_lbl(self): - return " - ".join( - [f.cached_label for f in self.find.all()] - ) + return " - ".join(f.cached_label for f in self.find.all()) finds_lbl.short_description = _("Find") finds_lbl.admin_order_field = "find__cached_label" @@ -514,14 +510,14 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, QA_LOCK = QuickAction( url="contextrecord-qa-lock", icon_class="fa fa-lock", - text=_(u"Lock/Unlock"), target="many", + text=_("Lock/Unlock"), target="many", rights=['change_contextrecord', 'change_own_contextrecord'] ) QUICK_ACTIONS = [ QA_LOCK, QuickAction( url="contextrecord-qa-duplicate", icon_class="fa fa-clone", - text=_(u"Duplicate"), target="one", + text=_("Duplicate"), target="one", rights=['change_contextrecord', 'change_own_contextrecord']), ] @@ -861,8 +857,7 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, return self.full_label() def _generate_cached_periods(self): - return " & ".join([dating.period.label - for dating in self.datings.all()]) + return " & ".join(dating.period.label for dating in self.datings.all()) def _generate_cached_related_context_records(self): return self.detailed_related_context_records() @@ -888,8 +883,7 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem, return self.archaeological_site.reference if self.operation.archaeological_sites.count(): return "-".join( - [a.reference for a in self.operation.archaeological_sites.all()] - ) + a.reference for a in self.operation.archaeological_sites.all()) return "" @property diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index 215dd2b4a..2de60dc2c 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -99,7 +99,7 @@ get_contextrecordrelationdetail = get_item( record_search_wizard = wizards.RecordSearch.as_view([ ('general-record_search', forms.RecordFormSelection)], - label=_(u"Context record search"), + label=_("Context record search"), url_name='record_search',) record_creation_steps = [ @@ -113,7 +113,7 @@ record_creation_steps = [ record_creation_wizard = wizards.RecordWizard.as_view( record_creation_steps, - label=_(u"New context record"), + label=_("New context record"), url_name='record_creation', ) @@ -129,7 +129,7 @@ record_modification_steps = [ record_modification_wizard = wizards.RecordModifWizard.as_view( record_modification_steps, - label=_(u"Context record modification"), + label=_("Context record modification"), url_name='record_modification', ) @@ -147,7 +147,7 @@ def record_modify(request, pk): record_deletion_wizard = wizards.RecordDeletionWizard.as_view([ ('selec-record_deletion', forms.RecordFormMultiSelection), ('final-record_deletion', forms.RecordDeletionForm)], - label=_(u"Context record deletion"), + label=_("Context record deletion"), url_name='record_deletion',) @@ -216,12 +216,12 @@ class QAOperationContextRecordView(QAItemForm): template_name = 'ishtar/forms/qa_operation_contextrecord.html' model = Operation form_class = forms.QAOperationCR - page_name = _(u"Context record") + page_name = _("Context record") def get_quick_action(self): return QuickAction( url="operation-qa-contextrecord", icon_class="fa fa-plus", - text=_(u"Add context record"), target="one", + text=_("Add context record"), target="one", rights=['add_contextrecord', 'add_own_contextrecord']) def form_valid(self, form): @@ -253,6 +253,6 @@ class QAContextRecordDuplicateFormView(QAItemForm): def get_context_data(self, **kwargs): data = super(QAContextRecordDuplicateFormView, self).get_context_data( **kwargs) - data['action_name'] = _(u"Duplicate") + data['action_name'] = _("Duplicate") data["operation"] = self.items[0].operation return data diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index 9d2c14691..0108a8375 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -64,34 +64,34 @@ class FileSelect(DocumentItemSelect): internal_reference = forms.CharField(max_length=200, label=_("Other reference")) towns = get_town_field() - parcel = forms.CharField(label=_(u"Parcel")) + parcel = forms.CharField(label=_("Parcel")) if settings.ISHTAR_DPTS: towns__numero_insee__startswith = forms.ChoiceField( - label=_(u"Department"), choices=[]) - name = forms.CharField(label=_(u"File name"), max_length=200) + label=_("Department"), choices=[]) + name = forms.CharField(label=_("File name"), max_length=200) file_type = forms.ChoiceField(label=_("File type"), choices=[]) - end_date = forms.NullBooleanField(label=_(u"Is active?")) + end_date = forms.NullBooleanField(label=_("Is active?")) saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[]) permit_type = forms.ChoiceField(label=_("Permit type"), choices=[]) permit_reference = forms.CharField(max_length=200, label=_("Permit reference")) - comment = forms.CharField(label=_(u"Comment"), max_length=500) + comment = forms.CharField(label=_("Comment"), max_length=500) in_charge = forms.IntegerField( - label=_(u"In charge"), + label=_("In charge"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=[person_type_pk_lazy('sra_agent')]), associated_model=Person), validators=[valid_id(Person)]) general_contractor = forms.IntegerField( - label=_(u"General contractor"), + label=_("General contractor"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=[person_type_pk_lazy('general_contractor')]), associated_model=Person), validators=[valid_id(Person)]) general_contractor__attached_to = forms.IntegerField( - label=_(u"Organization of general contractor"), + label=_("Organization of general contractor"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-organization', args=[organization_type_pks_lazy([ @@ -99,14 +99,14 @@ class FileSelect(DocumentItemSelect): associated_model=Organization), validators=[valid_id(Organization)]) history_creator = forms.IntegerField( - label=_(u"Created by"), + label=_("Created by"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=['0', 'user']), associated_model=Person), validators=[valid_id(Person)]) history_modifier = forms.IntegerField( - label=_(u"Modified by"), + label=_("Modified by"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=['0', 'user']), @@ -155,8 +155,8 @@ class FileFormMultiSelection(LockForm, MultiSearchForm): validators=[valid_ids(models.File)]) -DATE_SOURCE = (('creation', _(u"Creation date")), - ("reception", _(u"Reception date"))) +DATE_SOURCE = (('creation', _("Creation date")), + ("reception", _("Reception date"))) class DashboardForm(IshtarForm): @@ -171,9 +171,9 @@ class DashboardForm(IshtarForm): saisine_type = forms.ChoiceField( label=_("Saisine type"), choices=[], required=False) after = forms.DateField( - label=_(u"Date after"), widget=DatePicker, required=False) + label=_("Date after"), widget=DatePicker, required=False) before = forms.DateField( - label=_(u"Date before"), widget=DatePicker, required=False) + label=_("Date before"), widget=DatePicker, required=False) def __init__(self, *args, **kwargs): if 'prefix' not in kwargs: @@ -230,9 +230,9 @@ class FileFormGeneral(ManageOldType): numeric_reference = forms.IntegerField( label=_("Numeric reference"), widget=forms.HiddenInput, required=False) internal_reference = forms.CharField( - label=_(u"Other reference"), max_length=60, required=False) - name = forms.CharField(label=_(u"Name"), required=False, max_length=100) - creation_date = forms.DateField(label=_(u"Creation date"), + label=_("Other reference"), max_length=60, required=False) + name = forms.CharField(label=_("Name"), required=False, max_length=100) + creation_date = forms.DateField(label=_("Creation date"), initial=get_now, widget=DatePicker) file_type = forms.ChoiceField(label=_("File type"), choices=[]) related_file = forms.IntegerField( @@ -240,11 +240,11 @@ class FileFormGeneral(ManageOldType): widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), associated_model=models.File), validators=[valid_id(models.File)]) - comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, + comment = forms.CharField(label=_("Comment"), widget=forms.Textarea, required=False) total_surface = forms.FloatField( required=False, widget=widgets.AreaWidget, - label=_(u"Total surface (m2)"), + label=_("Total surface (m2)"), validators=[validators.MinValueValidator(0), validators.MaxValueValidator(999999999)]) address = forms.CharField(label=_("Main address"), widget=forms.Textarea) @@ -262,16 +262,16 @@ class FileFormGeneral(ManageOldType): .exclude(internal_reference='').order_by('-pk') if q.count() and 'internal_reference' in self.fields: lbl = self.fields['internal_reference'].label - lbl += _(u"
(last recorded: %s)") % ( + lbl += _("
(last recorded: %s)") % ( q.all()[0].internal_reference) self.fields['internal_reference'].label = mark_safe(lbl) class FileFormGeneralRO(FileFormGeneral): year = forms.IntegerField( - label=_(u"Year"), widget=forms.TextInput(attrs={'readonly': True})) + label=_("Year"), widget=forms.TextInput(attrs={'readonly': True})) numeric_reference = forms.IntegerField( - label=_(u"Numeric reference"), widget=forms.TextInput()) + label=_("Numeric reference"), widget=forms.TextInput()) id = forms.IntegerField(' ', widget=forms.HiddenInput, required=False) def clean(self): @@ -284,13 +284,13 @@ class FileFormGeneralRO(FileFormGeneral): .exclude(pk=pk) if numeric_reference and q.count(): raise forms.ValidationError( - _(u"Another file with this numeric id exists.")) + _("Another file with this numeric id exists.")) return cleaned_data ParcelFormset = formset_factory(ParcelForm, can_delete=True, formset=ParcelFormSet) -ParcelFormset.form_label = _(u"Parcels") +ParcelFormset.form_label = _("Parcels") ParcelFormset.form_admin_name = _("Archaeological file - 020 - Parcel") ParcelFormset.form_slug = "file-020-parcels" @@ -325,20 +325,20 @@ class FileFormPreventive(ManageOldType, forms.Form): ]}, associated_model=Person, new=True), validators=[valid_id(Person)]) - permit_type = forms.ChoiceField(label=_(u"Permit type"), required=False, + permit_type = forms.ChoiceField(label=_("Permit type"), required=False, choices=[]) permit_reference = forms.CharField( - label=_(u"Permit reference"), required=False, + label=_("Permit reference"), required=False, validators=[validators.MaxLengthValidator(60)]) total_developed_surface = forms.FloatField( - widget=widgets.AreaWidget, label=_(u"Total developed surface (m2)"), + widget=widgets.AreaWidget, label=_("Total developed surface (m2)"), required=False, validators=[validators.MinValueValidator(0), validators.MaxValueValidator(999999999)]) if settings.COUNTRY == 'fr': - saisine_type = forms.ChoiceField(label=_(u"Saisine type"), + saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[]) reception_date = forms.DateField( - label=_(u"Reception date"), initial=get_now, widget=DatePicker) + label=_("Reception date"), initial=get_now, widget=DatePicker) def __init__(self, *args, **kwargs): super(FileFormPreventive, self).__init__(*args, **kwargs) @@ -393,19 +393,19 @@ class FileFormResearch(CustomForm, ManageOldType, forms.Form): validators=[valid_id(Organization)], required=False, ) if settings.COUNTRY == 'fr': - cira_advised = forms.NullBooleanField(label=u"Passage en CIRA", + cira_advised = forms.NullBooleanField(label="Passage en CIRA", required=False) research_comment = forms.CharField( - label=_(u"Comment"), widget=forms.Textarea, required=False) + label=_("Comment"), widget=forms.Textarea, required=False) if settings.COUNTRY == 'fr': mh_register = forms.NullBooleanField( - label=u"Sur Monument Historique classé", required=False) + label="Sur Monument Historique classé", required=False) mh_listing = forms.NullBooleanField( - label=u"Sur Monument Historique inscrit", required=False) + label="Sur Monument Historique inscrit", required=False) classified_area = forms.NullBooleanField( - label=_(u"Classified area"), required=False) + label=_("Classified area"), required=False) protected_area = forms.NullBooleanField( - label=_(u"Protected area"), required=False) + label=_("Protected area"), required=False) def __init__(self, *args, **kwargs): super(FileFormResearch, self).__init__(*args, **kwargs) @@ -420,34 +420,34 @@ class FileFormResearch(CustomForm, ManageOldType, forms.Form): class FinalFileClosingForm(FinalForm): confirm_msg = " " - confirm_end_msg = _(u"Would you like to close this archaeological file?") + confirm_end_msg = _("Would you like to close this archaeological file?") class FinalFileDeleteForm(FinalForm): confirm_msg = " " - confirm_end_msg = _(u"Would you like to delete this archaeological file ?") + confirm_end_msg = _("Would you like to delete this archaeological file ?") class AdministrativeActFileModifySelect(TableSelect): _model = AdministrativeAct search_vector = forms.CharField( - label=_(u"Full text search"), widget=widgets.SearchWidget( + label=_("Full text search"), widget=widgets.SearchWidget( 'archaeological-operations', 'administrativeact', 'administrativeactfile', )) year = forms.IntegerField(label=_("Year")) index = forms.IntegerField(label=_("Index")) if settings.COUNTRY == 'fr': - ref_sra = forms.CharField(label=u"Référence SRA", + ref_sra = forms.CharField(label="Référence SRA", max_length=15) act_type = forms.ChoiceField(label=_("Act type"), choices=[]) - act_object = forms.CharField(label=_(u"Object (full text search)"), + act_object = forms.CharField(label=_("Object (full text search)"), max_length=300) operation__towns = get_town_field() if settings.ISHTAR_DPTS: operation__towns__numero_insee__startswith = forms.ChoiceField( - label=_(u"Department"), choices=[]) + label=_("Department"), choices=[]) def __init__(self, *args, **kwargs): super(AdministrativeActFileModifySelect, self).__init__(*args, @@ -467,33 +467,33 @@ class AdministrativeActFileSelect(TableSelect): _model = AdministrativeAct search_vector = forms.CharField( - label=_(u"Full text search"), widget=widgets.SearchWidget( + label=_("Full text search"), widget=widgets.SearchWidget( 'archaeological-operations', 'administrativeact', 'administrativeactfile', )) year = forms.IntegerField(label=_("Year")) index = forms.IntegerField(label=_("Index")) if settings.COUNTRY == 'fr': - ref_sra = forms.CharField(label=u"Autre référence", + ref_sra = forms.CharField(label="Autre référence", max_length=15) act_type = forms.ChoiceField(label=_("Act type"), choices=[]) - indexed = forms.NullBooleanField(label=_(u"Indexed?")) + indexed = forms.NullBooleanField(label=_("Indexed?")) associated_file__towns = get_town_field() - parcel = forms.CharField(label=_(u"Parcel")) + parcel = forms.CharField(label=_("Parcel")) if settings.ISHTAR_DPTS: associated_file__towns__numero_insee__startswith = forms.ChoiceField( - label=_(u"Department"), choices=[]) - act_object = forms.CharField(label=_(u"Object"), + label=_("Department"), choices=[]) + act_object = forms.CharField(label=_("Object"), max_length=300) signature_date_before = forms.DateField( - label=_(u"Signature date before"), widget=DatePicker) + label=_("Signature date before"), widget=DatePicker) signature_date_after = forms.DateField( - label=_(u"Signature date after"), widget=DatePicker) + label=_("Signature date after"), widget=DatePicker) associated_file__name = forms.CharField( - label=_(u"File name"), max_length=200) + label=_("File name"), max_length=200) associated_file__general_contractor = forms.IntegerField( - label=_(u"General contractor"), + label=_("General contractor"), widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', @@ -501,7 +501,7 @@ class AdministrativeActFileSelect(TableSelect): associated_model=Person), validators=[valid_id(Person)]) associated_file__general_contractor__attached_to = forms.IntegerField( - label=_(u"Organization of general contractor"), + label=_("Organization of general contractor"), widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-organization', @@ -514,7 +514,7 @@ class AdministrativeActFileSelect(TableSelect): associated_file__internal_reference = forms.CharField( max_length=200, label=_("File other reference")) associated_file__in_charge = forms.IntegerField( - label=_(u"File in charge"), + label=_("File in charge"), widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', @@ -524,7 +524,7 @@ class AdministrativeActFileSelect(TableSelect): associated_file__permit_reference = forms.CharField( max_length=200, label=_("File permit reference")) history_creator = forms.IntegerField( - label=_(u"Created by"), + label=_("Created by"), widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', @@ -532,7 +532,7 @@ class AdministrativeActFileSelect(TableSelect): associated_model=Person), validators=[valid_id(Person)]) history_modifier = forms.IntegerField( - label=_(u"Modified by"), + label=_("Modified by"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=['0', 'user']), @@ -576,9 +576,9 @@ class AdministrativeActFileModifyFormSelection( class AdministrativeActFileForm(AdministrativeActForm): - form_admin_name = _(u"Archaeological file - Administrative act - General") + form_admin_name = _("Archaeological file - Administrative act - General") form_slug = "file-adminact-general" - act_type = forms.ChoiceField(label=_(u"Act type"), choices=[]) + act_type = forms.ChoiceField(label=_("Act type"), choices=[]) TYPES = [ FieldType('act_type', ActType, diff --git a/archaeological_files/ishtar_menu.py b/archaeological_files/ishtar_menu.py index 889d27287..7c5f870a6 100644 --- a/archaeological_files/ishtar_menu.py +++ b/archaeological_files/ishtar_menu.py @@ -30,47 +30,47 @@ from . import models MENU_SECTIONS = [ (20, SectionItem( - 'file_management', _(u"Archaeological file"), + 'file_management', _("Archaeological file"), profile_restriction='files', css='menu-file', childs=[ MenuItem( - 'file_search', _(u"Search"), + 'file_search', _("Search"), model=models.File, access_controls=['view_file', 'view_own_file']), MenuItem( - 'file_creation', _(u"Creation"), + 'file_creation', _("Creation"), model=models.File, access_controls=['add_file', 'add_own_file']), MenuItem( - 'file_modification', _(u"Modification"), + 'file_modification', _("Modification"), model=models.File, access_controls=['change_file', 'change_own_file']), MenuItem( - 'file_closing', _(u"Closing"), + 'file_closing', _("Closing"), model=models.File, access_controls=['close_file']), MenuItem( - 'file_deletion', _(u"Deletion"), + 'file_deletion', _("Deletion"), model=models.File, access_controls=['delete_file', 'delete_own_file']), SectionItem( - 'admin_act_files', _(u"Administrative act"), + 'admin_act_files', _("Administrative act"), childs=[ MenuItem('file_administrativeactfil_search', - _(u"Search"), + _("Search"), model=AdministrativeAct, access_controls=['change_administrativeact']), MenuItem('file_administrativeactfil', - _(u"Creation"), + _("Creation"), model=AdministrativeAct, access_controls=['change_administrativeact']), MenuItem('file_administrativeactfil_modification', - _(u"Modification"), + _("Modification"), model=AdministrativeAct, access_controls=['change_administrativeact']), MenuItem('file_administrativeactfil_deletion', - _(u"Deletion"), + _("Deletion"), model=AdministrativeAct, access_controls=['change_administrativeact']), ],)]),), @@ -78,29 +78,29 @@ MENU_SECTIONS = [ """ (100, SectionItem( - 'dashboard', _(u"Dashboard"), + 'dashboard', _("Dashboard"), profile_restriction='files', css='menu-file', - childs=[MenuItem('dashboard_main', _(u"General informations"), + childs=[MenuItem('dashboard_main', _("General informations"), model=models.File, access_controls=['change_file', 'change_own_file']), - MenuItem('dashboard_file', _(u"Archaeological files"), + MenuItem('dashboard_file', _("Archaeological files"), model=models.File, access_controls=['change_file', 'change_own_file']), ]), ), - SectionItem('dashboard', _(u"Dashboard"), + SectionItem('dashboard', _("Dashboard"), childs=[ - MenuItem('dashboard_main', _(u"General informations"), + MenuItem('dashboard_main', _("General informations"), model=models.File, access_controls=['change_file', 'change_own_file']), - MenuItem('dashboard_file', _(u"Archaeological files"), + MenuItem('dashboard_file', _("Archaeological files"), model=models.File, access_controls=['change_file', 'change_own_file']), - #MenuItem('dashboard_treatment', _(u"Treatments"), + #MenuItem('dashboard_treatment', _("Treatments"), # model=models.Treatment, # access_controls=['change_treatment',]), - #MenuItem('dashboard_warehouse', _(u"Warehouses"), + #MenuItem('dashboard_warehouse', _("Warehouses"), # model=models.Warehouse, # access_controls=['change_warehouse',]), ]), diff --git a/archaeological_files/lookups.py b/archaeological_files/lookups.py index dab3fb38c..a96974c9f 100644 --- a/archaeological_files/lookups.py +++ b/archaeological_files/lookups.py @@ -20,4 +20,4 @@ class FileLookup(LookupChannel): return self.model.objects.filter(query).order_by('cached_label')[:20] def format_item_display(self, item): - return u"%s" % item.cached_label + return "%s" % item.cached_label diff --git a/archaeological_files/models.py b/archaeological_files/models.py index bef7d53a1..5b2c89e16 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -47,8 +47,8 @@ from archaeological_operations.models import get_values_town_related, \ class FileType(GeneralType): class Meta: - verbose_name = _(u"Archaeological file type") - verbose_name_plural = _(u"Archaeological file types") + verbose_name = _("Archaeological file type") + verbose_name_plural = _("Archaeological file types") ordering = ('label',) @classmethod @@ -67,8 +67,8 @@ post_delete.connect(post_save_cache, sender=FileType) class PermitType(GeneralType): class Meta: - verbose_name = _(u"Permit type") - verbose_name_plural = _(u"Permit types") + verbose_name = _("Permit type") + verbose_name_plural = _("Permit types") ordering = ('label',) @@ -164,7 +164,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, ] COL_LABELS = { - 'towns_label': _(u"Towns"), + 'towns_label': _("Towns"), } REVERSED_BOOL_FIELDS = [ @@ -237,7 +237,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, ), 'general_contractor__attached_to': SearchAltName( pgettext_lazy("key for text search", - u"general-contractor-organization"), + "general-contractor-organization"), 'general_contractor__attached_to__cached_label__iexact' ), } @@ -283,7 +283,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, verbose_name=_("Responsible for planning service"), on_delete=models.SET_NULL,) # service instructeur - personne raw_town_planning_service = models.CharField( - _(u"Planning service (raw)"), max_length=200, + _("Planning service (raw)"), max_length=200, blank=True, null=True) planning_service = models.ForeignKey( Organization, @@ -320,14 +320,14 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, saisine_type = models.ForeignKey( SaisineType, blank=True, null=True, on_delete=models.SET_NULL, - verbose_name=u"Type de saisine") + verbose_name="Type de saisine") instruction_deadline = models.DateField(_(u'Instruction deadline'), blank=True, null=True) - total_surface = models.FloatField(_(u"Total surface (m2)"), + total_surface = models.FloatField(_("Total surface (m2)"), blank=True, null=True) total_developed_surface = models.FloatField( - _(u"Total developed surface (m2)"), blank=True, null=True) - locality = models.CharField(_(u"Locality"), + _("Total developed surface (m2)"), blank=True, null=True) + locality = models.CharField(_("Locality"), max_length=100, null=True, blank=True) address = models.TextField(_("Main address"), blank=True, default="") postal_code = models.CharField(_("Main address - postal code"), @@ -335,34 +335,34 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, comment = models.TextField(_("Comment"), blank=True, default="") # research archaeology --> departments = models.ManyToManyField( - Department, verbose_name=_(u"Departments"), blank=True) + Department, verbose_name=_("Departments"), blank=True) requested_operation_type = models.ForeignKey( OperationType, related_name='+', on_delete=models.SET_NULL, - null=True, blank=True, verbose_name=_(u"Requested operation type")) + null=True, blank=True, verbose_name=_("Requested operation type")) organization = models.ForeignKey( - Organization, blank=True, null=True, verbose_name=_(u"Organization"), + Organization, blank=True, null=True, verbose_name=_("Organization"), related_name='files', on_delete=models.SET_NULL) scientist = models.ForeignKey( Person, blank=True, null=True, related_name='scientist', - on_delete=models.SET_NULL, verbose_name=_(u"Scientist in charge")) + on_delete=models.SET_NULL, verbose_name=_("Scientist in charge")) research_comment = models.TextField( _("Research archaeology comment"), blank=True, default="") classified_area = models.NullBooleanField( - _(u"Classified area"), blank=True, null=True) + _("Classified area"), blank=True, null=True) protected_area = models.NullBooleanField( - _(u"Protected area"), blank=True, null=True) + _("Protected area"), blank=True, null=True) if settings.COUNTRY == 'fr': cira_advised = models.NullBooleanField( - u"Passage en CIRA", blank=True, null=True) + "Passage en CIRA", blank=True, null=True) mh_register = models.NullBooleanField( - u"Sur Monument Historique classé", blank=True, null=True) + "Sur Monument Historique classé", blank=True, null=True) mh_listing = models.NullBooleanField( - u"Sur Monument Historique inscrit", blank=True, null=True) + "Sur Monument Historique inscrit", blank=True, null=True) # <-- research archaeology documents = models.ManyToManyField( - Document, related_name="files", verbose_name=_(u"Documents"), + Document, related_name="files", verbose_name=_("Documents"), blank=True) cached_label = models.TextField( @@ -380,15 +380,15 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, ] class Meta: - verbose_name = _(u"Archaeological file") - verbose_name_plural = _(u"Archaeological files") + verbose_name = _("Archaeological file") + verbose_name_plural = _("Archaeological files") permissions = ( - ("view_file", u"Can view all Archaeological files"), - ("view_own_file", u"Can view own Archaeological file"), - ("add_own_file", u"Can add own Archaeological file"), - ("change_own_file", u"Can change own Archaeological file"), - ("delete_own_file", u"Can delete own Archaeological file"), - ("close_file", u"Can close File"), + ("view_file", "Can view all Archaeological files"), + ("view_own_file", "Can view own Archaeological file"), + ("add_own_file", "Can add own Archaeological file"), + ("change_own_file", "Can change own Archaeological file"), + ("delete_own_file", "Can delete own Archaeological file"), + ("close_file", "Can close File"), ) ordering = ('cached_label',) indexes = [ @@ -398,22 +398,22 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, @classmethod def _get_department_code(cls, value): if not settings.ISHTAR_DPTS: - return u"" + return "" for k, v in settings.ISHTAR_DPTS: if v.lower() == value: return k - return u"" + return "" def _get_base_image_path(self): - return u"{}/{}".format(self.SLUG, self.reference or self.short_label) + return "{}/{}".format(self.SLUG, self.reference or self.short_label) @property def short_class_name(self): - return _(u"FILE") + return _("FILE") @property def full_internal_ref(self): - return u"{}{}".format(settings.ISHTAR_FILE_PREFIX or '', + return "{}{}".format(settings.ISHTAR_FILE_PREFIX or '', self.external_id or '') @property @@ -455,7 +455,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, address = '' if self.general_contractor: if self.general_contractor.name: - address = u" ".join([ + address = " ".join([ str(getattr(self.general_contractor, key)) for key in ('title', 'surname', 'name') if getattr(self.general_contractor, key)]) @@ -472,12 +472,12 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, if self.general_contractor and self.general_contractor.address: address = self.general_contractor.address if self.general_contractor.address_complement: - address += u" " + self.general_contractor.address_complement + address += " " + self.general_contractor.address_complement if not address and self.corporation_general_contractor and\ self.corporation_general_contractor.address: address = self.corporation_general_contractor.address if self.corporation_general_contractor.address_complement: - address += u" " + \ + address += " " + \ self.corporation_general_contractor.address_complement return address @@ -485,13 +485,13 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, def general_contractor_address_3(self): address = '' if self.general_contractor and self.general_contractor.postal_code: - address = u" ".join([ + address = " ".join([ getattr(self.general_contractor, key) for key in ('postal_code', 'town') if getattr(self.general_contractor, key)]) if not address and self.corporation_general_contractor and\ self.corporation_general_contractor.address: - address = u" ".join([ + address = " ".join([ getattr(self.corporation_general_contractor, key) for key in ('postal_code', 'town') if getattr(self.corporation_general_contractor, key)]) @@ -576,7 +576,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, @property def reference(self): - return self.external_id or u"" + return self.external_id or "" def _generate_cached_label(self): items = [self.get_town_label(), self.reference] @@ -595,7 +595,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, elif self.towns.count() == 1: lbl = self.towns.all()[0].name elif self.towns.count() == 0: - lbl = str(_(u"No town")) + lbl = str(_("No town")) return lbl def get_department(self): @@ -632,7 +632,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, CompleteIdentifierItem, @property def town_list(self): - return u", ".join([str(tw) for tw in self.towns.all()]) + return ", ".join([str(tw) for tw in self.towns.all()]) def total_surface_ha(self): if self.total_surface: @@ -789,8 +789,8 @@ class FileByDepartment(models.Model): DELETE_SQL = """ DROP VIEW IF EXISTS file_department; """ - file = models.ForeignKey(File, verbose_name=_(u"File")) - department = models.ForeignKey(Department, verbose_name=_(u"Department"), + file = models.ForeignKey(File, verbose_name=_("File")) + department = models.ForeignKey(Department, verbose_name=_("Department"), on_delete=models.DO_NOTHING, blank=True, null=True) diff --git a/archaeological_files/views.py b/archaeological_files/views.py index f94de1cb1..dcd1387f9 100644 --- a/archaeological_files/views.py +++ b/archaeological_files/views.py @@ -110,7 +110,7 @@ def dashboard_file(request, *args, **kwargs): file_search_wizard = wizards.FileSearch.as_view( [('general-file_search', forms.FileFormSelection)], - label=_(u"File search"), url_name='file_search',) + label=_("File search"), url_name='file_search',) file_creation_wizard = wizards.FileWizard.as_view( [('general-file_creation', forms.FileFormGeneral), @@ -119,7 +119,7 @@ file_creation_wizard = wizards.FileWizard.as_view( ('preventive-file_creation', forms.FileFormPreventive), ('research-file_creation', forms.FileFormResearch), ('final-file_creation', forms.FinalForm)], - label=_(u"New file"), + label=_("New file"), condition_dict={ 'preventive-file_creation': is_preventive('general-file_creation', models.FileType, @@ -138,7 +138,7 @@ file_modification_wizard = wizards.FileModificationWizard.as_view( ('preventive-file_modification', forms.FileFormPreventive), ('research-file_modification', forms.FileFormResearch), ('final-file_modification', forms.FinalForm)], - label=_(u"File modification"), + label=_("File modification"), condition_dict={ 'preventive-file_modification': is_preventive('general-file_modification', @@ -164,12 +164,12 @@ file_closing_wizard = wizards.FileClosingWizard.as_view( [('selec-file_closing', forms.FileFormSelection), ('date-file_closing', ClosingDateFormSelection), ('final-file_closing', forms.FinalFileClosingForm)], - label=_(u"File closing"), url_name='file_closing',) + label=_("File closing"), url_name='file_closing',) file_deletion_wizard = wizards.FileDeletionWizard.as_view( [('selec-file_deletion', forms.FileFormMultiSelection), ('final-file_deletion', forms.FinalFileDeleteForm)], - label=_(u"File deletion"), + label=_("File deletion"), url_name='file_deletion',) @@ -186,7 +186,7 @@ file_administrativeactfile_search_wizard = \ SearchWizard.as_view([ ('selec-file_administrativeactfile_search', forms.AdministrativeActFileFormSelection)], - label=_(u"File: search administrative act"), + label=_("File: search administrative act"), url_name='file_administrativeactfile_search',) file_administrativeactfile_wizard = \ @@ -195,7 +195,7 @@ file_administrativeactfile_wizard = \ ('administrativeact-file_administrativeactfile', forms.AdministrativeActFileForm), ('final-file_administrativeactfile', forms.FinalForm)], - label=_(u"File: new administrative act"), + label=_("File: new administrative act"), url_name='file_administrativeactfile',) file_administrativeactfile_modification_wizard = \ @@ -205,7 +205,7 @@ file_administrativeactfile_modification_wizard = \ ('administrativeact-file_administrativeactfile_modification', forms.AdministrativeActFileModifForm), ('final-file_administrativeactfile_modification', forms.FinalForm)], - label=_(u"File: administrative act modification"), + label=_("File: administrative act modification"), url_name='file_administrativeactfile_modification',) @@ -231,7 +231,7 @@ file_administrativeactfile_deletion_wizard = \ forms.AdministrativeActFileFormSelection), ('final-file_administrativeactfile_deletion', FinalAdministrativeActDeleteForm)], - label=_(u"File: administrative act deletion"), + label=_("File: administrative act deletion"), url_name='file_administrativeactfile_deletion',) diff --git a/archaeological_files/wizards.py b/archaeological_files/wizards.py index c208dc097..c259effbe 100644 --- a/archaeological_files/wizards.py +++ b/archaeological_files/wizards.py @@ -145,7 +145,7 @@ class FileAdministrativeActWizard(OperationAdministrativeActWizard): file_id = self.session_get_value(form_key, "pk") try: return ( - (_(u"Archaeological file"), + (_("Archaeological file"), str(models.File.objects.get(pk=file_id))),) except models.File.DoesNotExist: return @@ -155,7 +155,7 @@ class FileAdministrativeActWizard(OperationAdministrativeActWizard): admin = AdministrativeAct.objects.get(pk=admin_id) if not admin.associated_file: return - return ((_(u"Archaeological file"), + return ((_("Archaeological file"), str(admin.associated_file)),) except AdministrativeAct.DoesNotExist: return diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py index d4cc749a4..54cc51dde 100644 --- a/archaeological_files_pdl/forms.py +++ b/archaeological_files_pdl/forms.py @@ -43,7 +43,7 @@ from bootstrap_datepicker.widgets import DatePicker class FileFormGeneral(CustomForm, ManageOldType): form_label = _("General") - form_admin_name = _(u"Archaeological file - 010 - General") + form_admin_name = _("Archaeological file - 010 - General") form_slug = "file-010-general" associated_models = {'file_type': models.FileType} file_type = forms.ChoiceField(label=_("File type"), choices=[]) @@ -69,14 +69,14 @@ class FileFormGeneral(CustomForm, ManageOldType): class FileFormPreventiveType(CustomForm, ManageOldType, forms.Form): - form_label = u"Saisine" - form_admin_name = _(u"Archaeological file - 013 - Preventive - Saisine") + form_label = "Saisine" + form_admin_name = _("Archaeological file - 013 - Preventive - Saisine") form_slug = "file-013-preventivesaisine" associated_models = {'saisine_type': models.SaisineType, 'permit_type': models.PermitType} - permit_type = forms.ChoiceField(label=_(u"Permit type"), required=False, + permit_type = forms.ChoiceField(label=_("Permit type"), required=False, choices=[]) - saisine_type = forms.ChoiceField(label=_(u"Saisine type"), + saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[]) TYPES = [ FieldType('saisine_type', models.SaisineType), @@ -90,14 +90,14 @@ class FileFormPreventiveType(CustomForm, ManageOldType, forms.Form): class FileFormPlanning(CustomForm, ManageOldType): - form_label = _(u"Planning") - form_admin_name = _(u"Archaeological file - 017 - Preventive - Planning") + form_label = _("Planning") + form_admin_name = _("Archaeological file - 017 - Preventive - Planning") form_slug = "file-017-preventiveplanning" base_models = ['town', 'department'] associated_models = {'town': Town, 'department': Department} HEADERS = {} HEADERS['town'] = FormHeader(_("Localisation")) - name = forms.CharField(label=_(u"Planning name"), required=False, + name = forms.CharField(label=_("Planning name"), required=False, max_length=100) town = widgets.Select2MultipleField( model=Town, label=_("Towns"), required=False, remote=True) @@ -105,48 +105,48 @@ class FileFormPlanning(CustomForm, ManageOldType): model=Department, label=_("Departments"), required=False, help_text=_("Only relevant when no town is provided.") ) - locality = forms.CharField(label=_(u"Locality"), max_length=100, + locality = forms.CharField(label=_("Locality"), max_length=100, required=False) address = forms.CharField( - label=_(u"Address (number/street)"), - widget=forms.Textarea(attrs={"placeholder": _(u"Number/street")}), + label=_("Address (number/street)"), + widget=forms.Textarea(attrs={"placeholder": _("Number/street")}), required=False) - postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + postal_code = forms.CharField(label=_("Postal code"), max_length=10, required=False) HEADERS['total_surface'] = FormHeader(_("Surfaces")) total_surface = forms.FloatField( required=False, widget=widgets.AreaWidget, - label=_(u"Total surface (m2)"), + label=_("Total surface (m2)"), validators=[validators.MinValueValidator(0), validators.MaxValueValidator(999999999)]) total_developed_surface = forms.FloatField( widget=widgets.AreaWidget, - label=_(u"Total developed surface (m2)"), + label=_("Total developed surface (m2)"), required=False, validators=[validators.MinValueValidator(0), validators.MaxValueValidator(999999999)]) class FileFormResearchAddress(CustomForm, forms.Form): - form_label = _(u"Address") - form_admin_name = _(u"Archaeological file - 015 - Research - Address") + form_label = _("Address") + form_admin_name = _("Archaeological file - 015 - Research - Address") form_slug = "file-015-researchplanning" base_models = ['town', 'department'] associated_models = {'town': Town, 'department': Department} - name = forms.CharField(label=_(u"Project name"), required=False, + name = forms.CharField(label=_("Project name"), required=False, max_length=100) town = widgets.Select2MultipleField( model=Town, label=_("Towns"), required=False, remote=True) department = widgets.Select2MultipleField( model=Department, label=_("Departments"), required=False) - locality = forms.CharField(label=_(u"Locality"), max_length=100, + locality = forms.CharField(label=_("Locality"), max_length=100, required=False) address = forms.CharField( - label=_(u"Address (number/street)"), - widget=forms.Textarea(attrs={"placeholder": _(u"Number/street")}), + label=_("Address (number/street)"), + widget=forms.Textarea(attrs={"placeholder": _("Number/street")}), required=False) - postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + postal_code = forms.CharField(label=_("Postal code"), max_length=10, required=False) @@ -247,7 +247,7 @@ class PersonOrgaForm(forms.Form): class FileFormGeneralContractor(CustomForm, ManageOldType): - form_label = _(u"General contractor") + form_label = _("General contractor") form_admin_name = _("Archaeological file - 030 - General contractor") form_slug = "file-030-generalcontractor" extra_form_modals = ["person", "organization"] @@ -404,7 +404,7 @@ class FileFormInstruction(CustomForm, IshtarForm): widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), associated_model=models.File), validators=[valid_id(models.File)]) - comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, + comment = forms.CharField(label=_("Comment"), widget=forms.Textarea, required=False) instruction_deadline = forms.DateField(widget=DatePicker, required=False) diff --git a/archaeological_files_pdl/views.py b/archaeological_files_pdl/views.py index 0f5d0171d..a7d0dee02 100644 --- a/archaeological_files_pdl/views.py +++ b/archaeological_files_pdl/views.py @@ -46,7 +46,7 @@ file_creation_wizard = FileWizard.as_view([ ('research-file_creation', ref_forms.FileFormResearch), ('instruction-file_creation', forms.FileFormInstruction), ('final-file_creation', ref_forms.FinalForm)], - label=_(u"New file"), + label=_("New file"), condition_dict={ 'preventivetype-file_creation': file_creation_wizard_is_preventive, 'preventiveplanning-file_creation': file_creation_wizard_is_preventive, @@ -73,7 +73,7 @@ file_modification_wizard = FileModificationWizard.as_view([ ('research-file_modification', ref_forms.FileFormResearch), ('instruction-file_modification', forms.FileFormInstructionEdit), ('final-file_modification', ref_forms.FinalForm)], - label=_(u"File modification"), + label=_("File modification"), condition_dict={ 'preventivetype-file_modification': file_modification_wizard_is_preventive, 'preventiveplanning-file_modification': diff --git a/archaeological_operations/admin.py b/archaeological_operations/admin.py index 312f2c3d3..0650d4711 100644 --- a/archaeological_operations/admin.py +++ b/archaeological_operations/admin.py @@ -96,9 +96,9 @@ class AdminOperationForm(forms.ModelForm): class Meta: model = models.Operation exclude = [] - point = PointField(label=_(u"Point"), required=False, + point = PointField(label=_("Point"), required=False, widget=OSMWidget) - multi_polygon = MultiPolygonField(label=_(u"Multi polygon"), required=False, + multi_polygon = MultiPolygonField(label=_("Multi polygon"), required=False, widget=OSMWidget) in_charge = AutoCompleteSelectField('person', required=False) scientist = AutoCompleteSelectField('person', required=False) diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 3714b2e6a..b54a081d8 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -60,7 +60,7 @@ class ParcelField(forms.MultiValueField): super(ParcelField, self).__init__(*args, **kwargs) def compress(self, data_list): - return u"-".join(data_list) + return "-".join(data_list) class ParcelForm(IshtarForm): @@ -73,12 +73,12 @@ class ParcelForm(IshtarForm): year = forms.IntegerField(label=_("Year"), required=False, validators=[validators.MinValueValidator(1000), validators.MaxValueValidator(2100)]) - section = forms.CharField(label=_(u"Section"), required=False, + section = forms.CharField(label=_("Section"), required=False, validators=[validators.MaxLengthValidator(4)]) parcel_number = forms.CharField( - label=_(u"Parcel number"), required=False, + label=_("Parcel number"), required=False, validators=[validators.MaxLengthValidator(6)]) - public_domain = forms.BooleanField(label=_(u"Public domain"), + public_domain = forms.BooleanField(label=_("Public domain"), initial=False, required=False) def __init__(self, *args, **kwargs): @@ -122,7 +122,7 @@ class ParcelForm(IshtarForm): not self.cleaned_data.get('public_domain'): return {} if not self.cleaned_data.get('town'): - raise forms.ValidationError(_(u"Town section is required.")) + raise forms.ValidationError(_("Town section is required.")) return self.cleaned_data @classmethod @@ -193,10 +193,10 @@ class ParcelForm(IshtarForm): res += " ; " res += town + u' : ' if c_section: - res += u" / " + res += " / " c_section = section res += section + u' ' - res += u", ".join(parcel_numbers) + res += ", ".join(parcel_numbers) if year: res += " (%s)" % str(year) return res @@ -206,10 +206,10 @@ class ParcelSelectionForm(IshtarForm): _town = forms.ChoiceField(label=_("Town"), choices=(), required=False, validators=[valid_id(models.Town)]) _parcel_selection = forms.CharField( - label=_(u"Full text input"), + label=_("Full text input"), widget=SelectParcelWidget(attrs={'class': 'parcel-select'}), - help_text=_(u"example: \"2013: XD:1 to 13,24,33 to 39, YD:24\" or " - u"\"AB:24,AC:42\""), + help_text=_("example: \"2013: XD:1 to 13,24,33 to 39, YD:24\" or " + "\"AB:24,AC:42\""), max_length=100, required=False) @@ -373,10 +373,10 @@ class RecordRelationsForm(ManageOldType): current_related_model = models.Operation associated_models = {'right_record': models.Operation, 'relation_type': models.RelationType} - relation_type = forms.ChoiceField(label=_(u"Relation type"), + relation_type = forms.ChoiceField(label=_("Relation type"), choices=[], required=False) right_record = forms.IntegerField( - label=_(u"Operation"), + label=_("Operation"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-operation'), associated_model=models.Operation), @@ -398,8 +398,8 @@ class RecordRelationsForm(ManageOldType): if not nc or nc[-1][0] != rel: nc.append([rel, []]) nc[-1][1].append(ope) - rendered = u";".join( - [u"{}{} {}".format(rel, _(u":"), u" ; ".join(opes)) + rendered = ";".join( + ["{}{} {}".format(rel, _(":"), " ; ".join(opes)) for rel, opes in nc]) return rendered @@ -407,16 +407,16 @@ class RecordRelationsForm(ManageOldType): cleaned_data = self.cleaned_data if (cleaned_data.get('relation_type', None) and not cleaned_data.get('right_record', None)): - raise forms.ValidationError(_(u"You should select an operation.")) + raise forms.ValidationError(_("You should select an operation.")) if (not cleaned_data.get('relation_type', None) and cleaned_data.get('right_record', None)): raise forms.ValidationError( - _(u"You should select a relation type.")) + _("You should select a relation type.")) if self.left_record and \ str(cleaned_data.get('right_record', None)) == str( self.left_record.pk): raise forms.ValidationError( - _(u"An operation cannot be related to herself.")) + _("An operation cannot be related to herself.")) return cleaned_data @classmethod @@ -448,7 +448,7 @@ class RecordRelationsForm(ManageOldType): nc[-1][1].append(ope) result.append((_("Current relations"), cls._format_lst(current))) if deleted: - result.append((_("Deleted relations"), u" ; ".join(deleted))) + result.append((_("Deleted relations"), " ; ".join(deleted))) return result @@ -472,37 +472,37 @@ class RecordRelationsFormSetBase(FormSet): RecordRelationsFormSet = formset_factory( RecordRelationsForm, can_delete=True, formset=RecordRelationsFormSetBase) -RecordRelationsFormSet.form_label = _(u"Relations") -RecordRelationsFormSet.form_admin_name = _(u"Operation - 080 - Relations") +RecordRelationsFormSet.form_label = _("Relations") +RecordRelationsFormSet.form_admin_name = _("Operation - 080 - Relations") RecordRelationsFormSet.form_slug = "operation-080-relations" class OperationSelect(DocumentItemSelect): _model = models.Operation - form_admin_name = _(u"Operation - 001 - Search") + form_admin_name = _("Operation - 001 - Search") form_slug = "operation-001-search" search_vector = forms.CharField( - label=_(u"Full text search"), widget=widgets.SearchWidget( + label=_("Full text search"), widget=widgets.SearchWidget( 'archaeological-operations', 'operation')) year = forms.IntegerField(label=_("Year")) - operation_code = forms.IntegerField(label=_(u"Numeric reference")) + operation_code = forms.IntegerField(label=_("Numeric reference")) code_patriarche = forms.CharField( max_length=500, widget=OAWidget, label="Code PATRIARCHE") drassm_code = forms.CharField( - label=_(u"DRASSM code"), required=False, max_length=100) + label=_("DRASSM code"), required=False, max_length=100) towns = get_town_field() towns__areas = forms.ChoiceField(label=_("Areas"), choices=[]) - parcel = forms.CharField(label=_(u"Parcel")) + parcel = forms.CharField(label=_("Parcel")) if settings.ISHTAR_DPTS: towns__numero_insee__startswith = forms.ChoiceField( - label=_(u"Department"), choices=[]) - common_name = forms.CharField(label=_(u"Name"), max_length=30) - address = forms.CharField(label=_(u"Address / Locality"), max_length=100) - operation_type = forms.ChoiceField(label=_(u"Operation type"), choices=[]) - end_date = forms.NullBooleanField(label=_(u"Is open?")) + label=_("Department"), choices=[]) + common_name = forms.CharField(label=_("Name"), max_length=30) + address = forms.CharField(label=_("Address / Locality"), max_length=100) + operation_type = forms.ChoiceField(label=_("Operation type"), choices=[]) + end_date = forms.NullBooleanField(label=_("Is open?")) in_charge = forms.IntegerField( widget=widgets.JQueryAutoComplete( reverse_lazy( @@ -510,14 +510,14 @@ class OperationSelect(DocumentItemSelect): args=[person_type_pks_lazy(['sra_agent'])] ), associated_model=Person), - label=_(u"In charge")) + label=_("In charge")) scientist = forms.IntegerField( widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person-permissive', args=[person_type_pks_lazy(['sra_agent', 'head_scientist'])]), associated_model=Person), - label=_(u"Scientist in charge")) + label=_("Scientist in charge")) operator = forms.IntegerField( label=_("Operator"), widget=widgets.JQueryAutoComplete( @@ -526,24 +526,24 @@ class OperationSelect(DocumentItemSelect): args=[organization_type_pks_lazy(['operator'])]), associated_model=Organization), validators=[valid_id(Organization)]) - # operator_reference = forms.CharField(label=_(u"Operator reference"), + # operator_reference = forms.CharField(label=_("Operator reference"), # max_length=20) - remains = forms.ChoiceField(label=_(u"Remains"), choices=[]) - periods = forms.ChoiceField(label=_(u"Periods"), choices=[]) - start_before = DateField(label=_(u"Started before")) - start_after = DateField(label=_(u"Started after")) - end_before = DateField(label=_(u"Ended before")) - end_after = DateField(label=_(u"Ended after")) + remains = forms.ChoiceField(label=_("Remains"), choices=[]) + periods = forms.ChoiceField(label=_("Periods"), choices=[]) + start_before = DateField(label=_("Started before")) + start_after = DateField(label=_("Started after")) + end_before = DateField(label=_("Ended before")) + end_after = DateField(label=_("Ended after")) relation_types = forms.ChoiceField( - label=_(u"Search within relations"), choices=[]) - comment = forms.CharField(label=_(u"Comment"), max_length=500) - abstract = forms.CharField(label=_(u"Abstract (full text search)")) + label=_("Search within relations"), choices=[]) + comment = forms.CharField(label=_("Comment"), max_length=500) + abstract = forms.CharField(label=_("Abstract (full text search)")) scientific_documentation_comment = forms.CharField( - label=_(u"Comment about scientific documentation")) - record_quality_type = forms.ChoiceField(label=_(u"Record quality")) - report_processing = forms.ChoiceField(label=_(u"Report processing"), + label=_("Comment about scientific documentation")) + record_quality_type = forms.ChoiceField(label=_("Record quality")) + report_processing = forms.ChoiceField(label=_("Report processing"), choices=[]) - virtual_operation = forms.NullBooleanField(label=_(u"Virtual operation")) + virtual_operation = forms.NullBooleanField(label=_("Virtual operation")) archaeological_sites = forms.IntegerField( label=_("Archaeological site"), widget=widgets.JQueryAutoComplete( @@ -551,31 +551,31 @@ class OperationSelect(DocumentItemSelect): associated_model=models.ArchaeologicalSite), validators=[valid_id(models.ArchaeologicalSite)]) history_creator = forms.IntegerField( - label=_(u"Created by"), + label=_("Created by"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=['0', 'user']), associated_model=Person), validators=[valid_id(Person)]) history_modifier = forms.IntegerField( - label=_(u"Modified by"), + label=_("Modified by"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', args=['0', 'user']), associated_model=Person), validators=[valid_id(Person)]) documentation_received = forms.NullBooleanField( - label=_(u"Documentation received")) + label=_("Documentation received")) documentation_deadline_before = DateField( - label=_(u"Documentation deadline before")) + label=_("Documentation deadline before")) documentation_deadline_after = DateField( - label=_(u"Documentation deadline after")) + label=_("Documentation deadline after")) has_finds = forms.NullBooleanField(label=_("Has finds")) finds_received = forms.NullBooleanField( - label=_(u"Finds received")) + label=_("Finds received")) finds_deadline_before = DateField( - label=_(u"Finds deadline before")) + label=_("Finds deadline before")) finds_deadline_after = DateField( - label=_(u"Finds deadline after")) + label=_("Finds deadline after")) TYPES = [ FieldType('operation_type', models.OperationType), @@ -608,7 +608,7 @@ class OperationSelect(DocumentItemSelect): class OperationFormSelection(LockForm, CustomFormSearch): SEARCH_AND_SELECT = True - form_label = _(u"Operation search") + form_label = _("Operation search") associated_models = {'pk': models.Operation} extra_form_modals = ["person", "organization"] currents = {'pk': models.Operation} @@ -622,7 +622,7 @@ class OperationFormSelection(LockForm, CustomFormSearch): class OperationFormMultiSelection(LockForm, MultiSearchForm): - form_label = _(u"Operation search") + form_label = _("Operation search") associated_models = {'pks': models.Operation} extra_form_modals = ["person", "organization"] pk_key = 'pks' @@ -642,7 +642,7 @@ class OperationCodeInput(forms.TextInput): name, value = args base_name = '-'.join(name.split('-')[:-1]) rendered = super(OperationCodeInput, self).render(*args, **kwargs) - js = u"""\n