summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-09-09 11:47:56 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-09-09 11:47:56 +0200
commita46a56bc0369422a45d81b92ee2e6536142bded4 (patch)
tree089fa9d44d2683c3e2238dc53bd0366a6a1e5841 /archaeological_finds
parentc50e198731d5cf6b48ce250ce60031e9e5327fe8 (diff)
downloadIshtar-a46a56bc0369422a45d81b92ee2e6536142bded4.tar.bz2
Ishtar-a46a56bc0369422a45d81b92ee2e6536142bded4.zip
Flake8
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/models.py138
1 files changed, 78 insertions, 60 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index dd4b20b39..4fd4543b4 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -36,6 +36,7 @@ if WAREHOUSE_AVAILABLE:
FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
+
class MaterialType(GeneralType):
code = models.CharField(_(u"Code"), max_length=10, blank=True, null=True)
recommendation = models.TextField(_(u"Recommendation"), blank=True,
@@ -48,6 +49,7 @@ class MaterialType(GeneralType):
verbose_name_plural = _(u"Material types")
ordering = ('label',)
+
class ConservatoryState(GeneralType):
parent = models.ForeignKey("ConservatoryState", blank=True, null=True,
verbose_name=_(u"Parent conservatory state"))
@@ -57,24 +59,27 @@ class ConservatoryState(GeneralType):
verbose_name_plural = _(u"Conservatory states")
ordering = ('label',)
+
class PreservationType(GeneralType):
class Meta:
verbose_name = _(u"Preservation type")
verbose_name_plural = _(u"Preservation types")
ordering = ('label',)
+
class BaseFind(BaseHistorizedItem, OwnPerms):
label = models.CharField(_(u"ID"), max_length=60)
external_id = models.CharField(_(u"External ID"), blank=True, null=True,
max_length=120)
description = models.TextField(_(u"Description"), blank=True, null=True)
comment = models.TextField(_(u"Comment"), blank=True, null=True)
- topographic_localisation = models.CharField(_(u"Topographic localisation"),
- blank=True, null=True, max_length=120)
+ topographic_localisation = models.CharField(
+ _(u"Topographic localisation"), blank=True, null=True, max_length=120)
special_interest = models.CharField(_(u"Special interest"), blank=True,
null=True, max_length=120)
- context_record = models.ForeignKey(ContextRecord,
- related_name='base_finds', verbose_name=_(u"Context Record"))
+ context_record = models.ForeignKey(
+ ContextRecord, related_name='base_finds',
+ verbose_name=_(u"Context Record"))
discovery_date = models.DateField(_(u"Discovery date"),
blank=True, null=True)
is_isolated = models.NullBooleanField(_(u"Is isolated?"), blank=True,
@@ -98,7 +103,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
return self.label
def get_last_find(self):
- #TODO: manage virtuals - property(last_find) ?
+ # TODO: manage virtuals - property(last_find) ?
finds = self.find.filter().order_by("-order").all()
return finds and finds[0]
@@ -120,9 +125,9 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
# OPE|FIND_index
if not self.context_record.operation:
return
- find = self.get_last_find()
+ self.get_last_find()
ope = self.context_record.operation
- c_id = [unicode(ope.code_patriarche) or \
+ c_id = [unicode(ope.code_patriarche) or
(unicode(ope.year) + "-" + unicode(ope.operation_code))]
c_id.append(unicode(self.index))
return settings.JOINT.join(c_id)
@@ -134,7 +139,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
find = self.get_last_find()
finds = [find and find.material_type.code or '']
ope = self.context_record.operation
- finds += [unicode(ope.code_patriarche) or \
+ finds += [unicode(ope.code_patriarche) or
(unicode(ope.year) + "-" + unicode(ope.operation_code))]
finds += [self.context_record.label, unicode(self.material_index)]
return settings.JOINT.join(finds)
@@ -146,21 +151,20 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
return
find = self.get_last_find()
lbl = find.label or self.label
- return settings.JOINT.join([unicode(it) for it in (
- self.context_record.operation.code_patriarche,
- self.context_record.label,
- lbl) if it])
+ return settings.JOINT.join(
+ [unicode(it) for it in (
+ self.context_record.operation.code_patriarche,
+ self.context_record.label, lbl) if it])
def _temp_label(self):
if not self.context_record.parcel:
return
find = self.get_last_find()
lbl = find.label or self.label
- return settings.JOINT.join([unicode(it) for it in (
- self.context_record.parcel.year,
- self.index,
- self.context_record.label,
- lbl) if it])
+ return settings.JOINT.join(
+ [unicode(it) for it in (
+ self.context_record.parcel.year, self.index,
+ self.context_record.label, lbl) if it])
@property
def name(self):
@@ -177,6 +181,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
WEIGHT_UNIT = (('g', _(u"g")),
('kg', _(u"kg")),)
+
class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
TABLE_COLS = ['label', 'material_type', 'dating.period',
'base_finds.context_record.parcel.town',
@@ -185,8 +190,8 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
'container.reference', 'container.location',
'base_finds.is_isolated']
if settings.COUNTRY == 'fr':
- TABLE_COLS.insert(6,
- 'base_finds.context_record.operation.code_patriarche')
+ TABLE_COLS.insert(
+ 6, 'base_finds.context_record.operation.code_patriarche')
base_finds = models.ManyToManyField(BaseFind, verbose_name=_(u"Base find"),
related_name='find')
external_id = models.CharField(_(u"External ID"), blank=True, null=True,
@@ -194,27 +199,32 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
order = models.IntegerField(_(u"Order"), default=1)
label = models.CharField(_(u"ID"), max_length=60)
description = models.TextField(_(u"Description"), blank=True, null=True)
- material_type = models.ForeignKey(MaterialType,
- verbose_name = _(u"Material type"))
- conservatory_state = models.ForeignKey(ConservatoryState,
- verbose_name = _(u"Conservatory state"), blank=True, null=True)
- preservation_to_consider = models.ForeignKey(PreservationType,
- verbose_name = _(u"Type of preservation to consider"), blank=True,
- null=True)
+ material_type = models.ForeignKey(
+ MaterialType, verbose_name=_(u"Material type"))
+ conservatory_state = models.ForeignKey(
+ ConservatoryState, verbose_name=_(u"Conservatory state"), blank=True,
+ null=True)
+ preservation_to_consider = models.ForeignKey(
+ PreservationType, verbose_name=_(u"Type of preservation to consider"),
+ blank=True, null=True)
volume = models.FloatField(_(u"Volume (l)"), blank=True, null=True)
weight = models.FloatField(_(u"Weight (g)"), blank=True, null=True)
weight_unit = models.CharField(_(u"Weight unit"), max_length=4,
blank=True, null=True, choices=WEIGHT_UNIT)
find_number = models.IntegerField(_("Find number"), blank=True, null=True)
- upstream_treatment = models.ForeignKey("Treatment", blank=True, null=True,
- related_name='downstream_treatment', verbose_name=_("Upstream treatment"))
- downstream_treatment = models.ForeignKey("Treatment", blank=True, null=True,
- related_name='upstream_treatment', verbose_name=_("Downstream treatment"))
+ upstream_treatment = models.ForeignKey(
+ "Treatment", blank=True, null=True,
+ related_name='downstream_treatment',
+ verbose_name=_("Upstream treatment"))
+ downstream_treatment = models.ForeignKey(
+ "Treatment", blank=True, null=True, related_name='upstream_treatment',
+ verbose_name=_("Downstream treatment"))
dating = models.ForeignKey(Dating, verbose_name=_(u"Dating"), blank=True,
null=True)
if WAREHOUSE_AVAILABLE:
- container = models.ForeignKey(Container, verbose_name=_(u"Container"),
- blank=True, null=True, related_name='finds')
+ container = models.ForeignKey(
+ Container, verbose_name=_(u"Container"), blank=True, null=True,
+ related_name='finds')
history = HistoricalRecords()
def __init__(self, *args, **kwargs):
@@ -256,7 +266,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
for base_find in self.base_finds.all()])
def get_first_base_find(self):
- q= self.base_finds
+ q = self.base_finds
if not q.count():
return
return q.all()[0]
@@ -303,8 +313,9 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
q = cls.objects
if fltr:
q = q.filter(**fltr)
- return q.filter(downstream_treatment__isnull=True,
- base_finds__context_record__operation__start_date__year=year)
+ return q.filter(
+ downstream_treatment__isnull=True,
+ base_finds__context_record__operation__start_date__year=year)
@classmethod
def get_operations(cls):
@@ -321,8 +332,9 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
@classmethod
def get_by_operation(cls, operation_id):
- return cls.objects.filter(downstream_treatment__isnull=True,
- base_finds__context_record__operation__pk=operation_id)
+ return cls.objects.filter(
+ downstream_treatment__isnull=True,
+ base_finds__context_record__operation__pk=operation_id)
@classmethod
def get_total_number(cls, fltr={}):
@@ -332,11 +344,11 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
return q.filter(downstream_treatment__isnull=True).count()
def duplicate(self, user):
- dct = dict([(attr, getattr(self, attr)) for attr in ('order', 'label',
- 'description', 'material_type', 'volume', 'weight',
- 'find_number', 'dating', 'conservatory_state',
- 'preservation_to_consider', 'weight_unit',
- 'find_number')])
+ dct = dict([(attr, getattr(self, attr)) for attr in
+ ('order', 'label', 'description', 'material_type',
+ 'volume', 'weight', 'find_number', 'dating',
+ 'conservatory_state', 'preservation_to_consider',
+ 'weight_unit', 'find_number')])
dct['order'] += 1
dct['history_modifier'] = user
new = self.__class__(**dct)
@@ -349,18 +361,20 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
super(Find, self).save(*args, **kwargs)
for base_find in self.base_finds.all():
if not base_find.index:
- idx = BaseFind.objects.filter(context_record=\
- base_find.context_record).aggregate(Max('index'))
+ idx = BaseFind.objects\
+ .filter(context_record=base_find.context_record)\
+ .aggregate(Max('index'))
base_find.index = idx and idx['index__max'] + 1 or 1
if not base_find.material_index:
- idx = BaseFind.objects.filter(context_record=\
- base_find.context_record,
- find__material_type=self.material_type).aggregate(
- Max('material_index'))
- base_find.material_index = idx and \
- idx['material_index__max'] + 1 or 1
+ idx = BaseFind.objects\
+ .filter(context_record=base_find.context_record,
+ find__material_type=self.material_type)\
+ .aggregate(Max('material_index'))
+ base_find.material_index = \
+ idx and idx['material_index__max'] + 1 or 1
base_find.save()
+
class FindSource(Source):
class Meta:
verbose_name = _(u"Find documentation")
@@ -372,19 +386,22 @@ class FindSource(Source):
def owner(self):
return self.find
+
class TreatmentType(GeneralType):
virtual = models.BooleanField(_(u"Virtual"))
+
class Meta:
verbose_name = _(u"Treatment type")
verbose_name_plural = _(u"Treatment types")
ordering = ('label',)
+
class Treatment(BaseHistorizedItem, OwnPerms):
external_id = models.CharField(_(u"External ID"), blank=True, null=True,
max_length=120)
if WAREHOUSE_AVAILABLE:
- container = models.ForeignKey(Container, verbose_name=_(u"Container"),
- blank=True, null=True)
+ container = models.ForeignKey(Container, verbose_name=_(u"Container"),
+ blank=True, null=True)
description = models.TextField(_(u"Description"), blank=True, null=True)
comment = models.TextField(_(u"Comment"), blank=True, null=True)
treatment_type = models.ForeignKey(TreatmentType,
@@ -394,9 +411,9 @@ class Treatment(BaseHistorizedItem, OwnPerms):
blank=True, null=True)
other_location = models.CharField(_(u"Other location"), max_length=200,
blank=True, null=True)
- person = models.ForeignKey(Person, verbose_name=_(u"Person"),
- blank=True, null=True, on_delete=models.SET_NULL,
- related_name='treatments')
+ person = models.ForeignKey(
+ Person, verbose_name=_(u"Person"), blank=True, null=True,
+ on_delete=models.SET_NULL, related_name='treatments')
start_date = models.DateField(_(u"Start date"), blank=True, null=True)
end_date = models.DateField(_(u"End date"), blank=True, null=True)
history = HistoricalRecords()
@@ -418,22 +435,24 @@ class Treatment(BaseHistorizedItem, OwnPerms):
lbl += u" %s %s" % (_(u"by"), unicode(self.person))
return lbl
+
class TreatmentSource(Source):
class Meta:
verbose_name = _(u"Treatment documentation")
verbose_name_plural = _(u"Treament documentations")
- treatment = models.ForeignKey(Treatment, verbose_name=_(u"Treatment"),
- related_name="source")
+ treatment = models.ForeignKey(
+ Treatment, verbose_name=_(u"Treatment"), related_name="source")
@property
def owner(self):
return self.treatment
+
class Property(LightHistorizedItem):
find = models.ForeignKey(Find, verbose_name=_(u"Find"))
if FILES_AVAILABLE:
- administrative_act = models.ForeignKey(AdministrativeAct,
- verbose_name=_(u"Administrative act"))
+ administrative_act = models.ForeignKey(
+ AdministrativeAct, verbose_name=_(u"Administrative act"))
person = models.ForeignKey(Person, verbose_name=_(u"Person"),
related_name='properties')
start_date = models.DateField(_(u"Start date"))
@@ -445,4 +464,3 @@ class Property(LightHistorizedItem):
def __unicode__(self):
return self.person + settings.JOINT + self.find
-