Guest User

Untitled

a guest
Jul 17th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.94 KB | None | 0 0
  1. from django.db import models
  2. from django.utils.translation import ugettext_lazy as _
  3. from django.core.validators import RegexValidator
  4. from django.template.defaultfilters import slugify
  5. from django_countries.fields import CountryField
  6.  
  7. from model_utils import Choices
  8. from filebrowser.fields import FileBrowseField
  9. try:
  10. from south.modelsinspector import add_introspection_rules
  11. add_introspection_rules([], ["^filebrowser\.fields\.FileBrowseField"])
  12. except:
  13. pass
  14.  
  15. from academic.utils import *
  16. from academic.organizations.models import *
  17. from academic.people.models import *
  18.  
  19. class Conference(models.Model):
  20. class Meta:
  21. ordering = [
  22. 'acronym',
  23. 'name', ]
  24.  
  25. name = models.CharField(
  26. _('Name'),
  27. help_text=_('E.g., Recent Advances in Intrusion Detection'),
  28. max_length=256,
  29. unique=True,
  30. db_index=True)
  31. acronym = models.CharField(
  32. max_length=16,
  33. unique=True,
  34. help_text=_('E.g., RAID, IMC, EC2ND, CCS, SSP'),
  35. validators=[RegexValidator(regex=r'^([0-9A-Za-z]+[ ]?)+$')])
  36.  
  37. def __unicode__(self):
  38. if self.acronym != '':
  39. return self.acronym
  40. return self.name
  41.  
  42.  
  43. class ConferenceEdition(models.Model):
  44. class Meta:
  45. ordering = [
  46. '-year',
  47. '-month',
  48. 'conference__acronym',
  49. 'conference__name',]
  50. unique_together = (
  51. 'conference',
  52. 'year',)
  53.  
  54. conference = models.ForeignKey(
  55. Conference)
  56. edition_number = models.PositiveSmallIntegerField(
  57. help_text=_('E.g., "13" as in "Proceedings of the 13th Symposioum on ..."'),
  58. blank=True,
  59. null=True,
  60. db_index=True)
  61. month = models.PositiveSmallIntegerField(
  62. choices=MONTHS,
  63. blank=True,
  64. null=True,
  65. db_index=True)
  66. year = models.CharField(
  67. max_length=4,
  68. choices=YEARS,
  69. help_text=_('Year of the event'),
  70. db_index=True)
  71. address = models.TextField(
  72. _('Venue'),
  73. help_text=_('Conference location.'),
  74. blank=True,
  75. null=True)
  76. web_page = models.URLField(
  77. _('Web page'),
  78. blank=True,
  79. null=True)
  80. slug = models.SlugField(
  81. max_length=512,
  82. editable=False,
  83. db_index=True)
  84.  
  85. def __unicode__(self):
  86. return u'%s %s' % (self.conference, self.year)
  87.  
  88. def save(self, **kwargs):
  89. if len(self.slug) == 0:
  90. self.slug = slugify('%s %s' % (self.conference.acronym, self.year))
  91. super(ConferenceEdition, self).save(**kwargs)
  92.  
  93.  
  94. class Publication(models.Model):
  95. """
  96. A scientific publication.
  97. """
  98.  
  99. class Meta:
  100. unique_together = (
  101. ('title',
  102. 'year'), )
  103. verbose_name = _('Publication')
  104. verbose_name_plural = _('Publications')
  105. ordering = ['-year',]
  106.  
  107. title = models.CharField(
  108. _('Title'),
  109. max_length=1024)
  110. year = models.CharField(
  111. max_length=4,
  112. choices=YEARS,
  113. help_text=_('Year of publication'),
  114. db_index=True)
  115. month = models.PositiveSmallIntegerField(
  116. choices=MONTHS,
  117. db_index=True,
  118. null=True,
  119. blank=True)
  120. authors = models.ManyToManyField(
  121. Person,
  122. related_name='publications',
  123. through='Authorship',
  124. blank=True,
  125. null=True)
  126. attachment = FileBrowseField(
  127. _('Attachment'),
  128. max_length=256,
  129. format='File',
  130. blank=True,
  131. null=True)
  132. notes = models.CharField(
  133. _('Notes'),
  134. max_length=512,
  135. help_text=_('Notes, e.g., about the conference or the journal.'),
  136. blank=True,
  137. null=True)
  138. bibtex = models.TextField(
  139. verbose_name=_('BibTeX Entry'),
  140. help_text=_(
  141. 'At this moment, the BibTeX is not parsed for content.'\
  142. 'This will override the auto-generated BibTeX.'),
  143. blank=True,
  144. null=True)
  145. abstract = models.TextField(
  146. _('Abstract'),
  147. blank=True,
  148. null=True)
  149. fulltext = FileBrowseField(
  150. _('Fulltext'),
  151. max_length=256,
  152. format='Document',
  153. blank=True,
  154. null=True)
  155. date_updated = models.DateField(
  156. _('Last updated on'),
  157. auto_now=True,
  158. db_index=True)
  159. slug = models.SlugField(
  160. help_text=_('This is autofilled, then you may modify it if you wish.'),
  161. editable=False,
  162. unique=True,
  163. max_length=512,
  164. db_index=True)
  165.  
  166. def _get_subclass(self):
  167. for related_object in self._meta.get_all_related_objects():
  168. if not issubclass(related_object.model, self.__class__):
  169. continue
  170.  
  171. return related_object.__class__
  172. subclass = property(_get_subclass)
  173.  
  174. def _get_first_author(self):
  175. authorships = self.authorship_set.all()
  176. if authorships.count() > 0:
  177. return authorships[0].person
  178. return None
  179. first_author = property(_get_first_author)
  180.  
  181. def _get_author_list(self):
  182. author_list = ', '.join(map(
  183. lambda m:m.person.name , self.authorship_set.all()))
  184. return author_list
  185. author_list = property(_get_author_list)
  186.  
  187. @models.permalink
  188. def get_bibtex_url(self):
  189. return ('academic_publishing_publication_detail_bibtex', (), {
  190. 'slug': self.slug})
  191.  
  192. @models.permalink
  193. def get_absolute_url(self):
  194. return ('academic_publishing_publication_detail', (), {'slug': self.slug})
  195.  
  196. def __unicode__(self):
  197. return u'%s %s' % (
  198. self.title,
  199. self.year)
  200.  
  201. def save(self, *args, **kwargs):
  202. if len(self.slug) == 0:
  203. self.slug = slugify('%s %s %s' % (
  204. self.first_author or '',
  205. self.title,
  206. self.year))
  207. super(Publication, self).save(**kwargs)
  208.  
  209. class Authorship(models.Model):
  210. class Meta:
  211. ordering = ('order',)
  212. person = models.ForeignKey(Person)
  213. publication = models.ForeignKey(Publication)
  214. order = models.PositiveSmallIntegerField()
  215.  
  216.  
  217. class Book(Publication):
  218. editors = models.ManyToManyField(
  219. Person,
  220. related_name='proceedings',
  221. through='Editorship',
  222. blank=True,
  223. null=True)
  224. publisher = models.ForeignKey(
  225. Publisher,
  226. related_name='books',
  227. blank=True,
  228. null=True)
  229. volume = models.CharField(
  230. max_length=128,
  231. blank=True,
  232. null=True)
  233. number = models.CharField(
  234. max_length=128,
  235. blank=True,
  236. null=True)
  237. address = models.TextField(
  238. _('Address'),
  239. help_text=_('Conference location.'),
  240. blank=True,
  241. null=True)
  242. edition = models.CharField(
  243. max_length=128,
  244. blank=True,
  245. null=True,
  246. help_text=_('E.g., First, Second, II, 2, Second edition.'))
  247.  
  248.  
  249. class Editorship(models.Model):
  250. class Meta:
  251. ordering = ('order',)
  252. person = models.ForeignKey(Person)
  253. publication = models.ForeignKey(Book)
  254. order = models.PositiveSmallIntegerField()
  255.  
  256.  
  257. class Journal(Book):
  258. def save(self, *args, **kwargs):
  259. self.subclass = 'Journal'
  260. super(Journal, self).save()
  261.  
  262.  
  263. class BookChapter(Book):
  264. chapter = models.CharField(
  265. max_length=128)
  266. pages = models.CharField(
  267. blank=True,
  268. null=True,
  269. max_length=32,
  270. help_text=_('E.g., 12-20'),
  271. validators=[RegexValidator(regex=r'[0-9]+\-[0-9]+')])
  272.  
  273. def save(self, *args, **kwargs):
  274. self.subclass = 'BookChapter'
  275. super(BookChapter, self).save()
  276.  
  277. class JournalArticle(Publication):
  278. class Meta:
  279. verbose_name_plural = _('Journal papers')
  280. verbose_name = _('Journal paper')
  281.  
  282. journal = models.ForeignKey(
  283. Journal)
  284.  
  285. class ConferenceProceedings(Book):
  286. class Meta:
  287. verbose_name = _('Proceedings')
  288. verbose_name_plural = _('Proceedings')
  289. conference_edition = models.ForeignKey(
  290. ConferenceEdition)
  291.  
  292. def __unicode__(self):
  293. return u'%s %s (proceedings)' % (self.title, self.year)
  294.  
  295.  
  296. class ConferenceArticle(Publication):
  297. class Meta:
  298. verbose_name_plural = _('Conference papers')
  299. verbose_name = _('Conference paper')
  300. presentation = FileBrowseField(
  301. _('Presentation'),
  302. max_length=256,
  303. format='Document',
  304. blank=True,
  305. null=True)
  306. crossref = models.ForeignKey(
  307. ConferenceProceedings,
  308. verbose_name=_('Conference proceedings'),
  309. null=True,
  310. blank=True)
  311.  
  312.  
  313. class TechnicalReport(Publication):
  314. institution = models.ManyToManyField(
  315. Institution)
  316.  
  317.  
  318. class Thesis(Publication):
  319. school = models.ForeignKey(
  320. School)
  321. advisors = models.ManyToManyField(
  322. Person,
  323. through='Advisorship',
  324. related_name='advised_theses')
  325. co_advisors = models.ManyToManyField(
  326. Person,
  327. through='Coadvisorship',
  328. blank=True,
  329. null=True,
  330. related_name='coadvised_theses')
  331.  
  332.  
  333. class Advisorship(models.Model):
  334. class Meta:
  335. ordering = ('order',)
  336. person = models.ForeignKey(Person)
  337. publication = models.ForeignKey(Thesis)
  338. order = models.PositiveSmallIntegerField()
  339.  
  340.  
  341. class Coadvisorship(models.Model):
  342. class Meta:
  343. ordering = ('order',)
  344. person = models.ForeignKey(Person)
  345. publication = models.ForeignKey(Thesis)
  346. order = models.PositiveSmallIntegerField()
  347.  
  348.  
  349. class MasterThesis(Thesis):
  350. class Meta:
  351. verbose_name_plural = 'Master theses'
  352. verbose_name = 'Master thesis'
  353. pass
  354.  
  355.  
  356. class PhdThesis(Thesis):
  357. class Meta:
  358. verbose_name_plural = _('PhD theses')
  359. verbose_name = _('PhD thesis')
  360. reviewers = models.ManyToManyField(
  361. Person,
  362. through='Reviewing',
  363. related_name='reviewed_phdtheses',
  364. blank=True,
  365. null=True)
  366.  
  367.  
  368. class Reviewing(models.Model):
  369. person = models.ForeignKey(Person)
  370. publication = models.ForeignKey(PhdThesis)
  371. order = models.PositiveSmallIntegerField()
Add Comment
Please, Sign In to add comment