From 78cb0d4794a80c99e17f96a06e68951d5221d0f8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 16 Oct 2016 23:29:41 +0200 Subject: List and export context record relations (refs #3329) --- archaeological_context_records/forms.py | 2 +- archaeological_context_records/models.py | 19 ++++++++++++++ .../templates/ishtar/sheet_contextrecord.html | 30 +++------------------- archaeological_context_records/urls.py | 2 ++ archaeological_context_records/views.py | 7 +++++ 5 files changed, 32 insertions(+), 28 deletions(-) (limited to 'archaeological_context_records') 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 @@ {% endif %} +{% trans "Context record relations" as cr_rels %} {% if item.right_relations.count %} -

{% trans "In relation with"%}

-
-
- - - - - - - - - - - {% for relation in item.right_relations.all %} - - - - - {# periods ?#} - - - - - {% endfor %} -
{% trans "Relation type" %}{% trans "ID" %}{% trans "Type" %}{% trans "Chronology" %}{% trans "Description" %}{% trans "Parcel" %} 
{{ relation.relation_type }}{{ relation.right_record.label }}{{relation.right_record.unit|default:""}}{{ relation.right_record.datings.all|join:", " }}{{ relation.right_record.description }}{{ relation.right_record.parcel.section }} - {{relation.right_record.parcel.parcel_number}}
-
- +{% dynamic_table_document cr_rels 'context_records_relations' 'left_record' item.pk '' output %} {% endif %} + {% if item.operation %}

{% trans "Operation summary"%}

{% 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.+)?$', 'get_contextrecord', name='get-contextrecord-shortcut', kwargs={'full': 'shortcut'}), + url(r'get-contextrecordrelation/(?P.+)?$', + 'get_contextrecordrelation', name='get-contextrecordrelation'), url(r'show-contextrecordsource(?:/(?P.+))?/(?P.+)?$', 'show_contextrecordsource', name=models.ContextRecordSource.SHOW_URL), url(r'get-contexrecordsource/(?P.+)?$', 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"), -- cgit v1.2.3