diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-12 15:43:15 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:24 +0100 | 
| commit | 6e4f7a0390b7f49ce79f0e15e07e1d6df309f3ce (patch) | |
| tree | bb7c35ca850f60028c576ee42e3fb95db20a64be /ishtar_common/admin.py | |
| parent | 8ec062dab58750d8eb7fc0217d7adcf71d222747 (diff) | |
| download | Ishtar-6e4f7a0390b7f49ce79f0e15e07e1d6df309f3ce.tar.bz2 Ishtar-6e4f7a0390b7f49ce79f0e15e07e1d6df309f3ce.zip | |
Refactor - clean
Diffstat (limited to 'ishtar_common/admin.py')
| -rw-r--r-- | ishtar_common/admin.py | 91 | 
1 files changed, 44 insertions, 47 deletions
| diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index 75e79b714..cccc1f889 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -92,9 +92,9 @@ ISHTAR_FORMS = [common_forms, file_pdl_forms, file_forms, operation_forms,  class ImportGenericForm(forms.Form):      csv_file = forms.FileField( -        _(u"CSV file"), -        help_text=_(u"Only unicode encoding is managed - convert your" -                    u" file first") +        _("CSV file"), +        help_text=_("Only unicode encoding is managed - convert your" +                    " file first")      ) @@ -360,7 +360,7 @@ class AdminIshtarSiteProfileForm(forms.ModelForm):      class Meta:          model = models.IshtarSiteProfile          exclude = [] -    default_center = PointField(label=_(u"Maps - default center"), +    default_center = PointField(label=_("Maps - default center"),                                  widget=OSMWidget) @@ -398,8 +398,8 @@ admin_site.register(models.Organization, OrganizationAdmin)  class ProfileInline(admin.TabularInline):      model = models.UserProfile -    verbose_name = _(u"Profile") -    verbose_name_plural = _(u"Profiles") +    verbose_name = _("Profile") +    verbose_name_plural = _("Profiles")      extra = 1 @@ -570,31 +570,31 @@ class ImportActionAdmin(admin.ModelAdmin):  class ImportGeoJsonForm(forms.Form):      json_file = forms.FileField( -        _(u"Geojson file"), -        help_text=_(u"Only unicode encoding is managed - convert your" -                    u" file first. The file must be a geojson file or a zip " -                    u"containing a geojson file.") +        _("Geojson file"), +        help_text=_("Only unicode encoding is managed - convert your" +                    " file first. The file must be a geojson file or a zip " +                    "containing a geojson file.")      )      numero_insee_prefix = forms.CharField( -        label=_(u"Prefix for numero INSEE"), max_length=20, required=False) +        label=_("Prefix for numero INSEE"), max_length=20, required=False)      numero_insee_name = forms.CharField( -        label=_(u"Field name for numero INSEE"), max_length=200, +        label=_("Field name for numero INSEE"), max_length=200,          initial='numero_insee')      name_name = forms.CharField( -        label=_(u"Field name for name"), max_length=200, initial='name') -    UNIT_CHOICES = (('1', _(u"m2")), ('1000', _(u"km2"))) +        label=_("Field name for name"), max_length=200, initial='name') +    UNIT_CHOICES = (('1', _("m2")), ('1000', _("km2")))      surface_unit = forms.ChoiceField( -        label=_(u"Surface unit"), choices=UNIT_CHOICES) +        label=_("Surface unit"), choices=UNIT_CHOICES)      surface_name = forms.CharField( -        label=_(u"Field name for surface"), max_length=200, required=False) +        label=_("Field name for surface"), max_length=200, required=False)      year_name = forms.CharField( -        label=_(u"Field name for year"), max_length=200, required=False, +        label=_("Field name for year"), max_length=200, required=False,          initial="year", -        help_text=_(u"Not required for new town. Leave it empty when not " -                    u"available.") +        help_text=_("Not required for new town. Leave it empty when not " +                    "available.")      )      update = forms.BooleanField( -        label=_(u"Update only geometry of existing towns"), required=False, +        label=_("Update only geometry of existing towns"), required=False,          widget=forms.CheckboxInput      ) @@ -708,14 +708,14 @@ class ImportGEOJSONActionAdmin(object):                  if zipfile.is_zipfile(tmpfilename):                      zfile = zipfile.ZipFile(tmpfilename)                      for zmember in zfile.namelist(): -                        if os.sep in zmember or u".." in zmember: +                        if os.sep in zmember or ".." in zmember:                              continue                          if zmember.endswith("json"):                              zfile.extract(zmember, tempdir)                              json_filename = tempdir + os.sep + zmember                              break                      if not json_filename: -                        error = _(u"No json file found in zipfile") +                        error = _("No json file found in zipfile")                          return self.import_geojson_error(request, error,                                                           base_dct, tempdir)                  else: @@ -738,7 +738,7 @@ class ImportGEOJSONActionAdmin(object):                          assert 'features' in dct                          assert dct['features']                      except (ValueError, AssertionError): -                        error = _(u"Bad geojson file") +                        error = _("Bad geojson file")                          return self.import_geojson_error(                              request, error, base_dct, tempdir) @@ -748,7 +748,7 @@ class ImportGEOJSONActionAdmin(object):                      for idx, feat in enumerate(dct['features']):                          trace_error = True                          if error_count == 6: -                            self.message_user(request, _(u"Too many errors..."), +                            self.message_user(request, _("Too many errors..."),                                                level=messages.ERROR)                          if error_count > 5:                              trace_error = False @@ -859,27 +859,27 @@ class AdminRelatedTownForm(forms.ModelForm):          model = models_common.Town.children.through          exclude = []      from_town = AutoCompleteSelectField( -        'town', required=True, label=_(u"Parent")) +        'town', required=True, label=_("Parent"))  class AdminTownForm(forms.ModelForm):      class Meta:          model = models_common.Town          exclude = ['imports', 'departement'] -    center = PointField(label=_(u"Center"), required=False, +    center = PointField(label=_("Center"), required=False,                          widget=OSMWidget) -    limit = MultiPolygonField(label=_(u"Limit"), required=False, +    limit = MultiPolygonField(label=_("Limit"), required=False,                                widget=OSMWidget)      children = AutoCompleteSelectMultipleField('town', required=False, -                                               label=_(u"Town children")) +                                               label=_("Town children"))  class TownParentInline(admin.TabularInline):      model = models_common.Town.children.through      fk_name = 'to_town'      form = AdminRelatedTownForm -    verbose_name = _(u"Parent") -    verbose_name_plural = _(u"Parents") +    verbose_name = _("Parent") +    verbose_name_plural = _("Parents")      extra = 1 @@ -1059,10 +1059,7 @@ class CreateDepartmentActionAdmin(GeneralTypeAdmin):                      area = models.Area.objects.get(                          id=form.cleaned_data["area"])                  dpt_num = form.cleaned_data['department_number'] -                if dpt_num < 10: -                    dpt_num = "0" + str(dpt_num) -                else: -                    dpt_num = str(dpt_num) +                dpt_num = "0" + str(dpt_num) if dpt_num < 10 else str(dpt_num)                  current_towns = [a.numero_insee for a in area.towns.all()]                  nb = 0                  for town in models.Town.objects.filter( @@ -1190,7 +1187,7 @@ def duplicate_importertype(modeladmin, request, queryset):          old_pk = obj.pk          obj.pk = None          obj.slug = create_slug(models.ImporterType, obj.name) -        obj.name = obj.name + u" - duplicate" +        obj.name = obj.name + " - duplicate"          obj.name = obj.name[:200]          obj.save()  # create new          old_obj = modeladmin.model.objects.get(pk=old_pk) @@ -1229,7 +1226,7 @@ def duplicate_importertype(modeladmin, request, queryset):      messages.add_message(          request, messages.INFO,          str(_("{} importer type(s) duplicated: {}.")).format( -            queryset.count(), u" ; ".join(res)) +            queryset.count(), " ; ".join(res))          )      url = reverse(          'admin:%s_%s_changelist' % ( @@ -1239,7 +1236,7 @@ def duplicate_importertype(modeladmin, request, queryset):      return HttpResponseRedirect(url) -duplicate_importertype.short_description = _(u"Duplicate") +duplicate_importertype.short_description = _("Duplicate")  def generate_libreoffice_template(modeladmin, request, queryset): @@ -1313,7 +1310,7 @@ def duplicate_importercolumn(modeladmin, request, queryset):      for col in queryset.order_by('col_number'):          old_pk = col.pk          col.pk = None -        col.label = (col.label or u"") + u" - duplicate" +        col.label = (col.label or "") + " - duplicate"          col.label = col.label[:200]          # get the next available col number          col_nb = col.col_number + 1 @@ -1335,7 +1332,7 @@ def duplicate_importercolumn(modeladmin, request, queryset):      messages.add_message(          request, messages.INFO,          str(_("{} importer column(s) duplicated: {}.")).format( -            queryset.count(), u" ; ".join(res)) +            queryset.count(), " ; ".join(res))      )      url = reverse(          'admin:%s_%s_changelist' % ( @@ -1345,7 +1342,7 @@ def duplicate_importercolumn(modeladmin, request, queryset):      return HttpResponseRedirect(url) -duplicate_importercolumn.short_description = _(u"Duplicate") +duplicate_importercolumn.short_description = _("Duplicate")  def shift_right(modeladmin, request, queryset): @@ -1369,7 +1366,7 @@ def shift_right(modeladmin, request, queryset):      return HttpResponseRedirect(url) -shift_right.short_description = _(u"Shift right") +shift_right.short_description = _("Shift right")  def shift_left(modeladmin, request, queryset): @@ -1410,7 +1407,7 @@ def shift_left(modeladmin, request, queryset):      return HttpResponseRedirect(url) -shift_left.short_description = _(u"Shift left") +shift_left.short_description = _("Shift left")  class ImporterDuplicateFieldInline(admin.TabularInline): @@ -1556,8 +1553,8 @@ class JsonDataFieldAdmin(admin.ModelAdmin):      list_display = ['name', 'content_type', 'key', 'display',                      'value_type', 'search_index', 'order', 'section']      actions = [ -        change_value('display', True, _(u"Display selected")), -        change_value('display', False, _(u"Hide selected")) +        change_value('display', True, _("Display selected")), +        change_value('display', False, _("Hide selected"))      ]      list_filter = ['value_type', 'search_index']      form = JsonDataFieldForm @@ -1586,9 +1583,9 @@ class CustomFormForm(forms.ModelForm):      class Meta:          model = models.CustomForm          exclude = [] -    form = forms.ChoiceField(label=_(u"Form"), choices=get_choices_form) +    form = forms.ChoiceField(label=_("Form"), choices=get_choices_form)      users = AutoCompleteSelectMultipleField('ishtaruser', required=False, -                                            label=_(u"Users")) +                                            label=_("Users"))  class ExcludeFieldFormset(BaseInlineFormSet): @@ -1608,7 +1605,7 @@ class ExcludeFieldForm(forms.ModelForm):      class Meta:          model = models.ExcludedField          exclude = [] -    field = forms.ChoiceField(label=_(u"Field")) +    field = forms.ChoiceField(label=_("Field"))      def __init__(self, *args, **kwargs):          choices = kwargs.pop('choices') | 
