Esempio n. 1
0
 def __unicode__(self):
     parts = [u"%s" % self.issue.title]
     # little hack to get django's datetime support for stftime
     # when the year is < 1900
     parts.append(strftime(self.issue.date_issued, "%B %d, %Y"))
     if self.issue.edition_label:
         parts.append(self.issue.edition_label)
     if self.section_label:
         parts.append(self.section_label)
     parts.append("Image %s" % self.sequence)
     return u", ".join(parts)
Esempio n. 2
0
 def json(self, host, serialize=True):
     j = {
         "sequence": self.sequence,
         "issue": {
             "date_issued": strftime(self.issue.date_issued, "%Y-%m-%d"),
             "url": "http://" + host + self.issue.json_url,
         },
         "jp2": "http://" + host + self.jp2_url,
         "ocr": "http://" + host + self.ocr_url,
         "text": "http://" + host + self.txt_url,
         "pdf": "http://" + host + self.pdf_url,
         "title": {"name": self.issue.title.display_name, "url": "http://" + host + self.issue.title.json_url},
     }
     if serialize:
         return json.dumps(j, indent=2)
     return j
Esempio n. 3
0
    def json(self, host, serialize=True, include_pages=True):
        j = {
            "url": "http://" + host + self.json_url,
            "date_issued": strftime(self.date_issued, "%Y-%m-%d"),
            "volume": self.volume,
            "number": self.number,
            "edition": self.edition,
            "title": {"name": self.title.display_name, "url": "http://" + host + self.title.json_url},
            "batch": {"name": self.batch.name, "url": "http://" + host + self.batch.json_url},
        }

        j["pages"] = [{"url": "http://" + host + p.json_url, "sequence": p.sequence} for p in self.pages.all()]

        if serialize:
            return json.dumps(j, indent=2)
        return j
Esempio n. 4
0
    def json(self, host, serialize=True):
        j = {
            "url": "http://" + host + self.json_url,
            "lccn": self.lccn,
            "name": self.display_name,
            "place_of_publication": self.place_of_publication,
            "publisher": self.publisher,
            "start_year": self.start_year,
            "end_year": self.end_year,
            "subject": [s.heading for s in self.subjects.all()],
            "place": [p.name for p in self.places.all()],
            "issues": [
                {"url": "http://" + host + i.json_url, "date_issued": strftime(i.date_issued, "%Y-%m-%d")}
                for i in self.issues.all()
            ],
        }

        if serialize:
            return json.dumps(j, indent=2)
        return j
Esempio n. 5
0
 def json(self, host, include_issues=True, serialize=True):
     b = {}
     b["name"] = self.name
     b["ingested"] = rfc3339(self.created)
     b["page_count"] = self.page_count
     b["lccns"] = self.lccns()
     b["awardee"] = {"name": self.awardee.name, "url": "http://" + host + self.awardee.json_url}
     b["url"] = "http://" + host + self.json_url
     if include_issues:
         b["issues"] = []
         for issue in self.issues.all():
             i = {
                 "title": {"name": issue.title.display_name, "url": "http://" + host + issue.title.json_url},
                 "date_issued": strftime(issue.date_issued, "%Y-%m-%d"),
                 "url": "http://" + host + issue.json_url,
             }
             b["issues"].append(i)
     if serialize:
         return json.dumps(b)
     else:
         return b