本文整理汇总了Python中papers.models.Paper类的典型用法代码示例。如果您正苦于以下问题:Python Paper类的具体用法?Python Paper怎么用?Python Paper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_object
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
pk = self.kwargs.get('pk', None)
doi = self.kwargs.get('doi', None)
if doi:
doi = unquote(doi)
doi = to_doi(doi)
paper = None
try:
if pk is not None:
paper = queryset.get(pk=pk)
elif doi is not None:
paper = Paper.get_by_doi(doi)
else:
raise Http404(_("Paper view expects a DOI or a pk"))
except ObjectDoesNotExist:
pass
if not paper:
paper = Paper.create_by_doi(doi)
if paper is None or paper.is_orphan():
raise Http404(_("No %(verbose_name)s found matching the query") %
{'verbose_name': Paper._meta.verbose_name})
if not paper.visible:
raise Http404(_("This paper has been deleted."))
return paper
示例2: test_unmerge_orcid_nones
def test_unmerge_orcid_nones(self):
# First, fetch a few DOIs
dois = [
"10.1075/aicr.90.09ngo",
"10.1075/aicr.90.04wad",
]
for doi in dois:
Paper.create_by_doi(doi)
# Then, fetch an ORCID profile with a buggy version of the ORCID interface, which incorrectly merges papers together
with patch.object(OrcidPaperSource, '_oai_id_for_doi') as mock_identifier:
mock_identifier.return_value = "https://pub.orcid.org/v2.1/0000-0002-1909-134X/work/None"
profile = OrcidProfileStub('0000-0002-1909-134X', instance='orcid.org')
trung = Researcher.get_or_create_by_orcid('0000-0002-1909-134X', profile=profile)
OrcidPaperSource().fetch_and_save(trung, profile=profile)
# The two papers are incorrectly merged!
papers = [Paper.get_by_doi(doi) for doi in dois]
self.assertEqual(papers[0], papers[1])
# We unmerge them
unmerge_orcid_nones()
# The two papers are now distinct
papers = [Paper.get_by_doi(doi) for doi in dois]
self.assertTrue(papers[0] != papers[1])
示例3: test_query
def test_query(self):
invalid_payloads = [
'test', '{}',
'{"doi":"anurisecbld"}',
'{"title":""}',
'{"title":"this is a test"}',
'{"title":"this is a test","date":"aunriset"}',
'{"title":"this is a test","date":"2008"}',
'{"title":"this is a test","date":"2008","authors":"test"}',
'{"title":"this is a test","date":"2008-03","authors":[]}',
'{"title":"this is a test","date":"2008-03","authors":["lsc"]}',
'{"title":"test","date":"2008-03","authors":[{"error":"test"}]}',
]
for payload in invalid_payloads:
self.checkJson(self.postPage('api-paper-query', postargs=payload,
postkwargs={'content_type': 'application/json'}), 400)
# Paper not found
payload = '{"title":"Refining the Conceptualization of a Future-Oriented Self-Regulatory Behavior: Proactive Coping", "date":"2009-07-01","authors":[{"first":"Stephanie Jean","last":"Sohl"},{"first":"Anne","last":"Moyer"}]}'
self.checkJson(self.postPage('api-paper-query', postargs=payload,
postkwargs={'content_type': 'application/json'}), 404)
Paper.create_by_doi('10.1016/j.paid.2009.02.013')
# Paper now found
self.checkJson(self.postPage('api-paper-query', postargs=payload,
postkwargs={'content_type': 'application/json'}), 200)
self.checkJson(self.postPage('api-paper-query', postargs='{"doi":"10.1016/j.paid.2009.02.013"}',
postkwargs={'content_type': 'application/json'}), 200)
示例4: test_email_has_more_than_five_questions_with_three_questions
def test_email_has_more_than_five_questions_with_three_questions(self):
'''
Method will return true if 5 or more papers exist for a certain e-mail.
E-Mail is passed as a string for a count query. Creating 3 papers.
'''
sent_from = Sender(email="[email protected]", ip="10.10.50.50")
sent_from.save()
for x in range(3):
paper = Paper(sender=sent_from, sent_to="[email protected]", active_until=timezone.now())
paper.save()
self.assertEqual(email_has_more_than_five_questions_open('[email protected]'), False)
示例5: unmerge_paper_by_dois
def unmerge_paper_by_dois(paper):
"""
Given a paper that was merged by mistake, delete it and re-create
it with each DOI found in it.
"""
dois = [record.doi for record in paper.oairecords if record.doi]
paper.delete()
for doi in dois:
try:
Paper.create_by_doi(doi)
except ValueError:
continue
示例6: setUp
def setUp(self):
#Create test user but don't login.
self.user = User.objects.create_user('test', '[email protected]', 'test')
self.data = {'user': self.user, 'title': 'Test Title', 'url':
'http://example.com', 'journal': 'Journal of Test', 'year':
'2011', 'volume': '1', 'authors':
"Author One\nAuthor Two\nAuthor Three", 'issue': '2', 'pages':
'3-4', }
p = Paper(**self.data) #unpack dictionary to arguments
p.save()
示例7: test_ingest_dump
def test_ingest_dump(self):
doi = '10.1080/21645515.2017.1330236'
p = Paper.create_by_doi(doi)
self.assertEqual(p.pdf_url, None)
Paper.create_by_doi(doi)
# then load an OAdoi dump
oadoi = OadoiAPI()
oadoi.load_dump(os.path.join(self.testdir, 'data/sample_unpaywall_snapshot.jsonl.gz'))
# the paper is now OA, yay!
p = Paper.get_by_doi(doi)
self.assertEqual(p.pdf_url, 'http://europepmc.org/articles/pmc5718814?pdf=render')
示例8: test_multiple_get_or_create
def test_multiple_get_or_create(self):
date = datetime.date(year=2003, month=4, day=9)
paper = Paper.get_or_create('Beta-rays in black pudding',
list(map(Name.lookup_name, [
('F.', 'Rodrigo'), ('A.', 'Johnson'), ('Pete', 'Blunsom')])),
date)
paper2 = Paper.get_or_create('Beta-rays in black pudding',
list(map(Name.lookup_name, [
('Frank', 'Rodrigo'), ('A. L.', 'Johnson'), ('P.', 'Blunsom')])),
date)
self.assertEqual(paper.pk, paper2.pk)
self.assertEqual(Paper.objects.get(pk=paper.pk).bare_author_names(),
[('Frank', 'Rodrigo'), ('A. L.', 'Johnson'), ('Pete', 'Blunsom')])
示例9: api_paper_doi
def api_paper_doi(request, doi):
p = None
try:
p = Paper.get_by_doi(doi)
if not p:
p = Paper.create_by_doi(doi)
except MetadataSourceException:
pass
if p is None:
return JsonResponse({
'error': 404,
'message': 'The paper you requested could not be found.',
}, status=404)
return api_paper_common(request, p)
示例10: test_fetch
def test_fetch(self):
profile = OrcidProfileStub('0000-0002-8612-8827', instance='orcid.org')
papers = list(self.source.fetch_papers(self.researcher, profile=profile))
for paper in papers:
paper = Paper.from_bare(paper)
self.assertTrue(len(papers) > 1)
self.check_papers(papers)
示例11: fetch_and_save_new_records
def fetch_and_save_new_records(self, starting_cursor='*', batch_time=datetime.timedelta(days=1)):
"""
Fetches and stores all new Crossref records updated since the
last update time of the associated OaiSource.
"""
source = OaiSource.objects.get(identifier='crossref')
# We substract one day to 'until-update-date' parameter as it is inclusive
one_day = datetime.timedelta(days=1)
while source.last_update + batch_time < timezone.now():
last_updated = source.last_update
until_date = (last_updated + batch_time - one_day).date()
to_update = self.fetch_all_records(
filters={'from-update-date':last_updated.date().isoformat(),
'until-update-date':until_date.isoformat()},
cursor=starting_cursor)
for record in to_update:
try:
bare_paper = self.save_doi_metadata(record)
p = Paper.from_bare(bare_paper)
p.update_index()
except ValueError as e:
logger.info(record.get('DOI', 'unkown DOI') + ': %s' % e)
logger.info("Updated up to" + until_date.isoformat())
source.last_update += batch_time
source.save()
示例12: test_paper_already_in_hal_but_not_in_dissemin
def test_paper_already_in_hal_but_not_in_dissemin(self):
"""
In this case, Dissemin missed the paper on HAL
(for some reason) and so the deposit interface was
enabled. But HAL refuses the deposit! We have to
give a good error message to the user.
"""
# this paper is currently in HAL-preprod
p = Paper.create_by_doi('10.1051/jphys:01975003607-8060700')
# this is just to make sure that we are depositing with
# a single author (otherwise, the deposit would fail because
# we are not providing enough affiliations).
p.authors_list = [p.authors_list[0]]
r = self.dry_deposit(p,
abstract='this is an abstract',
topic='INFO',
depositing_author=0,
affiliation=59704) # ENS
# Deposit fails: a duplicate is found
self.assertEqualOrLog(r.status, 'failed')
# The error message should be specific
self.assertTrue('already in HAL' in r.message)
示例13: fetch_and_save
def fetch_and_save(self, researcher, incremental=False):
"""
Fetch papers and save them to the database.
:param incremental: When set to true, papers are clustered
and commited one after the other. This is useful when
papers are fetched on the fly for an user.
"""
if self.ccf is None:
raise ValueError('Clustering context factory not provided')
for p in self.fetch_bare(researcher):
# Save the paper as non-bare
p = Paper.from_bare(p)
# If clustering happens incrementally, cluster the researcher
if incremental:
self.ccf.clusterPendingAuthorsForResearcher(researcher)
researcher.update_stats()
# Check whether this paper is associated with an ORCID id
# for the target researcher
if researcher.orcid:
matches = filter(lambda a: a.orcid == researcher.orcid, p.authors)
if matches:
self.update_empty_orcid(researcher, False)
if self.max_results is not None and count >= self.max_results:
break
示例14: test_refresh_deposit_status
def test_refresh_deposit_status(self):
# This is the identifier of a paper which should
# currently be published on HAL preprod
hal_id = 'hal-01211282'
# First, fake the deposition of a paper
p = Paper.create_by_doi('10.1109/lics.2015.37')
r = OaiRecord.new(source=self.repo.oaisource,
identifier='deposition:1:'+hal_id,
splash_url='https://hal-preprod.archives-ouvertes.fr/'+hal_id,
pdf_url=None,
about=p)
f = UploadedPDF.objects.create(
user=self.user,
orig_name='File.pdf',
file=os.path.join(self.testdir, 'testdata/blank.pdf'),
thumbnail='my_thumbnail.png')
d = DepositRecord.objects.create(
paper=p,
oairecord=r,
repository=self.repo,
user=self.user,
status='pending',
identifier=hal_id,
upload_type='postprint',
file=f)
self.proto.refresh_deposit_status(d)
self.assertEqual(d.status, 'published')
self.assertTrue(r.pdf_url)
示例15: test_invisible_paper
def test_invisible_paper(self):
"""
If a paper is marked as invisible, then accessing it returns 404
"""
p = Paper.create_by_doi('10.1007/978-3-642-14363-2_7')
p.visible = False
p.save()
self.check404('paper', kwargs={'pk': p.id, 'slug': p.slug})