Skip to content

Commit

Permalink
Merge pull request #159 from zalf-rdm/issue_#116_related_identifier
Browse files Browse the repository at this point in the history
Issue #116 related identifier
  • Loading branch information
silvadealmeida authored Aug 7, 2024
2 parents 50aba6d + d132460 commit 77250ad
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 63 deletions.
1 change: 1 addition & 0 deletions geonode/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ class Meta:
"was_approved",
"was_published",
"funders",
"related_identifier",
)


Expand Down
28 changes: 20 additions & 8 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,8 @@ def __str__(self):


class RelatedIdentifier(models.Model):
related_identifier = models.CharField(
max_length=255, help_text=_("Identifiers of related resources. These must be globally unique identifiers.")
)
related_identifer_help_text = _("Identifiers of related resources. These must be globally unique identifiers.")
related_identifier = models.CharField(max_length=255, help_text=related_identifer_help_text)
related_identifier_type = models.ForeignKey(RelatedIdentifierType, on_delete=models.CASCADE)
relation_type = models.ForeignKey(RelationType, on_delete=models.CASCADE)

Expand All @@ -685,32 +684,45 @@ class FundingReference(models.Model):
"""Funding Reference Identifiers"""

funder_name = models.CharField(
max_length=255, help_text=_("Name of the funding provider. (e.g. European Commission)")
blank=True, null=True, max_length=255, help_text=_("Name of the funding provider. (e.g. European Commission)")
)
funder_identifier = models.CharField(
blank=True,
null=True,
max_length=255,
help_text=_(
"Uniquely identifies a funding entity, according to various types. (e.g. http://doi.org/10.13039/501100000780)"
),
)
funder_identifier_type = models.CharField(max_length=255, help_text=_("The type of the Identifier. (e.g. BMBF)"))
funder_identifier_type = models.CharField(
blank=True, null=True, max_length=255, help_text=_("The type of the Identifier. (e.g. BMBF)")
)

def __str__(self):
return f"{self.funder_name}"


class Funder(models.Model):
funding_reference = models.ForeignKey(FundingReference, null=False, blank=False, on_delete=models.CASCADE)
funders_help_text = _("List of funders, funded dataset creators")

funding_reference = models.ForeignKey(FundingReference, null=True, blank=True, on_delete=models.CASCADE)
award_number = models.CharField(
max_length=255, help_text=_("The code assigned by the funder to a sponsored award (grant). (e.g. 282625)")
blank=True,
null=True,
max_length=255,
help_text=funders_help_text,
)
award_uri = models.CharField(
blank=True,
null=True,
max_length=255,
help_text=_(
"The URI leading to a page provided by the funder for more information about the award (grant). (e.g. http://cordis.europa.eu/project/rcn/100180_en.html)"
),
)
award_title = models.CharField(
blank=True,
null=True,
max_length=255,
help_text=_(
"The human readable title of the award (grant). (e.g. MOTivational strength of ecosystem services)"
Expand Down Expand Up @@ -1137,7 +1149,7 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase):
Funder, verbose_name=_("Funder names"), null=True, blank=True, help_text=funders_help_text
)
related_projects = models.ManyToManyField(
RelatedProject, verbose_name=_("related project"), null=True, blank=True, help_text=related_projects_help_text
RelatedProject, verbose_name=_("Related project"), null=True, blank=True, help_text=related_projects_help_text
)

