src/p4l/models/data.py
changeset 0 81e7900b06a7
child 4 047675624f45
equal deleted inserted replaced
-1:000000000000 0:81e7900b06a7
       
     1 # -*- coding: utf-8 -*-
       
     2 
       
     3 from django.db import models
       
     4 from p4l.models.common import P4lModel, P4lModelLang
       
     5 
       
     6 
       
     7 class Imprint(P4lModelLang):
       
     8     record = models.ForeignKey('p4l.Record', related_name="imprints")
       
     9     imprintCity = models.CharField(max_length=512, blank=True, null=True, db_index=True)
       
    10     publisher = models.CharField(max_length=512, blank=True, null=True, db_index=True)
       
    11     imprintDate = models.CharField(max_length=512, blank=True, null=True, db_index=True)    
       
    12 
       
    13 
       
    14 class Serie(P4lModel):
       
    15     title = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
       
    16     volume = models.CharField(max_length=2048, blank=True, null=True, db_index=True)
       
    17     class Meta(P4lModel.Meta):
       
    18         unique_together = ['title', 'volume']
       
    19 
       
    20 class RecordSerie(P4lModelLang):
       
    21     record = models.ForeignKey('p4l.Record', related_name="series+")
       
    22     serie = models.ForeignKey('p4l.Serie', related_name="records")
       
    23     class Meta(P4lModelLang.Meta):
       
    24         unique_together = ['record','serie']
       
    25 
       
    26 
       
    27 
       
    28 class ProjectName(P4lModel):
       
    29     label = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
       
    30     acronym = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:acronym
       
    31     class Meta(P4lModel.Meta):
       
    32         unique_together = ['label', 'acronym']
       
    33 
       
    34 
       
    35 class CorporateAuthor(P4lModel):
       
    36     label = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
       
    37     acronym = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:acronym
       
    38     class Meta(P4lModel.Meta):
       
    39         unique_together = ['label', 'acronym']
       
    40 
       
    41 
       
    42 class Url(P4lModel):
       
    43     record = models.ForeignKey('p4l.Record', related_name="urls")
       
    44     address = models.CharField(max_length=2048, blank=False, null=False, db_index=True) #iiep:address
       
    45     display = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:display
       
    46     accessLevel = models.CharField(max_length=512, blank=True, null=True, db_index=True) #iiep:accessLevel
       
    47 
       
    48 
       
    49 class Subject(P4lModel):
       
    50     subject = models.URLField(max_length=2048, unique=True, db_index=True)
       
    51 
       
    52 class Theme(P4lModel):
       
    53     theme = models.URLField(max_length=2048, unique=True, db_index=True)
       
    54 
       
    55 
       
    56 class Country(P4lModel):
       
    57     country = models.URLField(max_length=2048, unique=True, db_index=True)
       
    58 
       
    59 
       
    60 class Isbn(P4lModelLang):
       
    61     record = models.ForeignKey('p4l.Record', related_name="isbns")
       
    62     isbn = models.CharField(max_length=128) #iiep:isbn
       
    63 
       
    64 
       
    65 class Issn(P4lModelLang):
       
    66     record = models.ForeignKey('p4l.Record', related_name="issns")
       
    67     issn = models.CharField(max_length=128) #iiep:issn
       
    68 
       
    69 class DocumentCode(P4lModelLang):
       
    70     record = models.ForeignKey('p4l.Record', related_name="documentCodes")
       
    71     documentCode = models.CharField(max_length=128) #iiep:issn
       
    72 
       
    73 class Language(P4lModel):
       
    74     language = models.URLField(max_length=2048, unique=True, db_index=True)
       
    75 
       
    76 
       
    77 
       
    78 class BaseTitle(P4lModelLang):
       
    79     title = models.CharField(max_length=2048, blank=False, null=False, db_index=True)
       
    80     class Meta(P4lModelLang.Meta):
       
    81         abstract = True
       
    82 
       
    83 class Title(BaseTitle):
       
    84     record = models.ForeignKey('p4l.Record', related_name="titles")
       
    85 
       
    86 class AddedTitle(BaseTitle):
       
    87     record = models.ForeignKey('p4l.Record', related_name="addedTitles")
       
    88 
       
    89 class TitleMainDocument(BaseTitle):
       
    90     record = models.ForeignKey('p4l.Record', related_name="titlesMainDocument")
       
    91 
       
    92 
       
    93 class Abstract(P4lModelLang):
       
    94     record = models.ForeignKey('p4l.Record', related_name="abstracts")
       
    95     abstract = models.TextField(blank=True, null=True)
       
    96 
       
    97 
       
    98 class Collation(P4lModelLang):
       
    99     record = models.ForeignKey('p4l.Record', related_name="collations")
       
   100     collation = models.CharField(max_length=1024, blank=False, null=False, db_index=True)
       
   101 
       
   102 
       
   103 class VolumeIssue(P4lModelLang):
       
   104     record = models.ForeignKey('p4l.Record', related_name="volumeIssues")
       
   105     volume = models.CharField(max_length=1024, blank=True, null=True, db_index=True) #iiep:volume
       
   106     number = models.CharField(max_length=1024, blank=True, null=True, db_index=True) #iiep:number
       
   107 
       
   108 
       
   109 class P4lPerson(P4lModel):
       
   110     name = models.CharField(max_length=2048, blank=False, null=False, db_index=True, unique=True)
       
   111     class Meta(P4lModel.Meta):
       
   112         abstract = True
       
   113 
       
   114 
       
   115 class Author(P4lPerson):
       
   116     pass
       
   117     
       
   118 class SubjectPerson(P4lPerson):
       
   119     pass
       
   120 
       
   121 
       
   122 class Periodical(P4lModel):
       
   123     label = models.CharField(max_length=2048, blank=False, null=False, db_index=True, unique=True) #iiep:periodical
       
   124 
       
   125 class RecordPeriodical(P4lModelLang):
       
   126     record = models.ForeignKey('p4l.Record', related_name="periodicals+")
       
   127     periodical = models.ForeignKey('p4l.Periodical', related_name="records")
       
   128     class Meta(P4lModelLang.Meta):
       
   129         unique_together = ['record','periodical']
       
   130 
       
   131 
       
   132 class BaseMeeting(P4lModel):
       
   133     label = models.CharField(max_length=2048, blank=False, null=False, db_index=True) #rdfs:label
       
   134     meetingNumber = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:meetingNumber
       
   135     meetingPlace = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:meetingPlace
       
   136     meetingDate = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:meetingDate
       
   137     meetingYear = models.PositiveSmallIntegerField(blank=True, null=True, db_index=True) #iiep:meetingYear
       
   138     class Meta(P4lModel.Meta):
       
   139         abstract = True
       
   140         unique_together = ['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear']
       
   141 
       
   142 
       
   143 class Meeting(BaseMeeting):
       
   144     pass
       
   145 
       
   146 class RecordMeeting(P4lModelLang):
       
   147     record = models.ForeignKey('p4l.Record', related_name="meetings+")
       
   148     meeting = models.ForeignKey('p4l.Meeting', related_name="records")
       
   149     class Meta(P4lModelLang.Meta):
       
   150         unique_together = ['record','meeting']
       
   151 
       
   152 
       
   153 class SubjectMeeting(BaseMeeting):
       
   154     pass
       
   155 
       
   156 
       
   157 class CorporateBody(P4lModel):
       
   158     label = models.CharField(max_length=2048, blank=False, null=False, db_index=True) #rdfs:label
       
   159     acronym = models.CharField(max_length=2048, blank=True, null=True, db_index=True) #iiep:acronym
       
   160     class Meta(P4lModel.Meta):
       
   161         unique_together = ['label','acronym']
       
   162 
       
   163 class Record(P4lModel):
       
   164     uri = models.URLField(max_length=2048, unique=True, db_index=True) #subject
       
   165     subjects = models.ManyToManyField('p4l.Subject') #dct:subject
       
   166     themes = models.ManyToManyField('p4l.Theme') #iiep:theme
       
   167     countries = models.ManyToManyField('p4l.Country') #iiep:country
       
   168     identifier = models.CharField(max_length=128, unique=True, db_index=True) #dct:identifier    
       
   169     notes = models.TextField(blank=True, null=True) #iiep:notes    
       
   170     #issns foreign key from Isbn #iiep:issn
       
   171     #isbns foreign key from Isbn #iiep:isbn
       
   172     #documentCodes foreign key from Isbn #iiep:documentCode
       
   173     language = models.ForeignKey('p4l.Language', blank=True, null=True) #dct:language
       
   174     otherLanguages = models.ManyToManyField('p4l.Language', related_name='otherLanguage_record') #iiep:otherLanguage
       
   175     #titles foreign Key from Title #dct:title
       
   176     #addedTitles foreign Key from AddedTitle #iiep:addedTitle
       
   177     #titlesMainDocument foreign Key from TitleMainDocument #iiep:titleMainDocument
       
   178     editionStatement = models.CharField(max_length=1024, blank=True, null=True) #iiep:editionStatement
       
   179     #imprints foreign Key from Imprint #iiep:imprint
       
   180     #collations = foreign Key from Collation #iiep:collation
       
   181     #volumeIssues = foreign Key from VolumeIssue #iiep:volumeIssue
       
   182     projectNames = models.ManyToManyField('p4l.ProjectName') #iiep:projectName
       
   183     periodicals = models.ManyToManyField('p4l.Periodical', through='p4l.RecordPeriodical') #iiep:periodical
       
   184     meetings = models.ManyToManyField('p4l.Meeting', through='p4l.RecordMeeting') #iiep:meeting
       
   185     series = models.ManyToManyField('p4l.Serie', through='p4l.RecordSerie')  #iiep:serie
       
   186     authors = models.ManyToManyField('p4l.Author') #iiep:author
       
   187     subjectPersons = models.ManyToManyField('p4l.SubjectPerson') #iiep:subjectPerson
       
   188     subjectCorporateBodies = models.ManyToManyField('p4l.CorporateBody') #iiep:subjectCorporateBody
       
   189     subjectMeetings = models.ManyToManyField('p4l.SubjectMeeting') #iiep:subjectMeeting
       
   190     corporateAuthors = models.ManyToManyField('p4l.CorporateAuthor') #iiep:corporateAuthor
       
   191     #urls foreign Key from Url #iiep:url
       
   192     recordType = models.URLField(max_length=2048) #dct:type
       
   193     isDocumentPart = models.BooleanField() #iiep:isDocumentPart
       
   194 
       
   195     def __unicode__(self):
       
   196         return "Record id %s { identifier: %s, uri: %s, editionStatement: %s,  recordType: %s, isDocumentPart: %s, notes: %s, language : %s}" \
       
   197             % (
       
   198                 self.id,
       
   199                 self.identifier,
       
   200                 self.uri,
       
   201                 self.editionStatement,
       
   202                 self.recordType,
       
   203                 self.isDocumentPart,
       
   204                 self.notes[:100] if self.notes else None,
       
   205                 self.language.id if self.language else None
       
   206             )
       
   207 
       
   208 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}issn', 3)
       
   209 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}documentCode', 3)
       
   210 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}country', 44)
       
   211 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}imprint', 5)
       
   212 #('{http://purl.org/dc/terms/}title', 4)
       
   213 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}isDocumentPart', 1)
       
   214 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}notes', 1)
       
   215 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}isbn', 8)
       
   216 #('{http://purl.org/dc/terms/}identifier', 1)
       
   217 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}meeting', 4)
       
   218 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}projectName', 10)
       
   219 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}addedTitle', 18)
       
   220 #('{http://purl.org/dc/terms/}subject', 29)
       
   221 #('{http://purl.org/dc/terms/}language', 1)
       
   222 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}serie', 4)
       
   223 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}volumeIssue', 3)
       
   224 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}url', 20)
       
   225 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}titleMainDocument', 3)
       
   226 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}otherLanguage', 13)
       
   227 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}periodical', 3)
       
   228 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}editionStatement', 1)
       
   229 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}collation', 4)
       
   230 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}subjectMeeting', 6)
       
   231 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}corporateAuthor', 7)
       
   232 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}author', 26)
       
   233 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}subjectPerson', 2)
       
   234 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}subjectCorporateBody', 8)
       
   235 #('{http://www.iiep.unesco.org/plan4learning/model.owl#}theme', 6)
       
   236 #('{http://purl.org/dc/terms/}abstract', 3)
       
   237 #('{http://purl.org/dc/terms/}type', 1)