Newer
Older
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
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
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
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'
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
1119
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')