Newer
Older
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
@login_required
def sign_existing_report(request, report_id):
"""
Allows the author of a Report, originally submitted anonymously,
to sign the Report.
"""
report = get_object_or_404(Report, pk=report_id)
if report.author != request.user.contributor:
errormessage = 'Only the author of this Report can change its anonymity status'
return render(request, 'scipost/error.html', context={'errormessage': errormessage})
form = ConfirmationForm(request.POST or None)
if form.is_valid():
if form.cleaned_data['confirm'] == 'True':
report.anonymous = False
report.doideposit_needs_updating = True
report.save()
messages.success(request, 'Your Report is now publicly signed.')
else:
messages.error(request, 'Report signing operation cancelled.')
return redirect(reverse('scipost:personal_page'))
context = {'report': report, 'form': form}
return render(request, 'journals/sign_existing_report.html', context)
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
@permission_required('scipost.can_publish_accepted_submission', return_403=True)
def manage_report_metadata(request):
"""
This page offers Editorial Administrators tools for managing
the metadata of Reports.
"""
reports = Report.objects.all()
context = {
'reports': reports,
}
return render(request, 'journals/manage_report_metadata.html', context)
@permission_required('scipost.can_publish_accepted_submission', return_403=True)
def manage_comment_metadata(request):
"""
This page offers Editorial Administrators tools for managing
the metadata of Comments.
"""
comments = Comment.objects.all()
context = {
'comments': comments,
}
return render(request, 'journals/manage_comment_metadata.html', context)
@permission_required('scipost.can_publish_accepted_submission', return_403=True)
def mark_report_doi_needed(request, report_id, needed):
report = get_object_or_404(Report, pk=report_id)
if needed == '1':
report.needs_doi = True
elif needed == '0':
report.needs_doi = False
report.save()
return redirect(reverse('journals:manage_report_metadata'))
@permission_required('scipost.can_publish_accepted_submission', return_403=True)
def mark_comment_doi_needed(request, comment_id, needed):
comment = get_object_or_404(Comment, pk=comment_id)
if needed == '1':
comment.needs_doi = True
elif needed == '0':
comment.needs_doi = False
comment.save()
return redirect(reverse('journals:manage_comment_metadata'))
@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'])
relation_to_published = _object.relation_to_published()
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)
if not _object.doi_label:
_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>admin@scipost.org</email_address>\n'
'</depositor>\n'
'<registrant>scipost</registrant>\n'
'</head>\n'
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
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
)
if relation_to_published:
metadata_xml += (
'<body>\n'
'<peer_review stage="' + relation['stage'] + '>\n'
'<contributors>'
)
if _object.anonymous:
metadata_xml += '<anonymous/>'
else:
metadata_xml += (
'<person_name>'
'<given_name>' + _object.author.user.first_name + '</given_name>'
'<surname>' + _object.author.user.last_name + '</surname>'
'</person_name>\n'
)
metadata_xml += (
'</contributors>\n'
'<titles><title>' + relation['title'] + '</title></titles>\n'
'<review_publication_date>'
'<year>' + _object.date_submitted.strftime('%Y') + '</year>'
'<month>' + _object.date_submitted.strftime('%m') + '</month>'
'<day>' + _object.date_submitted.strftime('%d') + '</day>'
'</review_publication_date>\n'
'<program xmlns="http://www.crossref.org/relations.xsd">\n'
'<related_item>'
'<description>' + relation['title'] + '</description>\n'
'<inter_work_relation relationship-type="isReviewOf" identifier-type="doi">'
+ relation['isReviewOfDOI'] + '</inter_work_relation></related_item>\n'
'</program>'
'<doi_data><doi>' + _object.doi_string + '</doi>\n'
'<resource>https://scipost.org' + _object.get_absolute_url() +
'</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>'
if not settings.DEBUG:
# CAUTION: Debug is False, production goes for real deposit!!!
url = 'http://doi.crossref.org/servlet/deposit'
else:
url = 'http://test.crossref.org/servlet/deposit'
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
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'))
###########
# Viewing #
###########
def publication_detail(request, doi_label):
publication = Publication.objects.get_published(doi_label=doi_label)
journal = publication.in_issue.in_volume.in_journal
context = {
'publication': publication,
return render(request, 'journals/publication_detail.html', context)
def publication_detail_pdf(request, doi_label):
publication = Publication.objects.get_published(doi_label=doi_label)
response = HttpResponse(publication.pdf_file.read(), content_type='application/pdf')
response['Content-Disposition'] = ('filename='
+ publication.doi_label.replace('.', '_') + '.pdf')