From 77ab13d95c0d2185d4a85c552abb43aba8ef568a Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Mon, 10 Jul 2017 11:23:25 +0200 Subject: [PATCH] Improve manage metadata --- journals/admin.py | 2 +- .../migrations/0030_auto_20170710_1051.py | 20 ++++++++ journals/models.py | 2 +- .../templates/journals/manage_metadata.html | 48 ++++++++++++------- .../journals/metadata_xml_deposit.html | 2 +- journals/urls/general.py | 2 +- journals/views.py | 34 ++++++------- 7 files changed, 71 insertions(+), 39 deletions(-) create mode 100644 journals/migrations/0030_auto_20170710_1051.py diff --git a/journals/admin.py b/journals/admin.py index 8c82762bb..167b0f62e 100644 --- a/journals/admin.py +++ b/journals/admin.py @@ -64,7 +64,7 @@ admin.site.register(Publication, PublicationAdmin) class DepositAdmin(admin.ModelAdmin): - list_display = ('doi_batch_id', 'publication', 'deposition_date',) + list_display = ('publication', 'timestamp', 'doi_batch_id', 'deposition_date',) readonly_fields = ('publication', 'doi_batch_id', 'metadata_xml', 'deposition_date',) actions = None diff --git a/journals/migrations/0030_auto_20170710_1051.py b/journals/migrations/0030_auto_20170710_1051.py new file mode 100644 index 000000000..e3534b851 --- /dev/null +++ b/journals/migrations/0030_auto_20170710_1051.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-10 08:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('journals', '0029_remove_publication_latest_crossref_deposit'), + ] + + operations = [ + migrations.AlterField( + model_name='deposit', + name='metadata_xml_file', + field=models.FileField(blank=True, max_length=512, null=True, upload_to=''), + ), + ] diff --git a/journals/models.py b/journals/models.py index 0e5238710..3f5454a8f 100644 --- a/journals/models.py +++ b/journals/models.py @@ -225,7 +225,7 @@ class Deposit(models.Model): timestamp = models.CharField(max_length=40, default='') doi_batch_id = models.CharField(max_length=40, default='') metadata_xml = models.TextField(blank=True, null=True) - metadata_xml_file = models.FileField(blank=True, null=True) + metadata_xml_file = models.FileField(blank=True, null=True, max_length=512) deposition_date = models.DateTimeField(blank=True, null=True) response_text = models.TextField(blank=True, null=True) deposit_successful = models.NullBooleanField(default=None) diff --git a/journals/templates/journals/manage_metadata.html b/journals/templates/journals/manage_metadata.html index 961591fa2..2d5ec8c24 100644 --- a/journals/templates/journals/manage_metadata.html +++ b/journals/templates/journals/manage_metadata.html @@ -54,6 +54,7 @@ event: "focusin" </tr> <tr id="collapse{{ publication.id }}" class="collapse" role="tabpanel" aria-labelledby="heading{{ publication.id }}" style="background-color: #fff;"> <td colspan="4"> + <h3 class="ml-3">Actions</h3> <ul> <li>Mark the first author (currently: {% if publication.first_author %}{{ publication.first_author }} {% elif publication.first_author_unregistered %}{{ publication.first_author_unregistered }} (unregistered){% endif %}) <div class="row"> @@ -87,24 +88,35 @@ event: "focusin" <li><a href="{% url 'journals:metadata_xml_deposit' publication.doi_label 'test' %}">Test metadata deposit (via Crossref test server)</a></li> <li><a href="{% url 'journals:metadata_xml_deposit' publication.doi_label 'deposit' %}">Deposit the metadata to Crossref</a></li> </ul> - <table> - {% for deposit in publication.deposit_set.all %} - <tr> - <td>{{ deposit.timestamp }}</td> - <td>{{ deposit.doi_batch_id }}</td> - <td>{% if deposit.deposition_date %}{{ deposit.deposition_date }}{% else %}Not deposited{% endif %}</td> - <td>Mark deposit as - <ul> - <li><a href="{% url 'journals:mark_deposit_success' deposit_id=deposit.id success=1 %}">successful</a></li> - <li><a href="{% url 'journals:mark_deposit_success' deposit_id=deposit.id success=0 %}">unsuccessful</a></li> - </ul> - </td> - </tr> - {% empty %} - <tr> - <td colspan="4">No Deposits found for this publication</td> - </tr> - {% endfor %} + <h3 class="ml-3">Deposits</h3> + <table class="ml-5"> + <thead class="thead-default"> + <th>Timestamp</th> + <th>batch id</th> + <th>deposition date</th> + <th>Successful?</th> + <th>actions</th> + </thead> + <tbody> + {% for deposit in publication.deposit_set.all %} + <tr> + <td>{{ deposit.timestamp }}</td> + <td>{{ deposit.doi_batch_id }}</td> + <td>{% if deposit.deposition_date %}{{ deposit.deposition_date }}{% else %}Not deposited{% endif %}</td> + <td>{{ deposit.deposit_successful }}</td> + <td>Mark deposit as + <ul> + <li><a href="{% url 'journals:mark_deposit_success' deposit_id=deposit.id success=1 %}">successful</a></li> + <li><a href="{% url 'journals:mark_deposit_success' deposit_id=deposit.id success=0 %}">unsuccessful</a></li> + </ul> + </td> + </tr> + {% empty %} + <tr> + <td colspan="4">No Deposits found for this publication</td> + </tr> + {% endfor %} + </tbody> </table> </td> </tr> diff --git a/journals/templates/journals/metadata_xml_deposit.html b/journals/templates/journals/metadata_xml_deposit.html index bc16e8cc5..645cba7c0 100644 --- a/journals/templates/journals/metadata_xml_deposit.html +++ b/journals/templates/journals/metadata_xml_deposit.html @@ -22,7 +22,7 @@ <h3>Response text:</h3> <p>{{ response_text|linebreaks }}</p> - <h3><a href="{{publication.get_absolute_url}}">return to the publication's page</a></h3> + <h3><a href="{{publication.get_absolute_url}}">return to the publication's page</a> or to the <a href="{% url 'journals:manage_metadata' %}">metadata management page</a></h3> </section> diff --git a/journals/urls/general.py b/journals/urls/general.py index dacdd5bb4..3fd938879 100644 --- a/journals/urls/general.py +++ b/journals/urls/general.py @@ -52,7 +52,7 @@ urlpatterns = [ url(r'^metadata_xml_deposit/(?P<doi_label>[a-zA-Z]+.[0-9]+.[0-9]+.[0-9]{3,})/(?P<option>[a-z]+)$', journals_views.metadata_xml_deposit, name='metadata_xml_deposit'), - url(r'^mark_deposit_as_successful/(?P<deposit_id>[0-9]+)/(?P<success>[0-1])$', + url(r'^mark_deposit_success/(?P<deposit_id>[0-9]+)/(?P<success>[0-1])$', journals_views.mark_deposit_success, name='mark_deposit_success'), url(r'^harvest_citedby_list/$', diff --git a/journals/views.py b/journals/views.py index 00221b7fa..4eb5a6810 100644 --- a/journals/views.py +++ b/journals/views.py @@ -21,6 +21,7 @@ from .forms import FundingInfoForm, InitiatePublicationForm, ValidatePublication UnregisteredAuthorForm, CreateMetadataXMLForm, CitationListBibitemsForm from .utils import JournalUtils +from journals.models import Publication, Deposit from submissions.models import Submission from scipost.models import Contributor @@ -608,22 +609,21 @@ def metadata_xml_deposit(request, doi_label, option='test'): response_text = r.text # Then, if deposit, create the associated Deposit object (saving the metadata to a file) - if option == 'deposit': - content = ContentFile(publication.metadata_xml) - timestamp = (publication.metadata_xml.partition( - '<timestamp>'))[2].partition('</timestamp>')[0] - doi_batch_id = (publication.metadata_xml.partition( - '<doi_batch_id>'))[2].partition('</doi_batch_id>')[0] - path = (settings.MEDIA_ROOT + publication.in_issue.path + '/' - + publication.get_paper_nr() + '/' + publication.doi_label.replace('.', '_') - + '_' + timestamp + '.xml') - deposit = Deposit(publication=publication, timestamp=timestamp, doi_batch_id=doi_batch_id, - metadata_xml=publication.metadata_xml, deposition_date=timezone.now()) - deposit.metadata_xml_file.save(path, content) - deposit.response_text = r.text - deposit.save() - publication.latest_crossref_deposit = timezone.now() - publication.save() + content = ContentFile(publication.metadata_xml) + timestamp = (publication.metadata_xml.partition( + '<timestamp>'))[2].partition('</timestamp>')[0] + doi_batch_id = (publication.metadata_xml.partition( + '<doi_batch_id>'))[2].partition('</doi_batch_id>')[0] + path = (settings.MEDIA_ROOT + publication.in_issue.path + '/' + + publication.get_paper_nr() + '/' + publication.doi_label.replace('.', '_') + + '_' + timestamp + '.xml') + deposit = Deposit(publication=publication, timestamp=timestamp, doi_batch_id=doi_batch_id, + metadata_xml=publication.metadata_xml, deposition_date=timezone.now()) + deposit.metadata_xml_file.save(path, content) + deposit.response_text = r.text + deposit.save() + publication.latest_crossref_deposit = timezone.now() + publication.save() context = { 'option': option, @@ -635,7 +635,7 @@ def metadata_xml_deposit(request, doi_label, option='test'): @permission_required('scipost.can_publish_accepted_submission', return_403=True) -def mark_deposit_success(deposit_id, success): +def mark_deposit_success(request, deposit_id, success): deposit = get_object_or_404(Deposit, pk=deposit_id) if success == '1': deposit.deposit_successful = True -- GitLab