diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/forms_common.py | 45 | ||||
| -rw-r--r-- | ishtar_common/migrations/0209_document_source_page_range.py | 20 | ||||
| -rw-r--r-- | ishtar_common/models.py | 30 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/sheet_document.html | 24 | ||||
| -rw-r--r-- | ishtar_common/templatetags/window_field.py | 4 | 
5 files changed, 98 insertions, 25 deletions
| diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index c191a2e6e..697abd1cc 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -21,6 +21,7 @@ from collections import OrderedDict  import datetime  import os  import pyqrcode +import re  import requests  import shutil  import tempfile @@ -115,10 +116,12 @@ class NewItemForm(forms.Form):      def limit_fields(self):          for key in self.limits:              if key in self.fields and hasattr(self.fields[key], 'choices'): -                new_choices = [] -                for value, lbl in self.fields[key].choices: -                    if str(value) in self.limits[key]: -                        new_choices.append((value, lbl)) +                new_choices = [ +                    (value, lbl) +                    for value, lbl in self.fields[key].choices +                    if str(value) in self.limits[key] +                ] +                  self.fields[key].choices = new_choices                  if len(new_choices) == 1:                      self.fields[key].initial = [new_choices[0][0]] @@ -1338,6 +1341,13 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType):      source_free_input = forms.CharField(          label=_("Source - free input"),          validators=[validators.MaxLengthValidator(500)], required=False) +    source_page_range = forms.CharField( +        label=_("Source - page range"), +        validators=[validators.MaxLengthValidator(500)], required=False, +        help_text=_("Unique page: \"242\", page range: \"242-245\", multiple " +                    "pages: \"242;245;249\", multiples pages and multiple " +                    "pages ranges: \"242-245;249;262-265\".") +    )      associated_url = forms.URLField(          max_length=1000, required=False,          label=_("Numerical ressource (web address)")) @@ -1392,7 +1402,7 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType):              'authors', 'receipt_date',              'receipt_date_in_documentation', 'creation_date',              'publisher', 'language', 'isbn', 'issn', 'licenses', -            'source', 'source_free_input', +            'source', 'source_free_input', 'source_page_range',              'container_id', "container_ref_id",              'comment', 'description', 'additional_information', 'duplicate'          ] @@ -1448,6 +1458,14 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType):              fields[k] = self.fields[k]          self.fields = fields +    def clean_source_page_range(self): +        value = self.cleaned_data.get( +            'source_page_range', None).replace(" ", "") +        if value and not re.match(r"^(\d+[-;]*\d)+$", value): +            raise forms.ValidationError( +                _("Incorrect page range.")) +        return value +      def get_headers(self):          headers = self.HEADERS.copy()          if self.is_instancied: @@ -1488,9 +1506,7 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType):              for k in lst:                  if k not in excluded_fields['format_type']:                      excluded_fields['format_type'].append(k) -            conditional_fields[key][sub_key] = [] -            conditional_fields[key][sub_key].append( -                ('format_type', ",".join(lst))) +            conditional_fields[key][sub_key] = [('format_type', ",".join(lst))]          for doc_type in models.SourceType.objects.filter(                  available=True, supports__pk__isnull=False).all():              if key not in conditional_fields: @@ -1548,10 +1564,10 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType):              initial = dict([(rel.pk, rel) for rel in related.all()])              new = [int(pk)                     for pk in sorted(self.cleaned_data.get(related_key, []))] -            for pk in initial.keys(): +            for pk, value in initial.items():                  if pk in new:                      continue -                related.remove(initial[pk]) +                related.remove(value)              for new_pk in new:                  related_item = related.model.objects.get(pk=new_pk)                  if new_pk not in initial.keys(): @@ -1799,9 +1815,7 @@ class QADocumentDuplicateForm(IshtarForm):              if not related.count():                  continue              model = models.Document._meta.get_field(related_key).related_model -            initial = [] -            for item in related.all(): -                initial.append(item.pk) +            initial = [item.pk for item in related.all()]              self.fields["qa_" + related_key] = widgets.Select2MultipleField(                  model=model, remote=True, label=model._meta.verbose_name_plural,                  required=False, long_widget=True, initial=initial @@ -1892,10 +1906,7 @@ class QALockForm(forms.Form):          locked = self.cleaned_data["action"] == "lock"          for item in items:              item.locked = locked -            if locked: -                item.lock_user = user -            else: -                item.lock_user = None +            item.lock_user = user if locked else None              item.skip_history_when_saving = True              item.save() diff --git a/ishtar_common/migrations/0209_document_source_page_range.py b/ishtar_common/migrations/0209_document_source_page_range.py new file mode 100644 index 000000000..5bbe8a1e0 --- /dev/null +++ b/ishtar_common/migrations/0209_document_source_page_range.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-11-30 15:56 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0208_auto_20201126_1516'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='document', +            name='source_page_range', +            field=models.CharField(blank=True, max_length=500, null=True, verbose_name='Source - page range'), +        ), +    ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index ffe302454..722e134ac 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3027,10 +3027,13 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel,      issn = models.CharField(_("ISSN"), blank=True, null=True, max_length=10)      isbn = models.CharField(_("ISBN"), blank=True, null=True, max_length=17)      source = models.ForeignKey("Document", verbose_name=_("Source"), -                               blank=True, null=True) +                               blank=True, null=True, related_name="children")      source_free_input = models.CharField(          verbose_name=_("Source - free input"), blank=True, null=True,          max_length=500) +    source_page_range = models.CharField( +        verbose_name=_("Source - page range"), blank=True, null=True, +        max_length=500)      support_type = models.ForeignKey(SupportType, verbose_name=_("Medium"),                                       on_delete=models.SET_NULL,                                       blank=True, null=True, ) @@ -3147,6 +3150,14 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel,      def natural_key(self):          return (self.external_id,) +    def sheet_header(self): +        headers = [] +        if self.complete_identifier: +            headers.append(self.complete_identifier) +        if self.title: +            headers.append(self.title) +        return " - ".join(headers) +      @property      def has_iframe(self):          return self.format_type and self.format_type.iframe_template @@ -3177,6 +3188,23 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel,          except Container.DoesNotExist:              return +    @property +    def pdf_attached(self): +        if not self.associated_file and (not self.source +                                         or not self.source.associated_file): +            return +        extra = "" +        if self.associated_file: +            url = self.associated_file.url +        else: +            url = self.source.associated_file.url +            if self.source_page_range: +                extra = "#page=" +                extra += self.source_page_range.split("-")[0].split(";")[0] +        if not url.lower().endswith(".pdf"): +            return +        return url + extra +      """      @property      def code(self): diff --git a/ishtar_common/templates/ishtar/sheet_document.html b/ishtar_common/templates/ishtar/sheet_document.html index e01d0d9fb..0497e7f5a 100644 --- a/ishtar_common/templates/ishtar/sheet_document.html +++ b/ishtar_common/templates/ishtar/sheet_document.html @@ -1,7 +1,7 @@  {% extends "ishtar/sheet.html" %}  {% load i18n window_field window_header link_to_window %} -{% block head_title %}<strong>{% trans "Document" %}</strong> {% if item.complete_identifier %} - {{item.complete_identifier}}{% endif %} - {{item.title}}{% endblock %} +{% block head_title %}<strong>{% trans "Document" %}</strong> - {{item.sheet_header}}{% endblock %}  {% block content %}  {% block window_nav %} @@ -20,6 +20,16 @@  {% else %}      <div class="row">  {% endif %} +    {% with pdf_attached=item.pdf_attached %} +    {% if pdf_attached %} +        <p class="text-center col-12 p-2"> +            <a href="{{pdf_attached}}" target="_blank"> +                {% trans "View PDF" %} +                <i class="fa fa-external-link" aria-hidden="true"></i> +            </a> +        </p> +    {% endif %} +    {% endwith %}          <h4 class="col-12">{% trans "Identification" %}</h4>          <div class="col-12 col-md-6 col-lg-3 flex-wrap"> @@ -82,6 +92,7 @@      <h4 class="col-12">{% trans "Source" %}</h4>      {% field_flex_detail "Source" item.source %}      {% field_flex "" item.source_free_input %} +    {% field_flex_detail "Pages" item.source_page_range %}      {% endif %}      {% if item.container or item.container_ref or item.item_number != 1 or item.duplicate %} @@ -100,14 +111,12 @@      {% endif %}      </div>  </div> -<div class="row"> -</div>  {% include "ishtar/blocks/sheet_json.html" %}  {% block related %}  {% if item.has_related %} -<h2>{% trans "Related items" %}</h2> +<h3>{% trans "Related items" %}</h3>  {% field_flex_full "Files" item.files|add_links %}  {% field_flex_full "Sites" item.sites|add_links %}  {% field_flex_full "Operations" item.operations|add_links %} @@ -121,5 +130,12 @@  {{ item.coins_tag|default:""|safe }}  {% endblock %} +{% if item.children.count %} +<h3>{% trans "Associated documents" %}</h3> +<div class="row"> +    {% field_flex_full "" item.children|add_links %} +</div> +{% endif %} +  {% endblock %}  {% endblock %} diff --git a/ishtar_common/templatetags/window_field.py b/ishtar_common/templatetags/window_field.py index cd4122b58..f9f8bcab8 100644 --- a/ishtar_common/templatetags/window_field.py +++ b/ishtar_common/templatetags/window_field.py @@ -1,6 +1,7 @@  import os  from django import template +from django.template import loader  from django.utils.translation import ugettext as _  from django.utils.text import mark_safe @@ -95,9 +96,6 @@ def field_multiple(caption, data, li=False, size=None):      return {'caption': caption, 'data': data, 'li': li, "size": size} -from django.template import Library, loader, Context - -  @register.simple_tag  def field_multiple_obj(caption, item, attr, li=False, size=None):      data = getattr(item, attr) | 
