summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-10-16 23:29:41 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-10-16 23:29:41 +0200
commit78cb0d4794a80c99e17f96a06e68951d5221d0f8 (patch)
treeceac818ab232d6fb74289ab31571de56086d7bb5
parentc5bf89a4177c3f40a9b02e721bdcc5e85fc136bf (diff)
downloadIshtar-78cb0d4794a80c99e17f96a06e68951d5221d0f8.tar.bz2
Ishtar-78cb0d4794a80c99e17f96a06e68951d5221d0f8.zip
List and export context record relations (refs #3329)
-rw-r--r--archaeological_context_records/forms.py2
-rw-r--r--archaeological_context_records/models.py19
-rw-r--r--archaeological_context_records/templates/ishtar/sheet_contextrecord.html30
-rw-r--r--archaeological_context_records/urls.py2
-rw-r--r--archaeological_context_records/views.py7
-rw-r--r--archaeological_operations/models.py4
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html5
-rw-r--r--ishtar_common/templatetags/window_tables.py5
-rw-r--r--ishtar_common/widgets.py2
9 files changed, 47 insertions, 29 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index d468e3a3c..4a5267654 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -214,7 +214,7 @@ class RecordFormGeneral(ManageOldType, forms.Form):
cr = models.ContextRecord.objects.filter(
label=label, parcel__operation__pk=operation_id)
if 'pk' in cleaned_data and cleaned_data['pk']:
- cr = cr.exclude(pk=cleaned_data['pk'])
+ cr = cr.exclude(pk=int(cleaned_data['pk']))
if cr.count():
raise forms.ValidationError(_(u"This ID already exists for "
u"this operation."))
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 5dc943275..e1cb216a2 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -363,6 +363,25 @@ class RecordRelations(GeneralRecordRelations, models.Model):
right_record = models.ForeignKey(ContextRecord,
related_name='left_relations')
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 = {
+ "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__parcel": _(u"Parcel (right)"),
+ "right_record__description": _(u"Description (right)"),
+ "right_record__datings__period": _(u"Periods (right)")
+ }
class Meta:
verbose_name = _(u"Record relation")
diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
index bd883ac0b..907697c9e 100644
--- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
+++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html
@@ -55,36 +55,12 @@
</ul>
{% endif %}
+{% trans "Context record relations" as cr_rels %}
{% if item.right_relations.count %}
-<h3>{% trans "In relation with"%}</h3>
-<div class='clean-table'>
-<div class='clean-table-wrap'>
-<table>
- <tr>
- <th>{% trans "Relation type" %}</th>
- <th>{% trans "ID" %}</th>
- <th>{% trans "Type" %}</th>
- <th>{% trans "Chronology" %}</th>
- <th>{% trans "Description" %}</th>
- <th>{% trans "Parcel" %}</th>
- <th class='link'>&nbsp;</th>
- </tr>
- {% for relation in item.right_relations.all %}
- <tr>
- <td class='string'>{{ relation.relation_type }}</td>
- <td class='string'>{{ relation.right_record.label }}</td>
- <td class='string'>{{relation.right_record.unit|default:""}}</td>
- <td class='string'>{{ relation.right_record.datings.all|join:", " }}</td>{# periods ?#}
- <td class='string'>{{ relation.right_record.description }}</td>
- <td class='string'>{{ relation.right_record.parcel.section }} - {{relation.right_record.parcel.parcel_number}}</td>
- <td class='link'><a href="#" class='display_details' onclick='load_window("{%url show-contextrecord relation.right_record.pk ''%}")'><i class="fa fa-info-circle" aria-hidden="true"></i></a></td>
- </tr>
- {% endfor %}
-</table>
-</div></div>
-
+{% dynamic_table_document cr_rels 'context_records_relations' 'left_record' item.pk '' output %}
{% endif %}
+
{% if item.operation %}
<h3>{% trans "Operation summary"%}</h3>
{% if not item.operation.code_patriarche %}
diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py
index a25559e29..24e8e06eb 100644
--- a/archaeological_context_records/urls.py
+++ b/archaeological_context_records/urls.py
@@ -92,6 +92,8 @@ urlpatterns += patterns(
url(r'get-contextrecord-shortcut/(?P<type>.+)?$',
'get_contextrecord', name='get-contextrecord-shortcut',
kwargs={'full': 'shortcut'}),
+ url(r'get-contextrecordrelation/(?P<type>.+)?$',
+ 'get_contextrecordrelation', name='get-contextrecordrelation'),
url(r'show-contextrecordsource(?:/(?P<pk>.+))?/(?P<type>.+)?$',
'show_contextrecordsource', name=models.ContextRecordSource.SHOW_URL),
url(r'get-contexrecordsource/(?P<type>.+)?$',
diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py
index bc95473e6..0ced39b20 100644
--- a/archaeological_context_records/views.py
+++ b/archaeological_context_records/views.py
@@ -121,6 +121,13 @@ get_contextrecordsource = get_item(
'context_record__unit': 'context_record__unit__pk',
})
+get_contextrecordrelation = get_item(
+ models.RecordRelations, 'get_contextrecordrelation',
+ 'contextrecordrelation',
+ extra_request_keys={
+ "left_record__operation": "left_record__operation__pk"
+ })
+
record_search_wizard = SearchWizard.as_view([
('general-record_search', RecordFormSelection)],
label=_(u"Context record search"),
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 4dd107da8..60a7359db 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -404,6 +404,10 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
def render_parcels(self):
return Parcel.render_parcels(list(self.parcels.all()))
+ def context_record_relations_q(self):
+ from archaeological_context_records.models import RecordRelations as CRRL
+ 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(
diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html
index 98a69a5f1..07f8d8ab0 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -113,6 +113,11 @@
{% dynamic_table_document '' 'context_records_for_ope' 'operation' item.pk 'TABLE_COLS_FOR_OPE' output %}
{% endif %}
+{% trans "Context record relations" as cr_rels %}
+{% if item.context_record_relations_q.count %}
+{% dynamic_table_document cr_rels 'context_records_relations' 'left_record__operation' item.pk '' output %}
+{% endif %}
+
{% trans "Documents from associated context records" as cr_docs %}
{% if item.context_record_docs_q.count %}
{% dynamic_table_document cr_docs 'context_records_docs' 'context_record__operation' item.pk '' output %}
diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py
index 578d94535..acb3d4a0a 100644
--- a/ishtar_common/templatetags/window_tables.py
+++ b/ishtar_common/templatetags/window_tables.py
@@ -15,7 +15,7 @@ from ishtar_common.widgets import JQueryJqGrid
from archaeological_files.models import File
from archaeological_operations.models import OperationSource, Operation
from archaeological_context_records.models import ContextRecord, \
- ContextRecordSource
+ ContextRecordSource, RecordRelations as CRRecordRelations
from archaeological_finds.models import Find, FindSource, \
FindUpstreamTreatments, FindDownstreamTreatments
@@ -39,6 +39,9 @@ ASSOCIATED_MODELS['context_records_for_ope'] = (
ASSOCIATED_MODELS['context_records_docs'] = (
ContextRecordSource,
'get-contextrecordsource', 'get-contextrecordsource-full')
+ASSOCIATED_MODELS['context_records_relations'] = (
+ CRRecordRelations, 'get-contextrecordrelation', '')
+
ASSOCIATED_MODELS['finds'] = (Find, 'get-find', 'get-find-full')
ASSOCIATED_MODELS['finds_for_ope'] = (
Find, 'get-find-for-ope', 'get-find-full')
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index 89eead988..48d1377fa 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -564,6 +564,8 @@ class JQueryJqGrid(forms.RadioSelect):
field_verbose_names.append(unicode(field_verbose_name))
if field_name in col_labels:
jq_col_names.append(unicode(col_labels[field_name]))
+ elif col_names and col_names[0] in col_labels:
+ jq_col_names.append(unicode(col_labels[col_names[0]]))
else:
jq_col_names.append(settings.JOINT.join(
[f for f in field_verbose_names if f]))