Coverage for portality/crosswalks/atom.py: 91%
44 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-22 15:59 +0100
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-22 15:59 +0100
1from flask import url_for
2from portality.core import app
5class AtomCrosswalk(object):
6 """
7 ~~Atom:Crosswalk->Atom:Feature~~
8 ~~->Journal:Model~~
9 """
10 def crosswalk(self, atom_record):
11 entry = {}
12 b = atom_record.bibjson()
14 doaj_url = app.config['BASE_URL'] + url_for('doaj.toc', identifier=atom_record.toc_id) + "?rss"
16 title = b.title
17 issns = b.issns()
18 if len(issns) > 0:
19 title += " (" + ", ".join(issns) + ")"
21 summary = ""
22 if b.publisher:
23 summary += "Published by " + b.publisher
24 if b.institution:
25 if not b.publisher:
26 summary += "Published in " + b.institution
27 else:
28 summary += " in " + b.institution
29 if summary != "":
30 summary += "\n"
31 summary += "Added to DOAJ on " + atom_record.created_timestamp.strftime("%e %b %Y") + "\n"
32 lccs = b.lcc_paths()
33 if len(lccs) > 0:
34 summary += "LCC Subject Category: " + " | ".join(lccs)
36 if b.publisher is not None:
37 entry["author"] = b.publisher
38 else:
39 entry["author"] = app.config.get("SERVICE_NAME")
41 cats = []
42 for subs in b.subjects():
43 scheme = subs.get("scheme")
44 term = subs.get("term")
45 cats.append(scheme + ":" + term)
46 entry["categories"] = cats
48 entry["content_src"] = doaj_url
49 entry["alternate"] = doaj_url
51 entry["id"] = "urn:uuid:" + atom_record.id
53 urls = b.get_urls(urltype="homepage")
54 if len(urls) > 0:
55 entry['related'] = urls[0]
57 entry['rights'] = app.config['FEED_LICENCE']
59 entry['summary'] = summary
60 entry['title'] = title
61 entry['updated'] = atom_record.last_updated
63 return entry