use_contraints = models.TextField(
Expand Down
127 changes: 118 additions & 9 deletions geonode/layers/templates/datasets/dataset_metadata_advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ <h2 class="page-title">{% trans "Edit Metadata" %}</h2>

{% block funder_form %}
<label > Fundings</label>
<div id="form_funder">
{{funder_form.management_form }}
<div id="DELETE" class="form-group">
<input type="hidden" name="FORM-xx-id" value="1" id="id_FORM-xx-id" hidden>
<input type="checkbox" name="FORM-xx-DELETE" id="id_FORM-xx-DELETE" hidden>

</div>
<div class="panel ">
<!-- Tab panes -->
Expand All @@ -144,25 +142,25 @@ <h2 class="page-title">{% trans "Edit Metadata" %}</h2>
<li role="presentation" class="active">
<a href="#{{ form.prefix }}" aria-controls="{{ form.prefix }}" role="tab" data-toggle="tab">
<span class="tabTex">{{ forloop.counter }} </span>
<button type="button" class="nav-remove"><icon class="fa fa-minus-circle"></icon>
<button type="button" class="nav-remove" onclick="removeTab(this)"><icon class="fa fa-minus-circle"></icon>
</button></a>
</li>
{% else %}
<li role="presentation" class="">
<a href="#{{ form.prefix }}" aria-controls="{{ form.prefix }}" role="tab" data-toggle="tab">
<span class="tabTex">{{ forloop.counter }} </span>
<button type="button" class="nav-remove"><icon class="fa fa-minus-circle"></icon>
<button type="button" class="nav-remove" onclick="removeTab(this)"><icon class="fa fa-minus-circle"></icon>
</button></a>
</li>
{% endif %}
{%endfor%}
<li role="presentation" class="nav-item enpt tab li-add" >
<a ><button id="nav-add" class="btn-primary nav-add " type="button"><icon class="fa fa-plus-circle"> new </button></a>
<a ><button id="nav-add" class="btn-primary nav-add " onclick="addNewTab(this)" type="button"><icon class="fa fa-plus-circle"> new </button></a>
</li>
<li role="presentation" class="nav-item enpt tab nav-empty templateTab hidden" >
<a href="" aria-controls="{{ form.prefix }}" role="tab" data-toggle="tab">
<span class="newTabTex"></span>
<button type="button" class="nav-remove"><icon class="fa fa-minus-circle"></icon>
<button type="button" class="nav-remove" onclick="removeTab(this)" ><icon class="fa fa-minus-circle"></icon>
</button></a>
</li>

Expand Down Expand Up @@ -234,9 +232,119 @@ <h2 class="page-title">{% trans "Edit Metadata" %}</h2>

</div>
</div>


</div>
{% endblock funder_form %}

{% block related_identifier_form %}
<label > Related Identifiers</label>
<div id="form_related_identifier">
{{related_identifier_form.management_form }}
<div id="DELETE" class="form-group">
</div>
<div class="panel ">
<!-- Tab panes -->
<div class="panel-heading panel-heading-nav">
<ul class="nav nav-tabs allTabs">
{% for form in related_identifier_form %}
{% if forloop.counter == 1 %}
<li role="presentation" class="active">
<a href="#{{ form.prefix }}" aria-controls="{{ form.prefix }}" role="tab" data-toggle="tab">
<span class="tabTex">{{ forloop.counter }} </span>
<button type="button" class="nav-remove" onclick="removeTab(this)"><icon class="fa fa-minus-circle"></icon>
</button></a>
</li>
{% else %}
<li role="presentation" class="">
<a href="#{{ form.prefix }}" aria-controls="{{ form.prefix }}" role="tab" data-toggle="tab">
<span class="tabTex">{{ forloop.counter }} </span>
<button type="button" class="nav-remove" onclick="removeTab(this)"><icon class="fa fa-minus-circle"></icon>
</button></a>
</li>
{% endif %}
{%endfor%}
<li role="presentation" class="nav-item enpt tab li-add" >
<a ><button id="nav-add" class="btn-primary nav-add " onclick="addNewTab(this)" type="button"><icon class="fa fa-plus-circle"> new </button></a>
</li>
<li role="presentation" class="nav-item enpt tab nav-empty templateTab hidden" >
<a href="" aria-controls="{{ form.prefix }}" role="tab" data-toggle="tab">
<span class="newTabTex"></span>
<button type="button" class="nav-remove" onclick="removeTab(this)" ><icon class="fa fa-minus-circle"></icon>
</button></a>
</li>

</ul>
</div>
<!-- Tab panes -->
<div class="tab-content allContent">
{% for form in related_identifier_form %}
{% if forloop.counter == 1 %}
<div class="tab-pane active" id="{{ form.prefix }}" role="tabpanel" >
<div>
{% if forloop.first %}

{% for field in form.visible_fields %}

<label for="{{ field.name }}">{{ field.label|capfirst }}</label>
<div id="{{ field.name }}" class="form-group">
{{ field }}
{{ field.errors.as_ul }}
</div>

{% endfor %}
{% endif %}
{% for hidden in form.hidden_fields %}
<div>
{{ hidden }}
</div>
{% endfor %}
</div>
</div>
{% else %}
<div class="tab-pane " id="{{ form.prefix }}" role="tabpanel" >
<div>

{% for field in form.visible_fields %}
<label for="{{ field.name }}">{{ field.label|capfirst }}</label>
<div id="{{ field.name }}" class="form-group">
{{ field }}
{{ field.errors.as_ul }}
</div>
{% endfor %}
{% for hidden in form.hidden_fields %}
<div>
{{ hidden }}
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% endfor %}

<div class="tab-pane hidden templateContent" id="templateContent" role="tabpanel" >
<div>

