summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py79
1 files changed, 67 insertions, 12 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 3f4dc1598..cf39870ca 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -29,7 +29,7 @@ from ishtar_common.utils import cached_label_changed
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, OwnPerms, ShortMenuItem, Source, GeneralRelationType,\
GeneralRecordRelations, post_delete_record_relation, get_external_id, \
- ImageModel, post_save_cache
+ ImageModel, post_save_cache, ValueGetter
from archaeological_operations.models import Operation, Period, Parcel
@@ -118,7 +118,8 @@ post_save.connect(post_save_cache, sender=IdentificationType)
post_delete.connect(post_save_cache, sender=IdentificationType)
-class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
+class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms,
+ ValueGetter, ShortMenuItem):
SHOW_URL = 'show-contextrecord'
SLUG = 'contextrecord'
TABLE_COLS = ['parcel__town', 'operation__year',
@@ -127,8 +128,9 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
if settings.COUNTRY == 'fr':
TABLE_COLS.insert(1, 'operation__code_patriarche')
TABLE_COLS_FOR_OPE = ['label', 'parcel', 'unit',
- 'datings__period', 'description']
- TABLE_COLS_FOR_OPE_LBL = {'section__parcel_number': _("Parcel")}
+ 'datings__period__label', 'description']
+ COL_LABELS = {'section__parcel_number': _(u"Parcel"),
+ 'datings__period__label': _(u"Periods")}
CONTEXTUAL_TABLE_COLS = {
'full': {
'related_context_records': 'detailled_related_context_records'
@@ -155,6 +157,14 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
RELATIVE_SESSION_NAMES = [
('operation', 'operation__pk'),
('file', 'operation__associated_file__pk')]
+ EXTRA_FULL_FIELDS_LABELS = {
+ 'parcel__town': _(u"Parcel (town)"),
+ 'detailled_related_context_records': _(u"Related context records"),
+ 'operation__code_patriarche': u"Operation (code patriarche)",
+ 'parcel__external_id': _(u"Parcel (external ID)"),
+ 'datings__period': _(u"Datings (period)"),
+ 'parcel__year': _(u"Parcel (year)"),
+ }
# fields
external_id = models.TextField(_(u"External ID"), blank=True, null=True)
@@ -259,9 +269,9 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None):
- replace_query = {}
- if menu_filtr:
- replace_query = {'operation': menu_filtr}
+ replace_query = None
+ if menu_filtr and 'operation' in menu_filtr:
+ replace_query = Q(operation=menu_filtr['operation'])
owns = super(ContextRecord, cls).get_owns(
user, replace_query=replace_query,
limit=limit)
@@ -392,19 +402,18 @@ class RecordRelations(GeneralRecordRelations, models.Model):
relation_type = models.ForeignKey(RelationType)
TABLE_COLS = [
"left_record__label", "left_record__unit", "left_record__parcel",
- "left_record__datings__period", "left_record__description",
"relation_type",
"right_record__label", "right_record__unit", "right_record__parcel",
- "right_record__datings__period", "right_record__description"]
- TABLE_COLS_LBL = {
+ ]
+ COL_LABELS = {
"left_record__label": _(u"ID (left)"),
"left_record__unit": _(u"Unit (left)"),
"left_record__parcel": _(u"Parcel (left)"),
"left_record__description": _(u"Description (left)"),
"left_record__datings__period": _(u"Periods (left)"),
"relation_type": _(u"Relation type"),
- "right_record__label": _(u"Unit (right)"),
- "right_record__unit": _(u"Parcel (right)"),
+ "right_record__label": _(u"ID (right)"),
+ "right_record__unit": _(u"Unit (right)"),
"right_record__parcel": _(u"Parcel (right)"),
"right_record__description": _(u"Description (right)"),
"right_record__datings__period": _(u"Periods (right)")
@@ -422,6 +431,52 @@ class RecordRelations(GeneralRecordRelations, models.Model):
post_delete.connect(post_delete_record_relation, sender=RecordRelations)
+class RecordRelationView(models.Model):
+ """
+ CREATE VIEW record_relations AS
+ SELECT DISTINCT right_record_id as id,
+ right_record_id,
+ left_record_id,
+ relation_type_id
+ FROM archaeological_context_records_recordrelations;
+
+ -- deactivate deletion
+ CREATE RULE record_relations_del AS ON DELETE TO record_relations
+ DO INSTEAD DELETE FROM record_relations where id=NULL;
+ """
+ TABLE_COLS = [
+ "relation_type",
+ "right_record__label", "right_record__unit", "right_record__parcel",
+ "right_record__datings__period", "right_record__description"]
+ COL_LABELS = {
+ "relation_type": _(u"Relation type"),
+ "right_record__label": _(u"ID"),
+ "right_record__unit": _(u"Unit"),
+ "right_record__parcel": _(u"Parcel"),
+ "right_record__description": _(u"Description"),
+ "right_record__datings__period": _(u"Periods")
+ }
+
+ # search parameters
+ EXTRA_REQUEST_KEYS = {
+ "left_record_id": "left_record_id"
+ }
+ left_record = models.ForeignKey(ContextRecord, related_name='+',
+ on_delete=models.DO_NOTHING)
+ right_record = models.ForeignKey(ContextRecord, related_name='+',
+ on_delete=models.DO_NOTHING)
+ relation_type = models.ForeignKey(RelationType, related_name='+',
+ on_delete=models.DO_NOTHING)
+
+ class Meta:
+ managed = False
+ db_table = 'record_relations'
+ unique_together = ('id', 'right_record')
+
+ def __unicode__(self):
+ return u"{} \"{}\"".format(self.relation_type, self.right_record)
+
+
class ContextRecordSource(Source):
SHOW_URL = 'show-contextrecordsource'
MODIFY_URL = 'record_source_modify'