diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/__init__.py | 6 | ||||
| -rw-r--r-- | ishtar_common/admin.py | 91 | ||||
| -rw-r--r-- | ishtar_common/forms.py | 77 | ||||
| -rw-r--r-- | ishtar_common/forms_common.py | 6 | ||||
| -rw-r--r-- | ishtar_common/ishtar_menu.py | 60 | ||||
| -rw-r--r-- | ishtar_common/management/commands/fix_missing_cached_labels.py | 6 | ||||
| -rw-r--r-- | ishtar_common/management/commands/ishtar_import.py | 2 | ||||
| -rw-r--r-- | ishtar_common/management/commands/process_pending_update.py | 6 | ||||
| -rw-r--r-- | ishtar_common/management/commands/reassociate_similar_images.py | 16 | ||||
| -rw-r--r-- | ishtar_common/management/commands/regenerate_external_id.py | 4 | ||||
| -rw-r--r-- | ishtar_common/management/commands/regenerate_qrcodes.py | 6 | ||||
| -rw-r--r-- | ishtar_common/management/commands/regenerate_search_vector_cached_label.py | 6 | ||||
| -rw-r--r-- | ishtar_common/models.py | 37 | 
13 files changed, 149 insertions, 174 deletions
diff --git a/ishtar_common/__init__.py b/ishtar_common/__init__.py index 6ae20f3c8..3d19ae8ff 100644 --- a/ishtar_common/__init__.py +++ b/ishtar_common/__init__.py @@ -5,8 +5,8 @@  from django.utils.translation import ugettext_lazy as _  # overload of translation of registration module -_(u"username") -_(u"email address") -_(u"Related item") +_("username") +_("email address") +_("Related item")  default_app_config = 'ishtar_common.apps.IshtarCommonConfig' 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') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index f1e5b34ca..74590c240 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -81,7 +81,7 @@ reverse_lazy = lazy(my_reverse, str)  regexp_name = re.compile(r"^[\.,:/\w\-'\"() \&\[\]@]+$", re.UNICODE)  name_validator = validators.RegexValidator(      regexp_name, -    _(u"Enter a valid name consisting of letters, spaces and hyphens."), +    _("Enter a valid name consisting of letters, spaces and hyphens."),      'invalid') @@ -100,19 +100,19 @@ class FloatField(forms.FloatField):      Allow the use of comma for separating float fields      """      def clean(self, value): -        if value and (isinstance(value, str) or isinstance(value, str)): +        if value and isinstance(value, str):              value = value.replace(',', '.').replace('%', '')          return super(FloatField, self).clean(value)  class FinalForm(forms.Form):      final = True -    form_label = _(u"Confirm") +    form_label = _("Confirm")  class FinalDeleteForm(FinalForm):      confirm_msg = " " -    confirm_end_msg = _(u"Are you sure you want to delete?") +    confirm_end_msg = _("Are you sure you want to delete?")  def get_readonly_clean(key): @@ -151,11 +151,11 @@ class BSForm(object):                  widget.attrs['class'] = cls              # 32 bits max value              if isinstance(self.fields[k], forms.IntegerField): -                has_max = False -                for validator in self.fields[k].validators: -                    if isinstance(validator, validators.MaxValueValidator): -                        has_max = True -                        break +                has_max = any( +                    isinstance(validator, validators.MaxValueValidator) +                    for validator in self.fields[k].validators +                ) +                  if not has_max:                      self.fields[k].validators.append(                          validators.MaxValueValidator(2147483647)) @@ -249,10 +249,7 @@ class CustomForm(BSForm):          self._post_init()      def are_available(self, keys): -        for k in keys: -            if k not in self.fields: -                return False -        return True +        return all(k in self.fields for k in keys)      def remove_field(self, key):          if key in self.fields: @@ -404,13 +401,10 @@ class LockForm(object):          if not pk_key:              raise NotImplementedError("pk_key must be set")          if pk_key not in cleaned_data or not cleaned_data[pk_key]: -            raise forms.ValidationError(_(u"You should select an item.")) +            raise forms.ValidationError(_("You should select an item."))          model = self.associated_models[pk_key]          pks = self.cleaned_data[pk_key] -        if isinstance(pks, int): -            pks = [pks] -        else: -            pks = pks.split(",") +        pks = [pks] if isinstance(pks, int) else pks.split(",")          for pk in pks:              try:                  item = model.objects.get(pk=pk) @@ -464,10 +458,10 @@ class MultiSearchForm(CustomFormSearch):                  except (current_model.DoesNotExist, ValueError):                      continue          return [ -            (u"", +            ("",               mark_safe( -                 u"<ul class='compact'><li>" + u"</li><li>".join(items) + -                 u"</li></ul>" +                 "<ul class='compact'><li>" + "</li><li>".join(items) + +                 "</li></ul>"               ))          ] @@ -497,7 +491,7 @@ class FormSet(CustomForm, BaseFormSet):          if not error_msg:              error_msg = _("There are identical items.")          items = [] -        for i in range(0, self.total_form_count()): +        for i in range(self.total_form_count()):              form = self.forms[i]              if not form.is_valid():                  continue @@ -586,7 +580,7 @@ class FormHeader(object):                  "<h{level}>{label}</h{level}>{help_message}".format(                      label=self.label, level=self.level,                      help_message=help_message)) -        html = u"""<div id="collapse-parent-{slug}" class="collapse-form"> +        html = """<div id="collapse-parent-{slug}" class="collapse-form">    <div class="card">      <div class="card-header" id="collapse-head-{slug}">        <h{level} href="#"> @@ -612,7 +606,7 @@ class FormHeader(object):      def render_end(self):          if not self.collapse:              return "" -        return mark_safe(u""" +        return mark_safe("""        </div>      </div>    </div> @@ -865,10 +859,8 @@ class TableSelect(IshtarForm):              if k == 'search_vector':                  cls += " search-vector"              self.fields[k].widget.attrs['class'] = cls -            if k in alt_names: -                self.fields[k].alt_name = alt_names[k].search_key -            else: -                self.fields[k].alt_name = k +            self.fields[k].alt_name = alt_names[k].search_key \ +                if k in alt_names else k          key = list(self.fields.keys())[0]          self.fields[key].widget.attrs['autofocus'] = 'autofocus' @@ -878,13 +870,13 @@ class TableSelect(IshtarForm):  class HistorySelect(CustomForm, TableSelect):      history_creator = forms.IntegerField( -        label=_(u"Created by"), +        label=_("Created by"),          widget=widgets.JQueryAutoComplete(              reverse_lazy('autocomplete-user'),              associated_model=User), required=False      )      history_modifier = forms.IntegerField( -        label=_(u"Last modified by"), +        label=_("Last modified by"),          widget=widgets.JQueryAutoComplete(              reverse_lazy('autocomplete-user'),              associated_model=User), required=False @@ -931,13 +923,12 @@ class DocumentItemSelect(HistorySelect):  def get_now():      format = formats.get_format('DATE_INPUT_FORMATS')[0] -    value = datetime.datetime.now().strftime(format) -    return value +    return datetime.datetime.now().strftime(format)  class ClosingDateFormSelection(IshtarForm):      form_label = _("Closing date") -    end_date = DateField(label=_(u"Closing date")) +    end_date = DateField(label=_("Closing date"))      def __init__(self, *args, **kwargs):          if 'initial' not in kwargs: @@ -953,8 +944,8 @@ def has_map():  def get_form_selection(          class_name, label, key, model, base_form, get_url, -        not_selected_error=_(u"You should select an item."), new=False, -        new_message=_(u"Add a new item"), get_full_url=None, +        not_selected_error=_("You should select an item."), new=False, +        new_message=_("Add a new item"), get_full_url=None,          gallery=False, map=False, multi=False, base_form_select=None,          alt_pk_field=None      ): @@ -1120,13 +1111,13 @@ class QAForm(CustomForm, ManageOldType):                              elif int(v) in list(dct_choices.keys()):                                  values.append(str(dct_choices[int(v)]))                          self.fields[k].rendered_value = mark_safe( -                            u" ; ".join(values)) +                            " ; ".join(values))              if k not in self.REPLACE_FIELDS:                  self.fields[k].label = str(self.fields[k].label) + \ -                                       str(_(u" - append to existing")) +                                       str(_(" - append to existing"))              else:                  self.fields[k].label = str(self.fields[k].label) + \ -                                       str(_(u" - replace")) +                                       str(_(" - replace"))      def _set_value(self, item, base_key):          value = self.cleaned_data[base_key] @@ -1143,19 +1134,15 @@ class QAForm(CustomForm, ManageOldType):                  if not isinstance(v, field.related_model):                      v = field.related_model.objects.get(pk=v)                  new_value.append(v) -            if is_list: -                value = new_value -            else: -                value = new_value[0] +            value = new_value if is_list else new_value[0]          if getattr(field, 'many_to_many', None):              if type(value) not in (list, tuple):                  value = [value]              for v in value:                  getattr(item, key).add(v)          else: -            if base_key not in self.REPLACE_FIELDS: -                if getattr(item, key): -                    value = getattr(item, key) + u"\n" + value +            if base_key not in self.REPLACE_FIELDS and getattr(item, key): +                value = getattr(item, key) + "\n" + value              setattr(item, key, value)      def save(self, items, user): diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 96a473c28..7224620e0 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1872,9 +1872,9 @@ class QADocumentPackagingForm(IshtarForm):      container_to_change = forms.ChoiceField(          label=_("Change "), required=True,          choices=( -            ('current-and-reference', _(u"current and reference containers")), -            ('reference', _(u"the reference container")), -            ('current', _(u"the current container")), +            ('current-and-reference', _("current and reference containers")), +            ('reference', _("the reference container")), +            ('current', _("the current container")),          )      ) diff --git a/ishtar_common/ishtar_menu.py b/ishtar_common/ishtar_menu.py index 501177eb5..1e64a80f2 100644 --- a/ishtar_common/ishtar_menu.py +++ b/ishtar_common/ishtar_menu.py @@ -26,80 +26,80 @@ from . import models  # be careful: each access_controls must be relevant with check_rights in urls  MENU_SECTIONS = [ -    (1, SectionItem('home', _(u"Home"), childs=[])), -    (5, SectionItem('admin', _(u"Administration"), +    (1, SectionItem('home', _("Home"), childs=[])), +    (5, SectionItem('admin', _("Administration"),       childs=[          SectionItem( -            'account', _(u"Account"), -            childs=[MenuItem('account_management', _(u"Addition/modification"), +            'account', _("Account"), +            childs=[MenuItem('account_management', _("Addition/modification"),                               model=models.IshtarUser,                               access_controls=['administrator', ]), -                    MenuItem('account_deletion', _(u"Deletion"), +                    MenuItem('account_deletion', _("Deletion"),                               model=models.IshtarUser,                               access_controls=['administrator', ]), ]), -        MenuItem('admin-globalvar', _(u"Global variables"), +        MenuItem('admin-globalvar', _("Global variables"),                   model=models.GlobalVar,                   access_controls=['administrator', ]),      ])      ), -    (10, SectionItem('administration', _(u"Directory"), +    (10, SectionItem('administration', _("Directory"),       childs=[          SectionItem( -            'person', _(u"Person"), +            'person', _("Person"),              childs=[                  MenuItem( -                    'person_search', _(u"Search"), +                    'person_search', _("Search"),                      model=models.Person,                      access_controls=['add_person']),                  MenuItem( -                    'person_creation', _(u"Creation"), +                    'person_creation', _("Creation"),                      model=models.Person,                      access_controls=['add_person']),                  MenuItem( -                    'person_modification', _(u"Modification"), +                    'person_modification', _("Modification"),                      model=models.Person,                      access_controls=['change_person', 'change_own_person']),                  MenuItem( -                    'person-merge', _(u"Automatic merge"), +                    'person-merge', _("Automatic merge"),                      model=models.Person,                      access_controls=['administrator']),                  MenuItem( -                    'person-manual-merge', _(u"Manual merge"), +                    'person-manual-merge', _("Manual merge"),                      model=models.Person,                      access_controls=['administrator']),                  MenuItem( -                    'person_deletion', _(u"Deletion"), +                    'person_deletion', _("Deletion"),                      model=models.Person,                      access_controls=['change_person', 'change_own_person']),              ]),          SectionItem( -            'organization', _(u"Organization"), +            'organization', _("Organization"),              childs=[                  MenuItem( -                    'organization_search', _(u"Search"), +                    'organization_search', _("Search"),                      model=models.Organization,                      access_controls=['add_organization',                                       'add_own_organization']),                  MenuItem( -                    'organization_creation', _(u"Creation"), +                    'organization_creation', _("Creation"),                      model=models.Organization,                      access_controls=['add_organization',                                       'add_own_organization']),                  MenuItem( -                    'organization_modification', _(u"Modification"), +                    'organization_modification', _("Modification"),                      model=models.Organization,                      access_controls=['change_organization',                                       'change_own_organization']),                  MenuItem( -                    'organization-merge', _(u"Automatic merge"), +                    'organization-merge', _("Automatic merge"),                      model=models.Organization,                      access_controls=['administrator']),                  MenuItem( -                    'orga-manual-merge', _(u"Manual merge"), +                    'orga-manual-merge', _("Manual merge"),                      model=models.Organization,                      access_controls=['administrator']),                  MenuItem( -                    'organization_deletion', _(u"Deletion"), +                    'organization_deletion', _("Deletion"),                      model=models.Organization,                      access_controls=['change_organization',                                       'change_own_organization']), @@ -107,41 +107,41 @@ MENU_SECTIONS = [      ])      ),      (15, SectionItem( -        'imports', _(u"Imports"), +        'imports', _("Imports"),          childs=[              MenuItem( -                'import-new', _(u"New import"), +                'import-new', _("New import"),                  model=models.Import,                  access_controls=['change_import']),              MenuItem( -                'import-list', _(u"Current imports"), +                'import-list', _("Current imports"),                  model=models.Import,                  access_controls=['change_import']),              MenuItem( -                'import-list-old', _(u"Old imports"), +                'import-list-old', _("Old imports"),                  model=models.Import,                  access_controls=['change_import']),          ])),      (250, SectionItem( -        'document', _(u"Documentation / Images"), +        'document', _("Documentation / Images"),          childs=[              MenuItem('document/search', -                     _(u"Search"), +                     _("Search"),                       model=models.Document,                       access_controls=['view_document',                                        'view_own_document']),              MenuItem('document/create', -                     _(u"Creation"), +                     _("Creation"),                       model=models.Document,                       access_controls=['add_document',                                        'add_own_document']),              MenuItem('document/edit', -                     _(u"Modification"), +                     _("Modification"),                       model=models.Document,                       access_controls=['change_document',                                        'change_own_document']),              MenuItem('document/delete', -                     _(u"Deletion"), +                     _("Deletion"),                       model=models.Document,                       access_controls=['change_document',                                        'change_own_document']), diff --git a/ishtar_common/management/commands/fix_missing_cached_labels.py b/ishtar_common/management/commands/fix_missing_cached_labels.py index 368d98fae..ad2767c56 100644 --- a/ishtar_common/management/commands/fix_missing_cached_labels.py +++ b/ishtar_common/management/commands/fix_missing_cached_labels.py @@ -52,7 +52,7 @@ class Command(BaseCommand):              if limit and app != limit:                  continue              if not quiet: -                print(u"* app: {}".format(app)) +                print("* app: {}".format(app))              for model in apps.get_app_config(app).get_models():                  if model_name and model.__name__.lower() != model_name:                      continue @@ -79,14 +79,14 @@ class Command(BaseCommand):                      else:                          query |= subquery                  q = model.objects.filter(query) -                msg = u"-> processing {}: ".format(model._meta.verbose_name) +                msg = "-> processing {}: ".format(model._meta.verbose_name)                  ln = q.count()                  for idx, obj_id in enumerate(q.values('pk').all()):                      obj = model.objects.get(pk=obj_id['pk'])                      obj.skip_history_when_saving = True                      obj._no_move = True                      obj._no_geo_check = True -                    cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln) +                    cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)                      if not quiet:                          sys.stdout.write(cmsg)                          sys.stdout.flush() diff --git a/ishtar_common/management/commands/ishtar_import.py b/ishtar_common/management/commands/ishtar_import.py index a8c9d3736..011af2f8c 100644 --- a/ishtar_common/management/commands/ishtar_import.py +++ b/ishtar_common/management/commands/ishtar_import.py @@ -31,7 +31,7 @@ class Command(BaseCommand):                  "|        name\n")              self.stdout.write("*" * 80 + "\n")              for imp in models.Import.objects.exclude(state="AC").all(): -                self.stdout.write(u"|{: ^6}| {: ^32} | {: ^12} | {}\n".format( +                self.stdout.write("|{: ^6}| {: ^32} | {: ^12} | {}\n".format(                      imp.pk, str(imp.importer_type)[:32],                      state[imp.state][:12],                      imp.name[:128])) diff --git a/ishtar_common/management/commands/process_pending_update.py b/ishtar_common/management/commands/process_pending_update.py index 6e97847cc..6feff38c3 100644 --- a/ishtar_common/management/commands/process_pending_update.py +++ b/ishtar_common/management/commands/process_pending_update.py @@ -42,7 +42,7 @@ class Command(BaseCommand):          quiet = options['quiet']          for app in APPS:              if not quiet: -                print(u"* app: {}".format(app)) +                print("* app: {}".format(app))              for model in apps.get_app_config(app).get_models():                  if model.__name__.startswith('Historical'):                      continue @@ -50,14 +50,14 @@ class Command(BaseCommand):                          [True for k in model._meta.get_fields()                           if k.name == "need_update"]):                      continue -                msg = u"-> processing {}: ".format(model._meta.verbose_name) +                msg = "-> processing {}: ".format(model._meta.verbose_name)                  q = model.objects.filter(need_update=True)                  ln = q.count()                  for idx, obj_id in enumerate(q.values('pk').all()):                      obj = model.objects.get(pk=obj_id['pk'])                      obj.skip_history_when_saving = True                      obj._no_move = True -                    cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln) +                    cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)                      if not quiet:                          sys.stdout.write(cmsg)                          sys.stdout.flush() diff --git a/ishtar_common/management/commands/reassociate_similar_images.py b/ishtar_common/management/commands/reassociate_similar_images.py index 0dbb3a765..9e52bc6f6 100644 --- a/ishtar_common/management/commands/reassociate_similar_images.py +++ b/ishtar_common/management/commands/reassociate_similar_images.py @@ -127,9 +127,9 @@ class Command(BaseCommand):                  for attr in attributes:                      ref_value = getattr(ref_item, attr)                      other_value = getattr(item, attr) +                    if not other_value: +                        continue                      if ref_value: -                        if not other_value: -                            continue                          if other_value != ref_value:                              if attr == 'title' and merged_title:                                  setattr(ref_item, 'title', merged_title) @@ -138,8 +138,6 @@ class Command(BaseCommand):                                      (attr, ref_value, other_value)                                  )                      else: -                        if not other_value: -                            continue                          setattr(ref_item, attr, other_value)                  base_csv = [ @@ -184,11 +182,11 @@ class Command(BaseCommand):                  item.delete()                  nb_merged_items += 1          if not quiet: -            out.write(u"\n") +            out.write("\n")          n = datetime.datetime.now().isoformat().split('.')[0].replace(':', '-')          if conflicts: -            filename = output_path + u"{}-conflict.csv".format(n) +            filename = output_path + "{}-conflict.csv".format(n)              with open(filename, 'w') as csvfile:                  writer = csv.writer(csvfile)                  writer.writerow( @@ -202,10 +200,10 @@ class Command(BaseCommand):                  for conflict in conflicts:                      writer.writerow(conflict)              if not quiet: -                out.write(u"* {} conflicted items ({})\n".format( +                out.write("* {} conflicted items ({})\n".format(                      nb_conflicted_items, filename))          if merged: -            filename = output_path + u"{}-merged.csv".format(n) +            filename = output_path + "{}-merged.csv".format(n)              with open(filename, 'w') as csvfile:                  writer = csv.writer(csvfile)                  writer.writerow( @@ -218,7 +216,7 @@ class Command(BaseCommand):                  for merge in merged:                      writer.writerow(merge)              if not quiet: -                out.write(u"* {} merged items ({})\n".format(nb_merged_items, +                out.write("* {} merged items ({})\n".format(nb_merged_items,                                                              filename))          if not quiet:              out.write("* {} distinct images\n".format(distinct_image)) diff --git a/ishtar_common/management/commands/regenerate_external_id.py b/ishtar_common/management/commands/regenerate_external_id.py index b64629386..5d1aad88e 100644 --- a/ishtar_common/management/commands/regenerate_external_id.py +++ b/ishtar_common/management/commands/regenerate_external_id.py @@ -51,14 +51,14 @@ class Command(BaseCommand):                      if not bool(                              [k for k in dir(model) if k == "external_id"]):                          continue -                    msg = u"* processing {} - {}:".format( +                    msg = "* processing {} - {}:".format(                          app, model._meta.verbose_name)                      ln = model.objects.count()                      for idx, object in enumerate(model.objects.all()):                          object.skip_history_when_saving = True                          object.external_id = None                          object._no_move = True -                        cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln) +                        cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)                          sys.stdout.write(cmsg)                          sys.stdout.flush()                          object.save() diff --git a/ishtar_common/management/commands/regenerate_qrcodes.py b/ishtar_common/management/commands/regenerate_qrcodes.py index 6c1ed8ecc..d915d2e21 100644 --- a/ishtar_common/management/commands/regenerate_qrcodes.py +++ b/ishtar_common/management/commands/regenerate_qrcodes.py @@ -54,7 +54,7 @@ class Command(BaseCommand):          for app in APPS:              if limit and app != limit:                  continue -            print(u"* app: {}".format(app)) +            print("* app: {}".format(app))              for model in apps.get_app_config(app).get_models():                  if model_name and model.__name__.lower() != model_name:                      continue @@ -64,13 +64,13 @@ class Command(BaseCommand):                      model._meta.get_field('qrcode')                  except FieldDoesNotExist:                      continue -                msg = u"-> processing {}: ".format(model._meta.verbose_name) +                msg = "-> processing {}: ".format(model._meta.verbose_name)                  ln = model.objects.count()                  tmpdir = tempfile.mkdtemp("-qrcode")                  for idx, object in enumerate(model.objects.all()):                      object.skip_history_when_saving = True                      object._no_move = True -                    cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln) +                    cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)                      sys.stdout.write(cmsg)                      sys.stdout.flush()                      object.generate_qrcode(secure=secure, tmpdir=tmpdir) diff --git a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py b/ishtar_common/management/commands/regenerate_search_vector_cached_label.py index 6a560df80..ab7f134ff 100644 --- a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py +++ b/ishtar_common/management/commands/regenerate_search_vector_cached_label.py @@ -51,7 +51,7 @@ class Command(BaseCommand):              if limit and app != limit:                  continue              if not quiet: -                print(u"* app: {}".format(app)) +                print("* app: {}".format(app))              for model in apps.get_app_config(app).get_models():                  if model_name and model.__name__.lower() != model_name:                      continue @@ -62,7 +62,7 @@ class Command(BaseCommand):                           if k.startswith('_generate_') or                              k == "search_vector"]):                      continue -                msg = u"-> processing {}: ".format(model._meta.verbose_name) +                msg = "-> processing {}: ".format(model._meta.verbose_name)                  ln = model.objects.count()                  for idx, obj_id in enumerate(model.objects.values('pk').all()):                      obj = model.objects.get(pk=obj_id['pk']) @@ -74,7 +74,7 @@ class Command(BaseCommand):                          obj.point_2d = None                          obj.x = None                          obj.y = None -                    cmsg = u"\r{} {}/{}".format(msg, idx + 1, ln) +                    cmsg = "\r{} {}/{}".format(msg, idx + 1, ln)                      if not quiet:                          sys.stdout.write(cmsg)                          sys.stdout.flush() diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 79fa8f6c0..bf8c8c19c 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -197,7 +197,7 @@ class ValueGetter(object):                  val = ''              elif (key in self.GET_VALUES_EXTRA_TYPES or "type" in key) and (                    val.__class__.__name__.split('.')[0] == 'ManyRelatedManager'): -                val = " ; ".join([str(v) for v in val.all()]) +                val = " ; ".join(str(v) for v in val.all())              elif not isinstance(val, (tuple, list, dict)):                  val = str(val)                  if val.endswith('.None'): @@ -219,10 +219,7 @@ class ValueGetter(object):      def get_empty_values(cls, prefix=''):          if not prefix:              prefix = cls._prefix -        values = {} -        for field_name in get_all_field_names(cls): -            values[prefix + field_name] = '' -        return values +        return {prefix + field_name: '' for field_name in get_all_field_names(cls)}  class HistoryModel(models.Model): @@ -296,7 +293,7 @@ class TinyUrl(models.Model):      @classmethod      def index_to_char(cls, seq): -        return "".join([cls.CHAR_MAP[x] for x in seq]) +        return "".join(cls.CHAR_MAP[x] for x in seq)      def get_short_id(self):          c_id = self.id @@ -348,7 +345,7 @@ class ImageModel(models.Model, ImageContainerModel):              return True          manager = getattr(self.__class__, 'objects')          old = getattr(manager.get(pk=self.pk), field) -        return not getattr(self, field) == old +        return getattr(self, field) != old      def create_thumb(self, image, size):          """Returns the image resized to fit inside a box of the given size""" @@ -2211,13 +2208,13 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):      @property      def person_types_list(self): -        return ", ".join([str(pt) for pt in self.person_types.all()]) +        return ", ".join(str(pt) for pt in self.person_types.all())      profiles_list_lbl = _("Profiles")      @property      def profiles_list(self): -        return ", ".join([str(p) for p in self.profiles.all()]) +        return ", ".join(str(p) for p in self.profiles.all())      def generate_merge_key(self):          if self.name and self.name.strip(): @@ -2389,8 +2386,7 @@ class UserProfile(models.Model):          lbl = self.name or str(self.profile_type)          if not self.areas.count():              return lbl -        return "{} ({})".format(lbl, ", ".join( -            [str(area) for area in self.areas.all()])) +        return "{} ({})".format(lbl, ", ".join(str(area) for area in self.areas.all()))      @property      def query_towns(self): @@ -2403,7 +2399,7 @@ class UserProfile(models.Model):      @property      def area_labels(self): -        return ", ".join([str(area) for area in self.areas.all()]) +        return ", ".join(str(area) for area in self.areas.all())      def duplicate(self, **kwargs):          areas = [area for area in self.areas.all()] @@ -2574,8 +2570,7 @@ class IshtarUser(FullSearch):          person = Person.objects.create(surname=surname,                                         name=name, email=email,                                         history_modifier=user) -        isht_user = cls.objects.create(user_ptr=user, person=person) -        return isht_user +        return cls.objects.create(user_ptr=user, person=person)      def has_right(self, right_name, session=None):          return self.person.has_right(right_name, session=session) @@ -2685,13 +2680,11 @@ class Basket(FullSearch, OwnPerms, ValueGetter, TemplateItem):          :param ishtaruser: if provided an alternate user is used          :return: the new basket          """ -        items = []          through = self.items.through          basket_pk = "{}_id".format(self.SLUG)          item_pk = "{}_id".format(self.items.model.SLUG)          q = through.objects.filter(**{basket_pk: self.pk}) -        for r in q.values("pk", item_pk).order_by("pk").all(): -            items.append(r[item_pk]) +        items = [r[item_pk] for r in q.values("pk", item_pk).order_by("pk").all()]          new_item = self          new_item.pk = None          if ishtaruser: @@ -3693,7 +3686,7 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel,                      "content": self.creation_date.strftime("%Y-%m-%d")}              tags.append(("meta", date))          if self.tags.count(): -            content = ", ".join([str(t) for t in self.tags.all()]) +            content = ", ".join(str(t) for t in self.tags.all())              tg = {"name": "DC.subject", "content": content}              tags.append(("meta", tg))          if self.description: @@ -3705,8 +3698,8 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel,                  ("meta", {"name": "DC.publisher",                            "content": self.publisher.name}))          if self.authors.count(): -            content = ", ".join([str(t.person.raw_name) for t in -                                 self.authors.all()]) +            content = ", ".join(str(t.person.raw_name) for t in +                                         self.authors.all())              tags.append(                  ("meta", {"name": "DC.creator",                            "content": content})) @@ -3729,7 +3722,7 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel,                  ("meta", {"name": "DC.language",                            "content": lang}))          if self.licenses.count(): -            licences = ", ".join([str(l) for l in self.licenses.all()]) +            licences = ", ".join(str(l) for l in self.licenses.all())              tags.append(                  ("meta", {"name": "DC.rights",                            "content": licences})) @@ -3806,7 +3799,7 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel,          if self.isbn:              info.append(("rft.isbn", self.isbn))          if self.licenses.count(): -            licenses = ";".join([str(l) for l in self.licenses.all()]) +            licenses = ";".join(str(l) for l in self.licenses.all())              info.append(("rft.rights", licenses))          if self.language:              info.append(("rft.language", self.language.iso_code))  | 
