"README.rst" did not exist on "452cae67201b3d9d048abc1c6d4cf5984885b10a"
Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
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
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
# 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><dataset>\n'
'<dataset_type>component<\dataset_type>\n'
'<doi_data><doi>' + _object.doi_string + '</doi>\n'
'<resource>' + _object.get_absolute_url() + '</resource>\n'
'</dataset></database>\n'
'</body></doi_batch>'
)
url = 'http://doi.crossref.org/servlet/deposit'
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
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')