Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import uuid
3from django.db import models
4from django.utils.html import format_html
5from django_bleach.models import BleachField
7from . import validators
10class Publication(models.Model):
11 class Meta:
12 ordering = ["authors_text", "title"]
14 uuid = models.UUIDField(default=uuid.uuid4, editable=False)
15 title = models.CharField(
16 max_length=200,
17 help_text='Title (including subtitle, seperated with ":")',
18 verbose_name="Title",
19 )
20 authors_text = models.CharField(
21 max_length=200,
22 help_text="Example: Andreas Heinrich, Felix Herrmann, Heiko Pleines",
23 verbose_name="Authors",
24 )
25 places_text = models.CharField(max_length=200, blank=True, verbose_name="Place")
26 publisher_text = models.CharField(
27 max_length=200, blank=True, verbose_name="Publisher"
28 )
29 included_text = models.CharField(
30 max_length=200,
31 blank=True,
32 help_text="Collection title, Journal issue, etc.",
33 verbose_name="Included in",
34 )
35 year = models.CharField(max_length=20)
36 url = models.URLField(blank=True)
37 isbn = models.CharField(
38 max_length=20,
39 blank=True,
40 validators=[validators.validate_isbn],
41 )
42 doi = models.CharField(
43 max_length=200,
44 blank=True,
45 validators=[validators.validate_doi],
46 )
47 pages = models.CharField(max_length=200, blank=True)
48 description = BleachField(
49 blank=True,
50 help_text="Additional information about the publication",
51 )
53 # authors = models.ManyToManyField('Person', related_name='publication_authors_person', blank=True)
54 # editors = models.ManyToManyField('Person', related_name='publication_editors_person', blank=True)
55 # places = models.ManyToManyField('Place', blank=True)
56 # publisher = models.ForeignKey('Publisher', blank=True, null=True, on_delete=models.PROTECT)
57 # date = models.DateField(blank=True, null=True)
58 # issn = models.CharField(max_length=200, blank=True)
59 # issue = models.CharField(max_length=200, blank=True)
60 # volume = models.CharField(max_length=200, blank=True)
62 # included_in = models.ForeignKey('Publication', blank=True, null=True, on_delete=models.PROTECT, related_name='publication_included_in_publication')
64 def short_citation(self):
65 return "{}, {}, {}".format(self.authors_text, self.title, self.year)
67 def citation(self):
68 citation_list = list()
69 if self.included_text:
70 citation_list.append("in: {}".format(self.included_text))
71 if self.publisher_text and self.places_text:
72 citation_list.append("{}: {}".format(self.publisher_text, self.places_text))
73 elif self.places_text:
74 citation_list.append(self.places_text)
75 elif self.publisher_text:
76 citation_list.append(self.publisher_text)
77 else:
78 pass
79 if self.year:
80 citation_list.append(self.year)
81 if self.pages:
82 citation_list.append(self.pages)
83 if self.doi:
84 doi_url = "http://doi.org/{}".format(self.doi)
85 citation_list.append(doi_url)
86 if self.isbn:
87 isbn_str = "ISBN: {}".format(self.isbn)
88 citation_list.append(isbn_str)
89 if self.url:
90 citation_list.append(self.url)
92 return format_html(
93 "<i>{}</i>, {}, {}", self.authors_text, self.title, ", ".join(citation_list)
94 )
96 def __str__(self):
97 # return '{}: {} ({})'.format(self.get_authors(), self.title, self.get_pub_type_display())
98 return self.title
100 # def get_authors(self):
101 # alist = list()
102 # for a in self.authors.all():
103 # alist.append(a.name)
104 # return ','.join(alist)
107class Person(models.Model):
108 name = models.CharField(max_length=200)
109 firstnames = models.CharField(max_length=200)
111 def __str__(self):
112 return self.name
115class Place(models.Model):
116 name = models.CharField(max_length=200)
118 def __str__(self):
119 return self.name
122class Publisher(models.Model):
123 name = models.CharField(max_length=200)
125 def __str__(self):
126 return self.name