Newer
Older
@permission_required('scipost.can_publish_accepted_submission', return_403=True)
@transaction.atomic
def generic_metadata_xml_deposit(request, **kwargs):
"""
This method creates the metadata for non-Publication objects
such as Reports and Comments, and deposits the metadata to
Crossref.
If there exists a relation to a SciPost-published object,
the deposit uses Crossref's peer review content type.
Otherwise the deposit is done as a dataset.
"""
type_of_object = kwargs['type_of_object']
object_id = int(kwargs['object_id'])
if type_of_object == 'report':
_object = get_object_or_404(Report, id=object_id)
elif type_of_object == 'comment':
_object = get_object_or_404(Comment, id=object_id)
relation_to_published = _object.relation_to_published
_object.create_doi_label()
# create a doi_batch_id
salt = ""
for i in range(5):
salt = salt + random.choice(string.ascii_letters)
salt = salt.encode('utf8')
idsalt = str(_object)[:10]
idsalt = idsalt.encode('utf8')
timestamp = timezone.now().strftime('%Y%m%d%H%M%S')
doi_batch_id = hashlib.sha1(salt+idsalt).hexdigest()
metadata_xml = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
'<doi_batch version="4.4.1" xmlns="http://www.crossref.org/schema/4.4.1" '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
'xsi:schemaLocation="http://www.crossref.org/schema/4.4.1 '
'http://www.crossref.org/shema/deposit/crossref4.4.1.xsd">\n'
'<head>\n'
'<doi_batch_id>' + str(doi_batch_id) + '</doi_batch_id>\n'
'<timestamp>' + timestamp + '</timestamp>\n'
'<depositor>\n'
'<depositor_name>scipost</depositor_name>\n'
'<email_address>' + settings.CROSSREF_DEPOSIT_EMAIL + '</email_address>\n'
'</depositor>\n'
'<registrant>scipost</registrant>\n'
'</head>\n'
)
if relation_to_published:
metadata_xml += (
'<body>\n'
'<peer_review stage="' + relation_to_published['stage'] + '">\n'
'<contributors>'
if _object.anonymous:
metadata_xml += (
'<anonymous sequence="first" contributor_role="'
+ relation_to_published['contributor_role'] + '"/>'
else:
metadata_xml += (
'<person_name sequence="first" contributor_role="'
+ relation_to_published['contributor_role'] + '">'
'<given_name>' + _object.author.user.first_name + '</given_name>'
'<surname>' + _object.author.user.last_name + '</surname>'
'</person_name>\n'
)
if isinstance(_object, Publication):
url_to_declare = 'https://scipost.org{}'.format(_object.get_absolute_url())
else:
url_to_declare = 'https://scipost.org/{}'.format(_object.doi_label)
metadata_xml += (
'</contributors>\n'
'<titles><title>' + relation_to_published['title'] + '</title></titles>\n'
'<month>' + _object.date_submitted.strftime('%m') + '</month>'
'<day>' + _object.date_submitted.strftime('%d') + '</day>'
'<year>' + _object.date_submitted.strftime('%Y') + '</year>'
'</review_date>\n'
'<program xmlns="http://www.crossref.org/relations.xsd">\n'
'<related_item>'
'<description>' + relation_to_published['title'] + '</description>\n'
'<inter_work_relation relationship-type="isReviewOf" identifier-type="doi">'
+ relation_to_published['isReviewOfDOI'] + '</inter_work_relation></related_item>\n'
'</program>'
'<doi_data><doi>' + _object.doi_string + '</doi>\n'
'</resource></doi_data>\n'
'</peer_review>\n'
'</body>\n'
'</doi_batch>\n'
)
else:
metadata_xml += (
'<body>\n'
'<database>\n'
'<database_metadata language="en">\n'
'<titles><title>SciPost Reports and Comments</title></titles>\n'
'</database_metadata>\n'
'<dataset dataset_type="collection">\n'
'<doi_data><doi>' + _object.doi_string + '</doi>\n'
'<resource>https://scipost.org' + _object.get_absolute_url() +
'</resource></doi_data>\n'
'</dataset></database>\n'
'</body></doi_batch>'
# CAUTION: Debug is False, production goes for real deposit!!!
url = 'http://doi.crossref.org/servlet/deposit'
else:
url = 'http://test.crossref.org/servlet/deposit'
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
params = {
'operation': 'doMDUpload',
'login_id': settings.CROSSREF_LOGIN_ID,
'login_passwd': settings.CROSSREF_LOGIN_PASSWORD,
}
files = {'fname': ('metadata.xml', metadata_xml, 'multipart/form-data')}
r = requests.post(url, params=params, files=files)
deposit = GenericDOIDeposit(content_type=ContentType.objects.get_for_model(_object),
object_id=object_id,
content_object=_object,
timestamp=timestamp,
doi_batch_id=doi_batch_id,
metadata_xml=metadata_xml,
deposition_date=timezone.now(),
response=r.text)
deposit.save()
context = {
'response_headers': r.headers,
'response_text': r.text,
}
return render(request, 'journals/generic_metadata_xml_deposit.html', context)
@permission_required('scipost.can_publish_accepted_submission', return_403=True)
def mark_generic_deposit_success(request, deposit_id, success):
deposit = get_object_or_404(GenericDOIDeposit, pk=deposit_id)
if success == '1':
deposit.deposit_successful = True
deposit.content_object.doideposit_needs_updating = False
deposit.content_object.save()
elif success == '0':
deposit.deposit_successful = False
deposit.save()
if deposit.content_type.name == 'report':
return redirect(reverse('journals:manage_report_metadata'))
else:
return redirect(reverse('journals:manage_comment_metadata'))
@permission_required('scipost.can_publish_accepted_submission', return_403=True)
def email_object_made_citable(request, **kwargs):
"""
This method sends an email to the author of a Report or a Comment,
to notify that the object has been made citable (doi registered).
"""
type_of_object = kwargs['type_of_object']
object_id = int(kwargs['object_id'])
if type_of_object == 'report':
_object = get_object_or_404(Report, id=object_id)
accepted_submission__preprint__identifier_wo_vn_nr=_object.submission.preprint.identifier_wo_vn_nr)
publication_citation = publication.citation
publication_doi = publication.doi_string
except Publication.DoesNotExist:
pass
elif type_of_object == 'comment':
_object = get_object_or_404(Comment, id=object_id)
redirect_to = reverse('journals:manage_comment_metadata')
else:
raise Http404
if not _object.doi_label:
messages.warning(request, 'This object does not have a DOI yet.')
return redirect(redirect_to)
if type_of_object == 'report':
JournalUtils.load({'report': _object,
'publication_citation': publication_citation,
'publication_doi': publication_doi})
JournalUtils.email_report_made_citable()
else:
JournalUtils.load({'comment': _object, })
JournalUtils.email_comment_made_citable()
messages.success(request, 'Email sent')
return redirect(redirect_to)
###########
# Viewing #
###########
def report_detail(request, doi_label):
report = get_object_or_404(Report.objects.accepted(), doi_label=doi_label)
return redirect(report.get_absolute_url())
def comment_detail(request, doi_label):
comment = get_object_or_404(Comment.objects.vetted().regular_comments(), doi_label=doi_label)
return redirect(comment.get_absolute_url())
def author_reply_detail(request, doi_label):
comment = get_object_or_404(Comment.objects.vetted().author_replies(), doi_label=doi_label)
return redirect(comment.get_absolute_url())
def publication_detail(request, doi_label):
"""
The actual Publication detail page. This is visible for everyone if published or
visible for Production Supervisors and Administrators if in draft.
"""
publication = get_object_or_404(Publication, doi_label=doi_label)
if not publication.is_published and not publication.status == PUBLICATION_PREPUBLISHED:
if not request.user.has_perm('scipost.can_draft_publication'):
raise Http404('Publication is not publicly visible')
if publication.in_issue:
journal = publication.in_issue.in_volume.in_journal
elif publication.in_journal:
journal = publication.in_journal
else:
raise Http404('Publication configuration is valid')
context = {
'publication': publication,
return render(request, 'journals/publication_detail.html', context)
def publication_detail_pdf(request, doi_label):
"""
The actual Publication pdf. This is visible for everyone if published or
visible for Production Supervisors and Administrators if in draft.
"""
publication = get_object_or_404(Publication, doi_label=doi_label)
if not publication.is_published and not request.user.has_perm('scipost.can_draft_publication'):
raise Http404('Publication is not publicly visible')
response = HttpResponse(publication.pdf_file.read(), content_type='application/pdf')
response['Content-Disposition'] = ('filename='
+ publication.doi_label.replace('.', '_') + '.pdf')
######################
# Feed DOIs to arXiv #
######################
def arxiv_doi_feed(request, doi_label):
"""
This method provides arXiv with the doi and journal ref of the 100 most recent
publications in the journal specified by doi_label.
"""
journal = get_object_or_404(Journal, doi_label=doi_label)
feedxml = ('<preprint xmlns="http://arxiv.org/doi_feed" '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
'identifier="SciPost.org ' + doi_label + ' arXiv.org DOI feed" '
'version="DOI SnappyFeed v1.0" '
'xsi:schemaLocation="http://arxiv.org/doi_feed '
'http://arxiv.org/schemas/doi_feed.xsd">')
now = timezone.now()
feedxml += '<date year="%s" month="%s" day="%s" />' % (now.strftime('%Y'),
now.strftime('%m'), now.strftime('%d'))
publications = Publication.objects.filter(
in_issue__in_volume__in_journal=journal).order_by('-publication_date')[:100]
for publication in publications:
feedxml += ('\n<article preprint_id="%s" doi="%s" journal_ref="%s" />' % (
publication.accepted_submission.preprint.identifier_wo_vn_nr, publication.doi_string,
feedxml += '\n</preprint>'
return HttpResponse(feedxml, content_type='text/xml')