{% for field in related_identifier_form.empty_form.visible_fields %}
<label for="{{ field.name }}">{{ field.label|capfirst }}</label>
<div id="{{ field.name }}" class="form-group">
{{ field }}
{{ field.errors.as_ul }}
</div>
{% endfor %}
{% for hidden in related_identifier_form.empty_form.hidden_fields %}
<div>
{{ hidden }}
</div>
{% endfor %}
</div>
</div>

</div>
</div>

</div>

{% endblock related_identifier_form %}



Expand Down Expand Up @@ -377,8 +485,9 @@ <h4 class="modal-title">{% trans "ERROR" %}</h4>
});
</script>
<script>
let prefix = "{{funder_form.prefix}}";
let formsetsInTabs = ["{{funder_form.prefix}}","{{related_identifier_form.prefix}}"];
</script>

{% comment %} <script type="text/javascript" src="{% static "geonode/js/utils/fundings_.js" %}"></script> {% endcomment %}
<script type="text/javascript" src="{% static "geonode/js/utils/formsetsInTabs.js" %}"></script>
{% endblock %}
35 changes: 31 additions & 4 deletions geonode/layers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from geonode.base.auth import get_or_create_token
from geonode.base.forms import CategoryForm, TKeywordForm, ThesaurusAvailableForm
from geonode.base.views import batch_modify
from geonode.base.models import Thesaurus, TopicCategory, Funder
from geonode.base.models import Thesaurus, TopicCategory, Funder, RelatedIdentifier
from geonode.base.enumerations import CHARSETS
from geonode.decorators import check_keyword_write_perms
from geonode.layers.forms import DatasetForm, DatasetTimeSerieForm, LayerAttributeForm, NewLayerUploadForm
Expand Down Expand Up @@ -363,6 +363,14 @@ def dataset_metadata(
extra=0,
min_num=1,
)

RelatedIdentifierFormset = modelformset_factory(
RelatedIdentifier,
fields=["related_identifier", "related_identifier_type", "relation_type"],
can_delete=True,
extra=0,
min_num=1,
)
current_keywords = [keyword.name for keyword in layer.keywords.all()]
topic_category = layer.category

Expand Down Expand Up @@ -419,10 +427,15 @@ def dataset_metadata(
"errors": [re.sub(re.compile("<.*?>"), "", str(err)) for err in attribute_form.errors],
}
return HttpResponse(json.dumps(out), content_type="application/json", status=400)
funders_intial_values = Funder.objects.all().filter(resourcebase=layer)

funder_form = FunderFormset(
request.POST,
prefix="funder_form",
prefix="form_funder",
)

related_identifier_form = RelatedIdentifierFormset(
request.POST,
prefix="form_related_identifier",
)
category_form = CategoryForm(
request.POST,
Expand Down Expand Up @@ -483,7 +496,13 @@ def dataset_metadata(
)

funders_intial_values = Funder.objects.all().filter(resourcebase=layer)
funder_form = FunderFormset(prefix="funder_form", queryset=funders_intial_values)
funder_form = FunderFormset(prefix="form_funder", queryset=funders_intial_values)

related_identifier_intial_values = RelatedIdentifier.objects.all().filter(resourcebase=layer)
related_identifier_form = RelatedIdentifierFormset(
prefix="form_related_identifier", queryset=related_identifier_intial_values
)

category_form = CategoryForm(
prefix="category_choice_field", initial=topic_category.id if topic_category else None
)
Expand Down Expand Up @@ -555,6 +574,7 @@ def dataset_metadata(
and dataset_form.is_valid()
and attribute_form.is_valid()
and funder_form.is_valid()
and related_identifier_form.is_valid()
and category_form.is_valid()
and tkeywords_form.is_valid()
and timeseries_form.is_valid()
Expand All @@ -580,7 +600,13 @@ def dataset_metadata(
layer.set_contact_roles_from_metadata_edit(dataset_form)
funder_form.save()
instance = funder_form.save(commit=False)

layer.funders.add(*instance)

related_identifier_form.save()
instance = related_identifier_form.save(commit=False)
layer.related_identifier.add(*instance)

layer.save()

new_keywords = current_keywords if request.keyword_readonly else dataset_form.cleaned_data["keywords"]
Expand Down Expand Up @@ -694,6 +720,7 @@ def dataset_metadata(
"attribute_form": attribute_form,
"timeseries_form": timeseries_form,
"funder_form": funder_form,
"related_identifier_form": related_identifier_form,
"category_form": category_form,
"tkeywords_form": tkeywords_form,
"preview": getattr(settings, "GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY", "mapstore"),
Expand Down
Loading

0 comments on commit 77250ad

Please sign in to comment.