diff options
| -rw-r--r-- | ishtar_common/forms.py | 1 | ||||
| -rw-r--r-- | ishtar_common/models.py | 306 | 
2 files changed, 77 insertions, 230 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index bc74001dc..2b6854b4a 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -683,7 +683,6 @@ class IshtarForm(forms.Form, BSForm):              for field_name, permissions, options in self.OPTIONS_PERMISSIONS:                  if field_name not in self.fields:                      continue -                  if not any(                      True                      for permission in permissions diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 66ecb8b29..72b2ff9cb 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -248,9 +248,7 @@ class ValueGetter(object):              and self.main_image              and hasattr(self.main_image, "get_values")          ): -            values[prefix + "main_image"] = self.main_image.get_values( -                no_values=True -            ) +            values[prefix + "main_image"] = self.main_image.get_values(no_values=True)          return values      def _get_values_update_sub_filter(self, filtr, prefix): @@ -285,9 +283,7 @@ class ValueGetter(object):                  continue              if hasattr(value, "get_values"):                  new_prefix = prefix + field_name + "_" -                values.update( -                    value.get_values(new_prefix, filtr=filtr, **kwargs) -                ) +                values.update(value.get_values(new_prefix, filtr=filtr, **kwargs))              if hasattr(self, "get_values_for_" + field_name):                  values[prefix + field_name] = getattr(                      self, "get_values_for_" + field_name @@ -325,9 +321,7 @@ class ValueGetter(object):      def get_empty_values(cls, prefix=""):          if not prefix:              prefix = cls._prefix -        return { -            prefix + field_name: "" for field_name in get_all_field_names(cls) -        } +        return {prefix + field_name: "" for field_name in get_all_field_names(cls)}  class HistoryModel(models.Model): @@ -343,9 +337,7 @@ class HistoryModel(models.Model):          models = import_module(models)          model = getattr(models, self.__class__.__name__[len("Historical") :])          related_model = getattr(model, key).rel.model -        return related_model.history_decompress( -            self.history_m2m[key], create=create -        ) +        return related_model.history_decompress(self.history_m2m[key], create=create)  def valid_id(cls): @@ -708,9 +700,7 @@ class JsonDataField(models.Model):          _("Type"), default="T", max_length=10, choices=JSON_VALUE_TYPES      )      order = models.IntegerField(_("Order"), default=10) -    search_index = models.BooleanField( -        _("Use in search indexes"), default=False -    ) +    search_index = models.BooleanField(_("Use in search indexes"), default=False)      section = models.ForeignKey(          JsonDataSection, blank=True, null=True, on_delete=models.SET_NULL      ) @@ -752,9 +742,7 @@ LOGICAL_TYPES = (  class GeneralRelationType(GeneralType):      order = models.IntegerField(_("Order"), default=1)      symmetrical = models.BooleanField(_("Symmetrical")) -    tiny_label = models.CharField( -        _("Tiny label"), max_length=50, blank=True, null=True -    ) +    tiny_label = models.CharField(_("Tiny label"), max_length=50, blank=True, null=True)      inverse_relation = models.ForeignKey(          "self", verbose_name=_("Inverse relation"), blank=True, null=True      ) @@ -772,9 +760,7 @@ class GeneralRelationType(GeneralType):      def clean(self):          # cannot have symmetrical and an inverse_relation          if self.symmetrical and self.inverse_relation: -            raise ValidationError( -                _("Cannot have symmetrical and an inverse_relation") -            ) +            raise ValidationError(_("Cannot have symmetrical and an inverse_relation"))      def get_tiny_label(self):          return self.tiny_label or self.label or "" @@ -842,9 +828,7 @@ def post_delete_record_relation(sender, instance, **kwargs):  class SearchQuery(models.Model):      label = models.TextField(_("Label"), blank=True, default="")      query = models.TextField(_("Query"), blank=True, default="") -    content_type = models.ForeignKey( -        ContentType, verbose_name=_("Content type") -    ) +    content_type = models.ForeignKey(ContentType, verbose_name=_("Content type"))      profile = models.ForeignKey("UserProfile", verbose_name=_("Profile"))      is_alert = models.BooleanField(_("Is an alert"), default=False) @@ -858,9 +842,7 @@ class SearchQuery(models.Model):  class Language(GeneralType): -    iso_code = models.CharField( -        _("ISO code"), null=True, blank=True, max_length=2 -    ) +    iso_code = models.CharField(_("ISO code"), null=True, blank=True, max_length=2)      class Meta:          verbose_name = _("Language") @@ -878,9 +860,7 @@ TRANSLATED_SITE_LABELS = {          "modification": _("Site modification"),          "deletion": _("Site deletion"),          "attached-to-operation": _("Site (attached to the operation)"), -        "name-attached-to-operation": _( -            "Site name (attached to the operation)" -        ), +        "name-attached-to-operation": _("Site name (attached to the operation)"),          "attached-to-cr": _("Site (attached to the context record)"),          "name-attached-to-cr": _("Site name (attached to the context record)"),      }, @@ -920,9 +900,7 @@ class IshtarSiteProfile(models.Model, Cached):      )      description = models.TextField(_("Description"), blank=True, default="")      warning_name = models.TextField(_("Warning name"), blank=True, default="") -    warning_message = models.TextField( -        _("Warning message"), blank=True, default="" -    ) +    warning_message = models.TextField(_("Warning message"), blank=True, default="")      delete_image_zip_on_archive = models.BooleanField(          _("Import - Delete image/document zip on archive"), default=False      ) @@ -944,9 +922,7 @@ class IshtarSiteProfile(models.Model, Cached):          _("Alternate configuration"),          max_length=200,          choices=ALTERNATE_CONFIGS_CHOICES, -        help_text=_( -            "Choose an alternate configuration for label, " "index management" -        ), +        help_text=_("Choose an alternate configuration for label, " "index management"),          null=True,          blank=True,      ) @@ -960,9 +936,7 @@ class IshtarSiteProfile(models.Model, Cached):          choices=SITE_LABELS,          default="site",      ) -    context_record = models.BooleanField( -        _("Context records module"), default=False -    ) +    context_record = models.BooleanField(_("Context records module"), default=False)      find = models.BooleanField(          _("Finds module"),          default=False, @@ -1004,9 +978,7 @@ class IshtarSiteProfile(models.Model, Cached):      use_town_for_geo = models.BooleanField(          _("Use town to locate when coordinates are missing"), default=True      ) -    relation_graph = models.BooleanField( -        _("Generate relation graph"), default=False -    ) +    relation_graph = models.BooleanField(_("Generate relation graph"), default=False)      underwater = models.BooleanField(_("Underwater module"), default=False)      parcel_mandatory = models.BooleanField(          _("Parcel are mandatory for context records"), default=True @@ -1057,9 +1029,7 @@ class IshtarSiteProfile(models.Model, Cached):          _("Archaeological site complete identifier"),          default="",          blank=True, -        help_text=_( -            "Formula to manage archaeological site complete" " identifier." -        ), +        help_text=_("Formula to manage archaeological site complete" " identifier."),      )      site_custom_index = models.TextField(          _("Archaeological site custom index key"), @@ -1084,9 +1054,7 @@ class IshtarSiteProfile(models.Model, Cached):          _("Archaeological file complete identifier"),          default="",          blank=True, -        help_text=_( -            "Formula to manage archaeological file complete " "identifier." -        ), +        help_text=_("Formula to manage archaeological file complete " "identifier."),      )      file_custom_index = models.TextField(          _("Archaeological file custom index key"), @@ -1268,9 +1236,7 @@ class IshtarSiteProfile(models.Model, Cached):              "data can be destructive."          ),      ) -    find_use_index = models.BooleanField( -        _("Use auto index for finds"), default=True -    ) +    find_use_index = models.BooleanField(_("Use auto index for finds"), default=True)      currency = models.CharField(          _("Currency"), default="€", choices=CURRENCY, max_length=5      ) @@ -1290,8 +1256,7 @@ class IshtarSiteProfile(models.Model, Cached):          blank=True,          null=True,          help_text=_( -            "Spatial Reference System used for display when no SRS is " -            "defined" +            "Spatial Reference System used for display when no SRS is " "defined"          ),      )      default_language = models.ForeignKey( @@ -1518,9 +1483,7 @@ class CustomForm(models.Model):              if not q.count():                  continue              ct = q.all()[0] -            for json_field in JsonDataField.objects.filter( -                content_type=ct -            ).all(): +            for json_field in JsonDataField.objects.filter(content_type=ct).all():                  res.append(                      (                          json_field.pk, @@ -1576,9 +1539,7 @@ class CustomFormJsonFieldManager(models.Manager):  class CustomFormJsonField(models.Model):      custom_form = models.ForeignKey(CustomForm, related_name="json_fields") -    json_field = models.ForeignKey( -        JsonDataField, related_name="custom_form_details" -    ) +    json_field = models.ForeignKey(JsonDataField, related_name="custom_form_details")      label = models.CharField(_("Label"), max_length=200, blank=True, default="")      order = models.IntegerField(verbose_name=_("Order"), default=1)      help_text = models.TextField(_("Help"), blank=True, default="") @@ -1635,9 +1596,7 @@ class UserDashboard:          types = IshtarUser.objects.values(              "person__person_types", "person__person_types__label"          ) -        self.types = types.annotate(number=Count("pk")).order_by( -            "person__person_types" -        ) +        self.types = types.annotate(number=Count("pk")).order_by("person__person_types")  class StatsCache(models.Model): @@ -1675,9 +1634,7 @@ class Dashboard(object):              if self.model == Find:                  last_ids = last_ids.filter(downstream_treatment_id__isnull=True)                  if modif_type == "+": -                    last_ids = last_ids.filter( -                        upstream_treatment_id__isnull=True -                    ) +                    last_ids = last_ids.filter(upstream_treatment_id__isnull=True)              last_ids = last_ids.order_by("-hd").distinct().all()[:5]              for idx in last_ids:                  try: @@ -1704,17 +1661,13 @@ class Dashboard(object):          if slice == "year":              self.values = [("year", "", list(reversed(self.periods)))]              self.numbers = [ -                model.get_by_year(year, **kwargs_num).count() -                for year in self.periods -            ] -            self.values += [ -                ("number", _("Number"), list(reversed(self.numbers))) +                model.get_by_year(year, **kwargs_num).count() for year in self.periods              ] +            self.values += [("number", _("Number"), list(reversed(self.numbers)))]          if slice == "month":              periods = list(reversed(self.periods))              self.periods = [ -                "%d-%s-01" -                % (p[0], ("0" + str(p[1])) if len(str(p[1])) == 1 else p[1]) +                "%d-%s-01" % (p[0], ("0" + str(p[1])) if len(str(p[1])) == 1 else p[1])                  for p in periods              ]              self.values = [("month", "", self.periods)] @@ -1722,13 +1675,9 @@ class Dashboard(object):                  for dpt, lbl in settings.ISHTAR_DPTS:                      self.serie_labels.append(str(dpt))                      idx = "number_" + str(dpt) -                    kwargs_num["fltr"]["towns__numero_insee__startswith"] = str( -                        dpt -                    ) +                    kwargs_num["fltr"]["towns__numero_insee__startswith"] = str(dpt)                      numbers = [ -                        model.get_by_month( -                            *p.split("-")[:2], **kwargs_num -                        ).count() +                        model.get_by_month(*p.split("-")[:2], **kwargs_num).count()                          for p in self.periods                      ]                      self.values += [(idx, dpt, list(numbers))] @@ -1750,9 +1699,7 @@ class Dashboard(object):          if not hasattr(model, "get_by_operation"):              return          operations = model.get_operations() -        operation_numbers = [ -            model.get_by_operation(op).count() for op in operations -        ] +        operation_numbers = [model.get_by_operation(op).count() for op in operations]          # calculate          self.operation_average = self.get_average(operation_numbers)          self.operation_variance = self.get_variance(operation_numbers) @@ -1760,15 +1707,11 @@ class Dashboard(object):              operation_numbers          )          self.operation_median = self.get_median(operation_numbers) -        operation_mode_pk = self.get_mode( -            dict(zip(operations, operation_numbers)) -        ) +        operation_mode_pk = self.get_mode(dict(zip(operations, operation_numbers)))          if operation_mode_pk:              from archaeological_operations.models import Operation -            self.operation_mode = str( -                Operation.objects.get(pk=operation_mode_pk) -            ) +            self.operation_mode = str(Operation.objects.get(pk=operation_mode_pk))      def get_average(self, vals=None):          if not vals: @@ -1861,10 +1804,7 @@ class DocumentTemplate(models.Model):      def clean(self):          if self.for_labels and not self.label_per_page:              raise ValidationError( -                _( -                    "For label template, you must provide " -                    "number of label per page." -                ) +                _("For label template, you must provide " "number of label per page.")              )      def generate_label_template(self): @@ -1945,11 +1885,7 @@ class DocumentTemplate(models.Model):          if not self.slug:              self.slug = create_slug(DocumentTemplate, self.name)          super(DocumentTemplate, self).save(*args, **kwargs) -        if ( -            self.label_template.name -            and self.label_targets -            and not self.template -        ): +        if self.label_template.name and self.label_targets and not self.template:              self.generate_label_template()      @classmethod @@ -2011,9 +1947,7 @@ class DocumentTemplate(models.Model):          for fil in filtr:              if not fil:                  continue -            new_filter += [ -                f for f in fil.split(" ") if f and f not in OPERATORS -            ] +            new_filter += [f for f in fil.split(" ") if f and f not in OPERATORS]          filtr = new_filter          new_filter = []          for fil in filtr: @@ -2145,9 +2079,7 @@ class Area(HierarchicalType):      towns = models.ManyToManyField(          Town, verbose_name=_("Towns"), blank=True, related_name="areas"      ) -    reference = models.CharField( -        _("Reference"), max_length=200, blank=True, null=True -    ) +    reference = models.CharField(_("Reference"), max_length=200, blank=True, null=True)      parent = models.ForeignKey(          "self",          blank=True, @@ -2255,9 +2187,7 @@ organization_type_pk_lazy = lazy(OrganizationType.get_or_create_pk, str)  organization_type_pks_lazy = lazy(OrganizationType.get_or_create_pks, str) -class Organization( -    Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, MainItem -): +class Organization(Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, MainItem):      TABLE_COLS = ("name", "organization_type", "town")      SLUG = "organization"      SHOW_URL = "show-organization" @@ -2294,9 +2224,7 @@ class Organization(      # fields      uuid = models.UUIDField(default=uuid.uuid4)      name = models.CharField(_("Name"), max_length=500) -    organization_type = models.ForeignKey( -        OrganizationType, verbose_name=_("Type") -    ) +    organization_type = models.ForeignKey(OrganizationType, verbose_name=_("Type"))      url = models.URLField(verbose_name=_("Web address"), blank=True, null=True)      grammatical_gender = models.CharField(          _("Grammatical gender"), @@ -2341,9 +2269,7 @@ class Organization(          if self.name:              return self.name          attrs = ["organization_type", "address", "town"] -        items = [ -            str(getattr(self, attr)) for attr in attrs if getattr(self, attr) -        ] +        items = [str(getattr(self, attr)) for attr in attrs if getattr(self, attr)]          if not items:              items = [str(_("unknown organization"))]          return " - ".join(items) @@ -2586,9 +2512,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):          ),      )      name = models.CharField(_("Name"), max_length=200, blank=True, null=True) -    raw_name = models.CharField( -        _("Raw name"), max_length=300, blank=True, null=True -    ) +    raw_name = models.CharField(_("Raw name"), max_length=300, blank=True, null=True)      contact_type = models.CharField(          _("Contact type"), max_length=300, blank=True, null=True      ) @@ -2659,9 +2583,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):          if not orga_address:              return []          items.append( -            """<span class="organization">{}</span>""".format( -                self.attached_to.name -            ) +            """<span class="organization">{}</span>""".format(self.attached_to.name)          )          items += orga_address          return items @@ -2711,9 +2633,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):              prefix=prefix, no_values=no_values, filtr=filtr, **kwargs          )          if not self.attached_to: -            values.update( -                Person.get_empty_values(prefix=prefix + "attached_to_") -            ) +            values.update(Person.get_empty_values(prefix=prefix + "attached_to_"))          return values      person_types_list_lbl = _("Types") @@ -2849,9 +2769,7 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):          )      def find_docs_q(self): -        return Document.objects.filter( -            authors__person=self, finds__pk__isnull=False -        ) +        return Document.objects.filter(authors__person=self, finds__pk__isnull=False)      def save(self, *args, **kwargs):          super(Person, self).save(*args, **kwargs) @@ -2869,12 +2787,8 @@ class Person(Address, Merge, OwnPerms, ValueGetter, MainItem):      @classmethod      def get_query_owns(cls, ishtaruser):          return ( -            Q( -                operation_scientist_responsability__collaborators__ishtaruser=ishtaruser -            ) -            | Q( -                operation_scientist_responsability__scientist__ishtaruser=ishtaruser -            ) +            Q(operation_scientist_responsability__collaborators__ishtaruser=ishtaruser) +            | Q(operation_scientist_responsability__scientist__ishtaruser=ishtaruser)              | Q(operation_collaborator__collaborators__ishtaruser=ishtaruser)              | Q(operation_collaborator__scientist__ishtaruser=ishtaruser)          ) @@ -2905,16 +2819,12 @@ class ProfileTypeSummary(ProfileType):  class UserProfile(models.Model):      name = models.CharField(_("Name"), blank=True, default="", max_length=100) -    profile_type = models.ForeignKey( -        ProfileType, verbose_name=_("Profile type") -    ) +    profile_type = models.ForeignKey(ProfileType, verbose_name=_("Profile type"))      areas = models.ManyToManyField(          "Area", verbose_name=_("Areas"), blank=True, related_name="profiles"      )      current = models.BooleanField(_("Current profile"), default=False) -    show_field_number = models.BooleanField( -        _("Show field number"), default=False -    ) +    show_field_number = models.BooleanField(_("Show field number"), default=False)      auto_pin = models.BooleanField(_("Automatically pin"), default=False)      display_pin_menu = models.BooleanField(_("Display pin menu"), default=False)      person = models.ForeignKey( @@ -2930,9 +2840,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): @@ -2984,9 +2892,9 @@ class UserProfile(models.Model):          # only one current profile per user          if not self.current:              return -        q = UserProfile.objects.filter( -            person=self.person, current=True -        ).exclude(pk=self.pk) +        q = UserProfile.objects.filter(person=self.person, current=True).exclude( +            pk=self.pk +        )          if not q.count():              return          for p in q.all(): @@ -3029,9 +2937,7 @@ class IshtarUser(FullSearch):      CACHED_LABELS = []  # needed to force search vector update      # search parameters -    EXTRA_REQUEST_KEYS = { -        "person__person_types_list": "person__person_types__label" -    } +    EXTRA_REQUEST_KEYS = {"person__person_types_list": "person__person_types__label"}      COL_LABELS = {          "person__attached_to__name": _("Organization"), @@ -3066,9 +2972,7 @@ class IshtarUser(FullSearch):      }      # fields -    user_ptr = models.OneToOneField( -        User, primary_key=True, related_name="ishtaruser" -    ) +    user_ptr = models.OneToOneField(User, primary_key=True, related_name="ishtaruser")      person = models.OneToOneField(          Person, verbose_name=_("Person"), related_name="ishtaruser"      ) @@ -3115,13 +3019,9 @@ class IshtarUser(FullSearch):              return          ishtaruser = q.all()[0]          person = ishtaruser.person -        admin, created = ProfileType.objects.get_or_create( -            txt_idx="administrator" -        ) +        admin, created = ProfileType.objects.get_or_create(txt_idx="administrator")          if user.is_superuser: -            if UserProfile.objects.filter( -                profile_type=admin, person=person -            ).count(): +            if UserProfile.objects.filter(profile_type=admin, person=person).count():                  return              UserProfile.objects.get_or_create(                  profile_type=admin, person=person, defaults={"current": True} @@ -3259,18 +3159,14 @@ class Basket(FullSearch, OwnPerms, ValueGetter, TemplateItem):          basket_pk = "{}_id".format(self.SLUG)          item_pk = "{}_id".format(self.items.model.SLUG)          q = through.objects.filter(**{basket_pk: self.pk}) -        items = [ -            r[item_pk] for r in q.values("pk", item_pk).order_by("pk").all() -        ] +        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:              new_item.user = ishtaruser          if not label:              label = new_item.label -        while self.__class__.objects.filter( -            label=label, user=new_item.user -        ).count(): +        while self.__class__.objects.filter(label=label, user=new_item.user).count():              label += str(_(" - duplicate"))          new_item.label = label          new_item.save() @@ -3297,9 +3193,7 @@ class Author(FullSearch):      PARENT_SEARCH_VECTORS = ["person"]      uuid = models.UUIDField(default=uuid.uuid4) -    person = models.ForeignKey( -        Person, verbose_name=_("Person"), related_name="author" -    ) +    person = models.ForeignKey(Person, verbose_name=_("Person"), related_name="author")      author_type = models.ForeignKey(AuthorType, verbose_name=_("Author type"))      cached_label = models.TextField(          _("Cached name"), blank=True, default="", db_index=True @@ -3350,9 +3244,7 @@ def author_post_save(sender, **kwargs):          return      cached_label_changed(sender, **kwargs)      instance = kwargs.get("instance") -    q = Author.objects.filter( -        person=instance.person, author_type=instance.author_type -    ) +    q = Author.objects.filter(person=instance.person, author_type=instance.author_type)      if q.count() <= 1:          return      authors = list(q.all()) @@ -3659,9 +3551,7 @@ class Document(              "container__cached_label__iexact",          ),          "warehouse_container_ref": SearchAltName( -            pgettext_lazy( -                "key for text search", "warehouse-container-reference" -            ), +            pgettext_lazy("key for text search", "warehouse-container-reference"),              "container_ref__cached_label__iexact",          ),          "comment": SearchAltName( @@ -3732,9 +3622,7 @@ class Document(              "receipt_date_in_documentation__lte",          ),          "receipt_date_in_documentation__after": SearchAltName( -            pgettext_lazy( -                "key for text search", "receipt-in-documentation-date-after" -            ), +            pgettext_lazy("key for text search", "receipt-in-documentation-date-after"),              "receipt_date_in_documentation__gte",          ),          "creation_date__before": SearchAltName( @@ -3836,9 +3724,7 @@ class Document(      index = models.IntegerField(verbose_name=_("Index"), blank=True, null=True)      external_id = models.TextField(_("External ID"), blank=True, default="")      reference = models.TextField(_("Ref."), blank=True, default="") -    internal_reference = models.TextField( -        _("Internal ref."), blank=True, default="" -    ) +    internal_reference = models.TextField(_("Internal ref."), blank=True, default="")      source_type = models.ForeignKey(          SourceType,          verbose_name=_("Type"), @@ -3859,9 +3745,7 @@ class Document(      licenses = models.ManyToManyField(          LicenseType, verbose_name=_("License"), blank=True      ) -    tags = models.ManyToManyField( -        DocumentTag, verbose_name=_("Tags"), blank=True -    ) +    tags = models.ManyToManyField(DocumentTag, verbose_name=_("Tags"), blank=True)      language = models.ForeignKey(          Language, verbose_name=_("Language"), blank=True, null=True      ) @@ -3936,12 +3820,8 @@ class Document(      additional_information = models.TextField(          _("Additional information"), blank=True, default=""      ) -    duplicate = models.NullBooleanField( -        _("Has a duplicate"), blank=True, null=True -    ) -    associated_links = models.TextField( -        _("Symbolic links"), blank=True, default="" -    ) +    duplicate = models.NullBooleanField(_("Has a duplicate"), blank=True, null=True) +    associated_links = models.TextField(_("Symbolic links"), blank=True, default="")      cache_related_label = models.TextField(          _("Related"),          blank=True, @@ -4010,9 +3890,7 @@ class Document(              .filter(                  Q(operations__id=current_operation)                  | Q(context_records__operation_id=current_operation) -                | Q( -                    finds__base_finds__context_record__operation_id=current_operation -                ) +                | Q(finds__base_finds__context_record__operation_id=current_operation)              )              .order_by("-custom_index")          ) @@ -4235,9 +4113,7 @@ class Document(                      q = subq                  else:                      q |= subq -        q |= cls._construct_query_own( -            "", [{"history_creator": ishtaruser.user_ptr}] -        ) +        q |= cls._construct_query_own("", [{"history_creator": ishtaruser.user_ptr}])          return q      def get_associated_operation(self): @@ -4296,11 +4172,7 @@ class Document(                  pass          while os.path.exists(path): -            if ( -                test_link -                and os.path.islink(path) -                and os.readlink(path) == test_link -            ): +            if test_link and os.path.islink(path) and os.readlink(path) == test_link:                  return path, True              current_nb += 1              path = "{}-{}.{}".format(base, current_nb, suffix) @@ -4354,11 +4226,7 @@ class Document(      @classmethod      def get_next_index(cls): -        q = ( -            cls.objects.values("index") -            .filter(index__isnull=False) -            .order_by("-index") -        ) +        q = cls.objects.values("index").filter(index__isnull=False).order_by("-index")          if not q.count():              return 1          cid = q.all()[0]["index"] @@ -4439,14 +4307,10 @@ class Document(                  )              )          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}))          if self.source_type: -            tags.append( -                ("meta", {"name": "DC.type", "content": str(self.source_type)}) -            ) +            tags.append(("meta", {"name": "DC.type", "content": str(self.source_type)}))          if self.format_type:              tags.append(                  ( @@ -4456,9 +4320,7 @@ class Document(              )          identifier = self.dublin_core_identifier          if identifier: -            tags.append( -                ("meta", {"name": "DC.identifier", "content": identifier}) -            ) +            tags.append(("meta", {"name": "DC.identifier", "content": identifier}))          if self.language:              lang = self.language.iso_code              tags.append(("meta", {"name": "DC.language", "content": lang})) @@ -4516,9 +4378,7 @@ class Document(              if person.first_name and person.name:                  info.append(("rft.aulast", person.name))                  info.append(("rft.aufirst", person.first_name)) -                info.append( -                    ("rft.au", "{}+{}".format(person.first_name, person.name)) -                ) +                info.append(("rft.au", "{}+{}".format(person.first_name, person.name)))              else:                  info.append(("rft.au", person.raw_name))          if self.source_type: @@ -4533,9 +4393,7 @@ class Document(              if self.creation_date.day == 1 and self.creation_date.month == 1:                  info.append(("rft.date", self.creation_date.year))              else: -                info.append( -                    ("rft.date", self.creation_date.strftime("%Y-%m-%d")) -                ) +                info.append(("rft.date", self.creation_date.strftime("%Y-%m-%d")))          if self.source and self.source.title:              info.append(("rft.source", self.source.title))          elif self.source_free_input: @@ -4552,9 +4410,7 @@ class Document(          return '<span class="Z3988" title="{}">'.format(urlencode(info))      def save(self, *args, **kwargs): -        no_path_change = "no_path_change" in kwargs and kwargs.pop( -            "no_path_change" -        ) +        no_path_change = "no_path_change" in kwargs and kwargs.pop("no_path_change")          self.set_index()          if not self.associated_url:              self.associated_url = None @@ -4793,9 +4649,7 @@ class AdministrationTask(models.Model):              stdout, stderr = session.communicate()          except OSError as e:              self.state = "FE" -            self.result = 'Error executing "{}" script: {}'.format( -                self.script.path, e -            ) +            self.result = 'Error executing "{}" script: {}'.format(self.script.path, e)              self.save()              return @@ -4829,9 +4683,7 @@ class ExportTask(models.Model):          _("Filter query"),          blank=True,          default="", -        help_text=_( -            "Textual query on this item (try it on the main " "interface)" -        ), +        help_text=_("Textual query on this item (try it on the main " "interface)"),      )      geo = models.BooleanField(          _("Export geographic data"), @@ -4845,9 +4697,7 @@ class ExportTask(models.Model):      state = models.CharField(          _("State"), max_length=2, choices=EXPORT_STATE, default="C"      ) -    put_locks = models.BooleanField( -        _("Put locks on associated items"), default=False -    ) +    put_locks = models.BooleanField(_("Put locks on associated items"), default=False)      lock_user = models.ForeignKey(          User,          related_name="+", @@ -4874,9 +4724,7 @@ class ExportTask(models.Model):      result = models.FileField(          _("Result"), null=True, blank=True, upload_to="exports/%Y/%m/"      ) -    result_info = models.TextField( -        _("Result information"), blank=True, default="" -    ) +    result_info = models.TextField(_("Result information"), blank=True, default="")      class Meta:          verbose_name = _("Archive - Export")  | 
