Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
django-tei-importer/eoa/models.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
301 lines (256 sloc)
8.4 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.utils import timezone | |
from django.core.validators import URLValidator, RegexValidator | |
from django.contrib.postgres.fields import HStoreField | |
################################################# | |
# | |
# file path should depend on instance type | |
# | |
################################################# | |
def filepath(instance, filename): | |
strPublicationSerie = instance.Publication.Serie | |
strPublicationNumber = str(instance.Publication.Number) | |
baseString = strPublicationSerie + "/" + strPublicationNumber + "/" | |
if instance.__class__.__name__ == Author: | |
strFilePath = 'authors' | |
elif instance.__class__.__name__ == Publication: | |
strFilePath = baseString + "/" + filename | |
elif instance.__class__.__name__ == Chapter: | |
strChapterOrder = str(instance.Order) | |
strFilePath = baseString + strChapterOrder + "/" + filename | |
return strFilePath | |
############################################ | |
# | |
# default settings which are used in several places | |
# | |
############################################ | |
series_choice = ( | |
('sources', 'Sources'), | |
('studies', 'Studies'), | |
('essays', 'Essays'), | |
('proceedings', 'Proceedings'), | |
('textbooks', 'Textbooks'), | |
) | |
citation_choice = ( | |
('book', 'Book'), | |
('journalArticle', 'Journal Article'), | |
('bookSection', 'Book Section'), | |
('thesis', 'Thesis'), | |
) | |
language_choice = ( | |
('de', 'German'), | |
('en', 'English'), | |
('it', 'Italian'), | |
) | |
tagname_choice = ( | |
('hi', 'Highlight'), | |
('foreign', 'Foreign'), | |
('ref', 'Reference'), | |
('note','Note'), | |
('label','Label'), | |
('language','Language'), | |
('graphic','Graphic'), | |
) | |
default_char = { | |
'max_length':200, | |
'default':None, | |
'blank':True, | |
'null':True, | |
} | |
validkeys = [ | |
'place', | |
'type', | |
'target', | |
'indexname', | |
'sortkey', | |
'xml:lang', | |
'pages', | |
'n', | |
'url', | |
'rendition', | |
'rend', | |
'height', | |
'notation' | |
] | |
########################################## | |
# | |
# basic information on publications, citations and authors | |
# | |
########################################### | |
class Publication(models.Model): | |
series = models.CharField( | |
max_length=20, | |
choices=series_choice, | |
default='sources') | |
language = models.CharField( | |
max_length=2, | |
choices=language_choice, | |
default='de') | |
published = models.BooleanField(default=False) | |
featured = models.BooleanField(default=False) | |
publication_id = models.IntegerField(default=None) | |
publisher = models.CharField(**default_char) | |
title = models.CharField(**default_char) | |
subtitle = models.CharField(**default_char) | |
description = models.TextField(blank=True) | |
pages = models.PositiveIntegerField() | |
price = models.FloatField() | |
created_date = models.DateField( | |
default =None, | |
null=True) | |
published_date = models.DateField( | |
blank=True, | |
null=True, | |
default=None) | |
def publish(self): | |
self.published_date = timezone.now() | |
self.save() | |
def __str__(self): | |
return self.title | |
class Meta: | |
ordering = ('title',) | |
class Citation(models.Model): | |
pubtype = models.CharField( | |
max_length=20, | |
choices=citation_choice, | |
default='book' | |
) | |
titlea = models.CharField(**default_char) | |
titlem = models.CharField(**default_char) | |
date = models.IntegerField( | |
blank=True, | |
null=False, | |
validators=[RegexValidator(r'^\d{4}$')]) | |
pupPlace = models.CharField(**default_char) | |
publisher = models.CharField(**default_char) | |
volume = models.CharField(**default_char) | |
issue = models.CharField(**default_char) | |
page = models.CharField(**default_char) | |
idstring = models.CharField(max_length=200,blank=False) | |
note = models.TextField(blank=True) | |
def __str__(self): | |
return self.idstring + ': ' + self.title | |
class Meta: | |
ordering = ('title',) | |
class Author(models.Model): | |
firstname = models.CharField(max_length=200, blank=False) | |
lastname = models.CharField(max_length=200, blank=False) | |
middlenames = models.CharField(**default_char) | |
email = models.EmailField( | |
default=None, | |
blank=True, | |
null=True, | |
unique=True) | |
homepage = models.URLField(**default_char) | |
description = models.CharField(**default_char) | |
publications = models.ManyToManyField( | |
Publication, | |
blank=True, | |
related_name='authors') | |
citations = models.ManyToManyField( | |
Citation, | |
blank=True, | |
related_name='authors') | |
editions = models.ManyToManyField( | |
Citation, | |
blank=True, | |
related_name='editors') | |
born = models.DateField( | |
blank=True, null=True) | |
foto = models.ImageField(upload_to=filepath, blank=True) | |
def edit_birthday(self): | |
self.born = timezone.now() | |
self.save() | |
def __str__(self): | |
return (str(self.firstname) + ' '\ | |
+ str(self.middlenames) + ' '\ | |
+ str(self.lastname)) | |
class Meta: | |
ordering = ('lastname',) | |
########################################## | |
# | |
# Common Text Parts and their abstract class | |
# | |
########################################### | |
class CommonTextPart(models.Model): | |
publication = models.ForeignKey(Publication) | |
title = models.CharField(max_length=200, blank=True) | |
idstring = models.CharField(max_length=100,blank=True) | |
order = models.PositiveIntegerField( | |
null=False, | |
validators=[RegexValidator(r'^\d{1,10}$')]) | |
number = models.CharField(max_length=20, blank=True) | |
language = models.CharField( | |
max_length=2, | |
choices=language_choice, | |
default='de') | |
authors = models.ManyToManyField( | |
Author, | |
default=None, | |
blank=True) | |
doi = models.CharField(max_length=200, blank=True) | |
citation = models.CharField(max_length=200, blank=True) | |
pdf = models.FileField(upload_to=filepath, blank=True) | |
def __str__(self): | |
return (self.publication.__str__() + ' ' + str(self.order) + ':' + self.title) | |
class Meta: | |
abstract = True | |
ordering = ('order',) | |
class Part(CommonTextPart): | |
pass | |
class Chapter(CommonTextPart): | |
part = models.ForeignKey(Part, blank=True, null=True) | |
class Section(CommonTextPart): | |
part = models.ForeignKey(Part, blank=True, null=True) | |
chapter = models.ForeignKey(Chapter, blank=False) | |
class Subsection(CommonTextPart): | |
part = models.ForeignKey(Part, blank=True, null=True) | |
chapter = models.ForeignKey(Chapter, blank=False) | |
section = models.ForeignKey(Section, blank=False) | |
class Subsubsection(CommonTextPart): | |
part = models.ForeignKey(Part, blank=True, null=True) | |
chapter = models.ForeignKey(Chapter, blank=False) | |
section = models.ForeignKey(Section, blank=False) | |
subsection = models.ForeignKey(Subsection, blank=False) | |
class MixedContent(models.Model): | |
parent = models.ForeignKey(MixedContent, blank=True) | |
position = model.PositiveIntegerField(blank=False) | |
tagname = models.CharField(**default_char, | |
choices=tagname_choice, | |
default='de') | |
attributes = HStoreField( | |
validators=[ | |
KeysValidator( | |
validkeys, | |
strict=True, | |
messages = { | |
'missing_keys': _('Some keys were missing: %(keys)s'), | |
'extra_keys': _('Some unknown keys were provided: %(keys)s'), | |
} | |
) | |
] | |
) | |
class Meta: | |
abstract = True | |
class Paragraph(models.Model): | |
publication = models.ForeignKey(Publication) | |
part = models.ForeignKey(Part, blank=True, null=True) | |
chapter = models.ForeignKey(Chapter, blank=True, null=True) | |
section = models.ForeignKey(Section, blank=True, null=True) | |
subsection = models.ForeignKey(Subsection, blank=True, null=True) | |
subsubsection = models.ForeignKey(Subsubsection, blank=True, null=True) | |
idstring = models.CharField(max_length=100,blank=True) | |
text = models.ForeignKey(MixedContent,blank=False) | |
def __str__(self): | |
return (self.publication.__str__() + ' ' + str(self.idstring)) | |
class Meta: | |
ordering = ('idstring',) | |
class Text(models.Model): | |
parent = models.ForeignKey(MixedContent) | |
position = models.PositiveIntegerField(blank=False) | |
text = models.TextField(blank=True) | |
pass | |
class Table(models.Model): | |
pass | |
class Figure(models.Model): | |
pass |