summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-06-01 15:50:52 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-06-12 09:57:24 +0200
commit7343c9f1bbc28be270b2093dcd9e713a7bdcdb89 (patch)
tree0ed9392291c50980c7dbff14c9a05edc601076de /archaeological_operations/models.py
parent10b603af68689ea3b251006b7ec05855b9616811 (diff)
downloadIshtar-7343c9f1bbc28be270b2093dcd9e713a7bdcdb89.tar.bz2
Ishtar-7343c9f1bbc28be270b2093dcd9e713a7bdcdb89.zip
Adapt forms, wizards, views, urls for new management of documents (refs #4107)
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py120
1 files changed, 18 insertions, 102 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index de58e0da7..e2e3422fa 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -27,15 +27,15 @@ from django.db import IntegrityError, transaction
from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed, post_delete
from django.forms import ValidationError
-from django.utils.translation import ugettext_lazy as _, ugettext
+from django.utils.translation import ugettext_lazy as _
-from ishtar_common.models import BaseHistorizedItem, BaseSource, Dashboard, \
+from ishtar_common.models import BaseHistorizedItem, Dashboard, \
DashboardFormItem, Department, Document, DocumentTemplate, \
GeneralRecordRelations, GeneralRelationType, GeneralType, \
- HistoricalRecords, IshtarImage, IshtarUser, LightHistorizedItem, \
+ HistoricalRecords, IshtarUser, LightHistorizedItem, \
OperationType, Organization, OwnPerms, Person, PersonType, \
post_delete_record_relation, post_save_cache, RelationItem, \
- ShortMenuItem, SourceType, ThroughImage, Town, ValueGetter
+ ShortMenuItem, SourceType, Town, ValueGetter
from ishtar_common.utils import cached_label_changed, \
force_cached_label_changed, mode
@@ -131,8 +131,6 @@ class ArchaeologicalSite(BaseHistorizedItem):
documents = models.ManyToManyField(
Document, related_name="sites", verbose_name=_(u"Documents"),
blank=True)
- images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"),
- through='SiteImage', blank=True)
class Meta:
verbose_name = _(u"Archaeological site")
@@ -221,11 +219,6 @@ class ArchaeologicalSite(BaseHistorizedItem):
)
-class SiteImage(ThroughImage):
- item = models.ForeignKey(ArchaeologicalSite, on_delete=models.CASCADE,
- related_name='associated_images')
-
-
def get_values_town_related(item, prefix, values):
values[prefix + 'parcellist'] = item.render_parcels()
values[prefix + 'towns'] = ''
@@ -464,8 +457,6 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
documents = models.ManyToManyField(
Document, related_name='operations', verbose_name=_(u"Documents"),
blank=True)
- images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"),
- blank=True, through='OperationImage')
cached_label = models.CharField(_(u"Cached name"), max_length=500,
null=True, blank=True, db_index=True)
archaeological_sites = models.ManyToManyField(
@@ -642,14 +633,12 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return CRRL.objects.filter(left_record__operation=self)
def context_record_docs_q(self):
- from archaeological_context_records.models import ContextRecordSource
- return ContextRecordSource.objects.filter(
- context_record__operation=self)
+ return Document.objects.filter(
+ context_records__operation=self)
def find_docs_q(self):
- from archaeological_finds.models import FindSource
- return FindSource.objects.filter(
- find__base_finds__context_record__operation=self)
+ return Document.objects.filter(
+ finds__base_finds__context_record__operation=self)
def containers_q(self):
from archaeological_warehouse.models import Container
@@ -885,13 +874,11 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return self._get_or_set_stats('_nb_documents', update)
def _nb_documents(self):
- from archaeological_context_records.models import ContextRecordSource
- from archaeological_finds.models import FindSource
- nbs = self.source.count() + \
- ContextRecordSource.objects.filter(
- context_record__operation=self).count() + \
- FindSource.objects.filter(
- find__base_finds__context_record__operation=self).count()
+ nbs = self.documents.count() + \
+ Document.objects.filter(
+ context_records__operation=self).count() + \
+ Document.objects.filter(
+ finds__base_finds__context_record__operation=self).count()
return nbs
@property
@@ -899,16 +886,14 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return self._get_or_set_stats('_nb_documents_by_types', update)
def _nb_documents_by_types(self):
- from archaeological_context_records.models import ContextRecordSource
- from archaeological_finds.models import FindSource
docs = {}
qs = [
- self.source,
- ContextRecordSource.objects.filter(context_record__operation=self),
- FindSource.objects.filter(
- find__upstream_treatment_id__isnull=True,
- find__base_finds__context_record__operation=self)]
+ self.documents,
+ Document.objects.filter(context_records__operation=self),
+ Document.objects.filter(
+ finds__upstream_treatment_id__isnull=True,
+ finds__base_finds__context_record__operation=self)]
for q in qs:
for res in q.values('source_type').distinct():
st = res['source_type']
@@ -982,11 +967,6 @@ def operation_post_save(sender, **kwargs):
post_save.connect(operation_post_save, sender=Operation)
-class OperationImage(ThroughImage):
- item = models.ForeignKey(Operation, on_delete=models.CASCADE,
- related_name='associated_images')
-
-
class RelationType(GeneralRelationType):
class Meta:
@@ -1044,70 +1024,6 @@ class OperationByDepartment(models.Model):
db_table = 'operation_department'
-class OperationSource(BaseSource):
- SHOW_URL = 'show-operationsource'
- MODIFY_URL = 'operation_source_modify'
- TABLE_COLS = ['operation__code_patriarche', 'operation__year',
- 'operation__operation_code', 'code'] + BaseSource.TABLE_COLS
-
- # search parameters
- BOOL_FIELDS = ['duplicate']
- EXTRA_REQUEST_KEYS = {
- 'title': 'title__icontains',
- 'description': 'description__icontains',
- 'comment': 'comment__icontains',
- 'additional_information': 'additional_information__icontains',
- 'person': 'authors__person__pk',
- 'operation__towns': 'operation__towns__pk',
- 'operation__operation_code': 'operation__operation_code',
- 'operation__code_patriarche': 'operation__code_patriarche',
- 'operation__operation_type': 'operation__operation_type__pk',
- 'operation__year': 'operation__year'}
- COL_LABELS = {
- 'operation__year': _(u"Operation year"),
- 'operation__operation_code': _(u"Operation code"),
- 'code': _(u"Document code")
- }
- PARENT_SEARCH_VECTORS = BaseSource.PARENT_SEARCH_VECTORS + ['operation']
-
- # fields
- operation = models.ForeignKey(Operation, verbose_name=_(u"Operation"),
- related_name="source")
-
- class Meta:
- verbose_name = _(u"Operation documentation")
- verbose_name_plural = _(u"Operation documentations")
- permissions = (
- ("view_operationsource",
- ugettext(u"Can view all Operation sources")),
- ("view_own_operationsource",
- ugettext(u"Can view own Operation source")),
- ("add_own_operationsource",
- ugettext(u"Can add own Operation source")),
- ("change_own_operationsource",
- ugettext(u"Can change own Operation source")),
- ("delete_own_operationsource",
- ugettext(u"Can delete own Operation source")),
- )
-
- @property
- def owner(self):
- return self.operation
-
- @property
- def code(self):
- if not self.index:
- return u"{}-".format(self.operation.code_patriarche or '')
- return u"{}-{:04d}".format(self.operation.code_patriarche or '',
- self.index)
-
- @classmethod
- def get_query_owns(cls, ishtaruser):
- return cls._construct_query_own(
- 'operation__', Operation._get_query_owns_dicts(ishtaruser)
- )
-
-
class ActType(GeneralType):
TYPE = (('F', _(u'Archaeological file')),
('O', _(u'Operation')),