diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2015-09-09 12:20:08 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2015-09-09 12:20:08 +0200 | 
| commit | 7f3dbe476dba46b87f771ee35a25fbf56fe71d34 (patch) | |
| tree | 91523ce577cb02247afc5226e4ad7c612f30bbfd /archaeological_context_records/models.py | |
| parent | a46a56bc0369422a45d81b92ee2e6536142bded4 (diff) | |
| download | Ishtar-7f3dbe476dba46b87f771ee35a25fbf56fe71d34.tar.bz2 Ishtar-7f3dbe476dba46b87f771ee35a25fbf56fe71d34.zip | |
Flake8
Diffstat (limited to 'archaeological_context_records/models.py')
| -rw-r--r-- | archaeological_context_records/models.py | 103 | 
1 files changed, 63 insertions, 40 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 81d395ced..8adc2a294 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -25,21 +25,24 @@ from django.db.models.signals import post_delete  from django.utils.translation import ugettext_lazy as _, ugettext, pgettext  from ishtar_common.models import GeneralType, BaseHistorizedItem, \ -          HistoricalRecords, OwnPerms, ShortMenuItem, Town, Person, Source +    HistoricalRecords, OwnPerms, ShortMenuItem, Source  from archaeological_operations.models import Operation, Period, Parcel +  class DatingType(GeneralType):      class Meta:          verbose_name = _(u"Dating type")          verbose_name_plural = _(u"Dating types")          ordering = ('label',) +  class DatingQuality(GeneralType):      class Meta:          verbose_name = _(u"Dating quality")          verbose_name_plural = _(u"Dating qualities")          ordering = ('label',) +  class Dating(models.Model):      period = models.ForeignKey(Period, verbose_name=_(u"Period"))      start_date = models.IntegerField(_(u"Start date"), blank=True, null=True) @@ -60,6 +63,7 @@ class Dating(models.Model):              return unicode(self.period)          return u"%s (%s-%s)" % (self.period, start_date, end_date) +  class Unit(GeneralType):      order = models.IntegerField(_(u"Order"))      parent = models.ForeignKey("Unit", verbose_name=_(u"Parent unit"), @@ -73,6 +77,7 @@ class Unit(GeneralType):      def __unicode__(self):          return self.label +  class ActivityType(GeneralType):      order = models.IntegerField(_(u"Order")) @@ -84,8 +89,10 @@ class ActivityType(GeneralType):      def __unicode__(self):          return self.label +  class IdentificationType(GeneralType):      order = models.IntegerField(_(u"Order")) +      class Meta:          verbose_name = _(u"Type Identification")          verbose_name_plural = _(u"Types Identification") @@ -94,6 +101,7 @@ class IdentificationType(GeneralType):      def __unicode__(self):          return self.label +  class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):      TABLE_COLS = ['parcel.town', 'operation.year',                    'operation.operation_code', @@ -114,11 +122,13 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):      closing_date = models.DateField(_(u"End date"), blank=True, null=True)      length = models.IntegerField(_(u"Length (cm)"), blank=True, null=True)      width = models.IntegerField(_(u"Width (cm)"), blank=True, null=True) -    thickness = models.IntegerField(_(u"Thickness (cm)"), blank=True, null=True) +    thickness = models.IntegerField(_(u"Thickness (cm)"), blank=True, +                                    null=True)      depth = models.IntegerField(_(u"Depth (cm)"), blank=True, null=True) -    location = models.CharField(_(u"Location"), blank=True, null=True, -     max_length=200, -     help_text=_(u"A short description of the location of the context record")) +    location = models.CharField( +        _(u"Location"), blank=True, null=True, max_length=200, +        help_text=_(u"A short description of the location of the context " +                    u"record"))      datings = models.ManyToManyField(Dating)      unit = models.ForeignKey(Unit, verbose_name=_(u"Unit"), related_name='+',                               blank=True, null=True) @@ -127,23 +137,27 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):      filling = models.TextField(_(u"Filling"), blank=True, null=True)      interpretation = models.TextField(_(u"Interpretation"), blank=True,                                        null=True) -    taq = models.IntegerField(_(u"TAQ"), blank=True, null=True, -     help_text=_(u"\"Terminus Ante Quem\" the context record can't have been " -                 "created after this date")) -    taq_estimated = models.IntegerField(_(u"Estimated TAQ"), blank=True, -     null=True, help_text=_(u"Estimation of a \"Terminus Ante Quem\"")) -    tpq = models.IntegerField(_(u"TPQ"), blank=True, null=True, -     help_text=_(u"\"Terminus Post Quem\" the context record can't have been " -                 " created before this date")) -    tpq_estimated = models.IntegerField(_(u"Estimated TPQ"), blank=True, -     null=True, help_text=_(u"Estimation of a \"Terminus Post Quem\"")) -    identification = models.ForeignKey(IdentificationType, blank=True, -                            null=True, verbose_name=_(u"Identification"),) -    activity = models.ForeignKey(ActivityType,blank=True, null=True, +    taq = models.IntegerField( +        _(u"TAQ"), blank=True, null=True, +        help_text=_(u"\"Terminus Ante Quem\" the context record can't have " +                    u"been created after this date")) +    taq_estimated = models.IntegerField( +        _(u"Estimated TAQ"), blank=True, null=True, +        help_text=_(u"Estimation of a \"Terminus Ante Quem\"")) +    tpq = models.IntegerField( +        _(u"TPQ"), blank=True, null=True, +        help_text=_(u"\"Terminus Post Quem\" the context record can't have " +                    u"been created before this date")) +    tpq_estimated = models.IntegerField( +        _(u"Estimated TPQ"), blank=True, null=True, +        help_text=_(u"Estimation of a \"Terminus Post Quem\"")) +    identification = models.ForeignKey( +        IdentificationType, blank=True, null=True, +        verbose_name=_(u"Identification"),) +    activity = models.ForeignKey(ActivityType, blank=True, null=True,                                   verbose_name=_(u"Activity"),) -    related_context_records = models.ManyToManyField('ContextRecord', -                                               through='RecordRelations', -                                               blank=True, null=True) +    related_context_records = models.ManyToManyField( +        'ContextRecord', through='RecordRelations', blank=True, null=True)      history = HistoricalRecords()      class Meta: @@ -151,10 +165,14 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):          verbose_name_plural = _(u"Context Record")          permissions = (              ("view_contextrecord", ugettext(u"Can view all Context Record")), -            ("view_own_contextrecord", ugettext(u"Can view own Context Record")), -            ("add_own_contextrecord", ugettext(u"Can add own Context Record")), -            ("change_own_contextrecord", ugettext(u"Can change own Context Record")), -            ("delete_own_contextrecord", ugettext(u"Can delete own Context Record")), +            ("view_own_contextrecord", +             ugettext(u"Can view own Context Record")), +            ("add_own_contextrecord", +             ugettext(u"Can add own Context Record")), +            ("change_own_contextrecord", +             ugettext(u"Can change own Context Record")), +            ("delete_own_contextrecord", +             ugettext(u"Can delete own Context Record")),          )      @property @@ -170,8 +188,8 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):      @property      def short_label(self): -        return settings.JOINT.join([unicode(item) for item in [self.parcel, -                                                   self.label] if item]) +        return settings.JOINT.join([unicode(item) for item in [ +            self.parcel, self.label] if item])      @property      def show_url(self): @@ -192,9 +210,8 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):          if self.operation.code_patriarche:              return          return settings.JOINT.join([unicode(lbl) for lbl in [ -                                           self.operation.year, -                                           self.operation.operation_code, -                                           self.label] if lbl]) +            self.operation.year, self.operation.operation_code, self.label] +            if lbl])      @property      def reference(self): @@ -253,11 +270,13 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):          from archaeological_finds.models import FindSource          return FindSource.objects.filter(find__base_finds__context_record=self) +  class RelationType(GeneralType):      order = models.IntegerField(_(u"Order"), default=1)      symmetrical = models.BooleanField(_(u"Symmetrical")) -    inverse_relation = models.ForeignKey('RelationType', -                verbose_name=_(u"Inverse relation"), blank=True, null=True) +    inverse_relation = models.ForeignKey( +        'RelationType', verbose_name=_(u"Inverse relation"), blank=True, +        null=True)      class Meta:          verbose_name = _(u"Relation type") @@ -268,7 +287,7 @@ class RelationType(GeneralType):          # cannot have symmetrical and an inverse_relation          if self.symmetrical and self.inverse_relation:              raise ValidationError( -                        _(u"Cannot have symmetrical and an inverse_relation")) +                _(u"Cannot have symmetrical and an inverse_relation"))      def save(self, *args, **kwargs):          obj = super(RelationType, self).save(*args, **kwargs) @@ -282,6 +301,7 @@ class RelationType(GeneralType):              self.inverse_relation.save()          return obj +  class RecordRelations(models.Model):      left_record = models.ForeignKey(ContextRecord,                                      related_name='right_relations') @@ -306,11 +326,12 @@ class RecordRelations(models.Model):          if not sym_rel_type:              return -        dct = {'right_record':self.left_record, 'left_record':self.right_record, -               'relation_type':sym_rel_type} +        dct = {'right_record': self.left_record, +               'left_record': self.right_record, 'relation_type': sym_rel_type}          RecordRelations.objects.get_or_create(**dct)          return self +  def post_delete_record_relation(sender, instance, **kwargs):      # delete symmetrical or inverse relation      sym_rel_type = instance.relation_type @@ -321,19 +342,21 @@ def post_delete_record_relation(sender, instance, **kwargs):      if not sym_rel_type:          return -    dct = {'right_record':instance.left_record, -           'left_record':instance.right_record, -           'relation_type':sym_rel_type} +    dct = {'right_record': instance.left_record, +           'left_record': instance.right_record, +           'relation_type': sym_rel_type}      RecordRelations.objects.filter(**dct).delete()  post_delete.connect(post_delete_record_relation, sender=RecordRelations) +  class ContextRecordSource(Source):      class Meta:          verbose_name = _(u"Context record documentation")          verbose_name_plural = _(u"Context record documentations") -    context_record = models.ForeignKey(ContextRecord, -                       verbose_name=_(u"Context record"), related_name="source") +    context_record = models.ForeignKey( +        ContextRecord, verbose_name=_(u"Context record"), +        related_name="source")      @property      def owner(self): | 
