diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-06-02 13:18:25 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:21 +0100 |
commit | fa90d96f807d56d87ccfbb3141e70a7603ca5b60 (patch) | |
tree | 22f26730c66de9d357f3ceb2f343d6d0cab53b91 | |
parent | 916311c130b2a736374444894e232df605fd7d19 (diff) | |
download | Ishtar-fa90d96f807d56d87ccfbb3141e70a7603ca5b60.tar.bz2 Ishtar-fa90d96f807d56d87ccfbb3141e70a7603ca5b60.zip |
Documents form: new fields
-rw-r--r-- | docs/fr/source/_static/ishtar-dublincore.png | bin | 84902 -> 82073 bytes | |||
-rw-r--r-- | docs/fr/source/media-src/ishtar-dublincore.dot | 3 | ||||
-rw-r--r-- | example_project/settings.py | 8 | ||||
-rw-r--r-- | ishtar_common/forms_common.py | 41 | ||||
-rw-r--r-- | ishtar_common/models.py | 12 | ||||
-rw-r--r-- | ishtar_common/urls.py | 2 | ||||
-rw-r--r-- | ishtar_common/views.py | 25 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 10 |
8 files changed, 92 insertions, 9 deletions
diff --git a/docs/fr/source/_static/ishtar-dublincore.png b/docs/fr/source/_static/ishtar-dublincore.png Binary files differindex 6407e2749..299a41757 100644 --- a/docs/fr/source/_static/ishtar-dublincore.png +++ b/docs/fr/source/_static/ishtar-dublincore.png diff --git a/docs/fr/source/media-src/ishtar-dublincore.dot b/docs/fr/source/media-src/ishtar-dublincore.dot index fa37b73b6..72735c64f 100644 --- a/docs/fr/source/media-src/ishtar-dublincore.dot +++ b/docs/fr/source/media-src/ishtar-dublincore.dot @@ -3,7 +3,7 @@ digraph ishtar_dc { rankdir="LR"; graph [fontname="cantarell" splines=false]; node [shape=box fontname="liberationsansnarrow" style="rounded" - color="#A4A4A4" fontcolor="#333333" margin="0.2,0.2"]; + color="#A4A4A4" fontcolor="#333333" margin="0.2,0.2"]; edge [fontname="cantarell" color="#432776"]; DC_Coverage [label="Couverture (Coverage)"]; @@ -61,6 +61,7 @@ digraph ishtar_dc { I_ISBN -> DC_Identifier; I_ISSN -> DC_Identifier; I_Source1 -> DC_Source; + I_Source1 -> DC_Relation; I_Source2 -> DC_Source; I_Rights -> DC_Rights; I_Language -> DC_Language; diff --git a/example_project/settings.py b/example_project/settings.py index 50aa231ad..344fd8eab 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -259,14 +259,18 @@ ISHTAR_QRCODE_VERSION = 6 # density of the QR code ISHTAR_QRCODE_SCALE = 2 # scale of the QR code ISHTAR_DEFAULT_YEAR = 1900 +ISHTAR_SLUGS = { + "document-editor": ["editor"], +} + SRID = 4326 # WGS84 - World SURFACE_SRID = 4326 # WGS84 - World ENCODING = 'windows-1252' ALT_ENCODING = 'ISO-8859-15' APP_NAME = "SRA - Pays de la Loire" SURFACE_UNIT = 'square-metre' -SURFACE_UNIT_LABEL = u'm²' -JOINT = u" | " +SURFACE_UNIT_LABEL = 'm²' +JOINT = " | " # dir for ishtar maintenance script - as it can be a serious security issue if # not managed cautiously the dir contening theses scripts is not set by default ISHTAR_SCRIPT_DIR = "" diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 70204fbd7..20cf0b613 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1237,6 +1237,7 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): extra_form_modals = ["author", "person", "organization"] associated_models = {'source_type': models.SourceType, 'support_type': models.SupportType, + 'publisher': models.Organization, 'format_type': models.Format} pk = forms.IntegerField(label="", required=False, widget=forms.HiddenInput) @@ -1261,6 +1262,38 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): authors = widgets.ModelJQueryAutocompleteField( model=models.Author, multiple=True, label=_("Authors"), new=True, long_widget=True, required=False) + publisher = forms.IntegerField( + label=_("Publisher"), + widget=widgets.JQueryAutoComplete( + reverse_lazy( + 'autocomplete-organization', + args=[models.organization_type_pks_lazy( + settings.ISHTAR_SLUGS["document-editor"])]), + limit={ + 'organization_type': models.organization_type_pks_lazy( + ['responsible_planning_service']) + }, + tips=models.get_publisher_label, + associated_model=models.Organization, new=True), + validators=[models.valid_id(models.Organization)], required=False) + license = widgets.Select2MultipleField( + label=_("Licences"), required=False) + tag = widgets.Select2MultipleField(label=_("Tags"), required=False) + language = widgets.ModelChoiceField( + model=models.Language, label=_("Language"), choices=[], + required=False) + issn = forms.CharField( + label=_("ISSN"), + validators=[validators.MaxLengthValidator(8)], required=False) + isbn = forms.CharField( + label=_("ISBN"), + validators=[validators.MaxLengthValidator(13)], required=False) + source = widgets.ModelJQueryAutocompleteField( + label=_("Source"), + model=models.Document, required=False) + source_free_input = forms.CharField( + label=_("Source free input"), + validators=[validators.MaxLengthValidator(500)], required=False) associated_url = forms.URLField( max_length=1000, required=False, label=_("Numerical ressource (web address)")) @@ -1301,6 +1334,9 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): FieldType('source_type', models.SourceType), FieldType('support_type', models.SupportType), FieldType('format_type', models.Format), + FieldType('language', models.Language), + FieldType('licence', models.LicenseType, is_multiple=True), + FieldType('tag', models.DocumentTag, is_multiple=True), ] class Meta: @@ -1308,10 +1344,12 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): fields = [ 'title', 'source_type', 'reference', 'internal_reference', 'format_type', 'support_type', 'scale', - 'image', 'associated_file', 'associated_url', + 'image', 'associated_file', 'associated_url', 'tag', 'authors', 'receipt_date', 'receipt_date_in_documentation', 'creation_date', + 'publisher', 'language', 'isbn', 'issn', 'license', 'container', "container_ref", + 'source', 'source_free_input', 'comment', 'description', 'additional_information', 'duplicate' ] @@ -1321,6 +1359,7 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): 'image': FormHeader(_("Content")), 'authors': FormHeader(_("Authors")), 'receipt_date': FormHeader(_("Dates")), + 'publisher': FormHeader(_("Publishing"), collapse=True), 'container': FormHeader(_("Container"), collapse=True), 'comment': FormHeader(_("Advanced"), collapse=True), 'finds': FormHeader(_("Related items")), diff --git a/ishtar_common/models.py b/ishtar_common/models.py index b3a19c42f..58385c1dc 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4477,6 +4477,18 @@ def get_responsible_planning_service_label(): return _("Error: responsible_planning_service type is missing") +def get_publisher_label(): + if apps.ready: + lbls = [] + for key in settings.ISHTAR_SLUGS["document-editor"]: + lbl = get_general_type_label(OrganizationType, key) + if lbl: + lbls.append(lbl) + if lbls: + return " ; ".join(lbls) + return _("Error: publisher type is missing") + + class TitleType(GeneralType): class Meta: verbose_name = _("Title type") diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 8b506c55c..03550302a 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -316,6 +316,8 @@ urlpatterns += [ check_rights(['change_document', 'change_own_document'])( views.document_deletion_wizard), name='document_deletion'), + url(r'autocomplete-document/$', + views.autocomplete_document, name='autocomplete-document'), url(r'document/shortcut/delete/(?P<pk>.+)/$', views.document_delete, name='delete-document'), diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 2176c4519..3e5ef48cf 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -729,6 +729,31 @@ def autocomplete_advanced_town(request, department_id=None, state_id=None): return HttpResponse(data, content_type='text/plain') +def autocomplete_document(request): + if not request.GET.get('term'): + return HttpResponse(content_type='text/plain') + q = request.GET.get('term') + q = unicodedata.normalize("NFKD", q).encode('ascii', 'ignore').decode() + fields = ["title__icontains", "reference__icontains", + "internal_reference__icontains", "isbn__icontains", + "authors__person__cached_label__icontains", + "authors_raw__icontains"] + query = None + for q in q.split(' '): + qu = Q(**{fields[0]: q}) + for field in fields[1:]: + qu |= Q(**{field: q}) + if not query: + query = qu + else: + query = query & qu + limit = 20 + items = models.Document.objects.filter(query)[:limit] + data = json.dumps([{'id': item.pk, 'value': str(item)} + for item in items]) + return HttpResponse(data, content_type='text/plain') + + def department_by_state(request, state_id=''): if not state_id: data = [] diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 9483f9719..e5f4c67b1 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -606,10 +606,7 @@ class JQueryAutoComplete(forms.TextInput): """ self.source = source self.associated_model = associated_model - if callable(tips): - self.tips = tips() - else: - self.tips = tips + self.tips = tips self.options = None if options and len(options) > 0: @@ -733,11 +730,14 @@ class JQueryAutoComplete(forms.TextInput): # "extra_form_modals" list is used for that in form or view model_name = self.associated_model._meta.object_name.lower() if self.tips: + tips = self.tips + if callable(tips): + tips = tips() new += """<span class="input-group-append"> <span class="add-button input-group-text"> <em id="{}-tips">{}</em> </span></span> - """.format(attrs_hidden['id'], self.tips) + """.format(attrs_hidden['id'], tips) if self.modify: new += """ <span class="input-group-append"> |