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
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
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.
"""
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)
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.0" xmlns="http://www.crossref.org/schema/4.4.0" '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
'xmlns:fr="http://www.crossref.org/fundref.xsd" '
'xsi:schemaLocation="http://www.crossref.org/schema/4.4.0 '
'http://www.crossref.org/shema/deposit/crossref4.4.0.xsd" '
'xmlns:ai="http://www.crossref.org/AccessIndicators.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'
'<body>\n'
'<database>\n'
'<database_metadata language="en">\n'
'<titles><title>SciPost Reports and Comments</title></titles>\n'
'</database_metadata>\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'
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
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')