From 5621d42127ad11dd032842b8b99903ff002c73d0 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 4 Apr 2019 20:24:02 -0700 Subject: web editing of container urls --- python/fatcat_web/forms.py | 24 +++++-- python/fatcat_web/templates/container_edit.html | 92 +++++++++++++++++++++++++ python/fatcat_web/templates/entity_macros.html | 8 +++ 3 files changed, 119 insertions(+), 5 deletions(-) (limited to 'python/fatcat_web') diff --git a/python/fatcat_web/forms.py b/python/fatcat_web/forms.py index 776812ae..79365687 100644 --- a/python/fatcat_web/forms.py +++ b/python/fatcat_web/forms.py @@ -187,17 +187,24 @@ class ContainerEntityForm(EntityEditForm): publisher = StringField("Publisher") issnl = StringField("ISSN-L") wikidata_qid = StringField('Wikidata QID') + urls = FieldList( + StringField("Container URLs", + [validators.DataRequired(), + validators.URL(require_tld=False)])) @staticmethod - def from_entity(re): + def from_entity(ce): """ Initializes form with values from an existing container entity. """ - ref = ContainerEntityForm() + cef = ContainerEntityForm() for simple_attr in CONTAINER_SIMPLE_ATTRS: - a = getattr(ref, simple_attr) - a.data = getattr(re, simple_attr) - return ref + a = getattr(cef, simple_attr) + a.data = getattr(ce, simple_attr) + if ce.extra and ce.extra.get('urls'): + for url in ce.extra['urls']: + cef.urls.append_entry(url) + return cef def to_entity(self): assert(self.name.data) @@ -218,6 +225,13 @@ class ContainerEntityForm(EntityEditForm): if a == '': a = None setattr(ce, simple_attr, a) + extra_urls = [] + for url in self.urls: + extra_urls.append(url.data) + if extra_urls: + if not ce.extra: + ce.extra = dict() + ce.extra['urls'] = extra_urls if self.edit_description.data: ce.edit_extra = dict(description=self.edit_description.data) diff --git a/python/fatcat_web/templates/container_edit.html b/python/fatcat_web/templates/container_edit.html index 2a3f6f5f..83c00514 100644 --- a/python/fatcat_web/templates/container_edit.html +++ b/python/fatcat_web/templates/container_edit.html @@ -21,6 +21,33 @@ {{ edit_macros.form_field_inline(form.issnl) }} {{ edit_macros.form_field_inline(form.wikidata_qid) }} +
+

Homepage URLs

+ Landing page or mirror locations of container as a whole. +

+
+ {% for cfield in form.urls %} +
+
+ +
+
+
+ {{ cfield() }} + {{ edit_macros.form_field_errors(cfield) }} +
+
+
+ +
+
+ {% endfor %} +
+
+ +

Submit

{{ edit_macros.form_field_basic(form.edit_description) }} @@ -38,12 +65,77 @@ {% endblock %} {% block postscript %} + {% endblock %} diff --git a/python/fatcat_web/templates/entity_macros.html b/python/fatcat_web/templates/entity_macros.html index 3e83b9d4..6d9ceed0 100644 --- a/python/fatcat_web/templates/entity_macros.html +++ b/python/fatcat_web/templates/entity_macros.html @@ -35,6 +35,14 @@ {{ key }}.{{ inner_key }} {{ inner_value }} {% endfor %} + {% elif key in ("urls") and value and value is iterable and value is not string %} + {{ key }} + + + {% for u in value %} + {{ u }}
+ {% endfor %} +
{% else %} {{ key }} {{ value }} -- cgit v1.2.3