From 7f871c7698c56dce6f398e850a08d5619cebd243 Mon Sep 17 00:00:00 2001
From: Étienne Loks
Date: Thu, 16 Jun 2011 18:39:42 +0200
Subject: Correct the database link between context records and operations
(closes #482)
---
ishtar/furnitures/forms_context_records.py | 8 +++----
ishtar/furnitures/forms_items.py | 7 +++---
ishtar/furnitures/models.py | 2 ++
ishtar/furnitures/views.py | 10 ++++-----
ishtar/templates/sheet_contextrecord.html | 36 +++++++++++++++---------------
ishtar/templates/sheet_operation.html | 8 ++-----
6 files changed, 34 insertions(+), 37 deletions(-)
diff --git a/ishtar/furnitures/forms_context_records.py b/ishtar/furnitures/forms_context_records.py
index f5160a1bb..a46d67995 100644
--- a/ishtar/furnitures/forms_context_records.py
+++ b/ishtar/furnitures/forms_context_records.py
@@ -111,7 +111,7 @@ class RecordModifWizard(RecordWizard):
class RecordSelect(forms.Form):
parcel__town = get_town_field()
- parcel__operation__year = forms.IntegerField(label=_("Year"))
+ operation__year = forms.IntegerField(label=_("Year"))
datings__period = forms.ChoiceField(label=_("Period"),
choices=models.Period.get_types())
unit = forms.ChoiceField(label=_("Unit type"),
@@ -138,7 +138,7 @@ class RecordFormGeneral(forms.Form):
form_label = _("General")
associated_models = {'parcel':models.Parcel, 'unit':models.Unit}
pk = forms.IntegerField(required=False, widget=forms.HiddenInput)
- hidden_operation_id = forms.IntegerField(widget=forms.HiddenInput)
+ operation_id = forms.IntegerField(widget=forms.HiddenInput)
parcel = forms.ChoiceField(label=_("Parcel"), choices=[])
label = forms.CharField(label=_(u"ID"),
validators=[validators.MaxLengthValidator(200)])
@@ -172,7 +172,7 @@ class RecordFormGeneral(forms.Form):
super(RecordFormGeneral, self).__init__(*args, **kwargs)
self.fields['parcel'].choices = [('', '--')]
if operation:
- self.fields['hidden_operation_id'].initial = operation.pk
+ self.fields['operation_id'].initial = operation.pk
parcels = operation.parcels.all()
sort = lambda x: (x.town.name, x.section)
parcels = sorted(parcels, key=sort)
@@ -184,7 +184,7 @@ class RecordFormGeneral(forms.Form):
def clean(self):
# manage unique context record ID
cleaned_data = self.cleaned_data
- operation_id = cleaned_data.get("hidden_operation_id")
+ operation_id = cleaned_data.get("operation_id")
label = cleaned_data.get("label")
cr = models.ContextRecord.objects.filter(label=label,
parcel__operation__pk=operation_id)
diff --git a/ishtar/furnitures/forms_items.py b/ishtar/furnitures/forms_items.py
index 6efb705e2..b6da0f889 100644
--- a/ishtar/furnitures/forms_items.py
+++ b/ishtar/furnitures/forms_items.py
@@ -69,8 +69,7 @@ class ItemWizard(Wizard):
current_cr = self.get_current_contextrecord(request, storage)
if not current_cr:
return context
- # TOCHANGE
- operation = current_cr.parcel.operation
+ operation = current_cr.operation
items = []
if hasattr(operation, 'code_patriarche') and operation.code_patriarche:
items.append(unicode(operation.code_patriarche))
@@ -136,9 +135,9 @@ item_creation_wizard = ItemWizard([
class ItemSelect(forms.Form):
base_items__context_record__parcel__town = get_town_field()
- base_items__context_record__parcel__operation__year = forms.IntegerField(
+ base_items__context_record__operation__year = forms.IntegerField(
label=_(u"Year"))
- base_items__context_record__parcel__operation__code_patriarche = \
+ base_items__context_record__operation__code_patriarche = \
forms.IntegerField(label=_(u"Code PATRIARCHE"))
dating__period = forms.ChoiceField(
label=_(u"Period"), choices=models.Period.get_types())
diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py
index 3012511de..6a0999119 100644
--- a/ishtar/furnitures/models.py
+++ b/ishtar/furnitures/models.py
@@ -752,6 +752,8 @@ class ContextRecord(BaseHistorizedItem, OwnPerms):
TABLE_COLS.insert(1, 'parcel.operation.code_patriarche')
parcel = models.ForeignKey(Parcel, verbose_name=_(u"Parcel"),
related_name='context_record')
+ operation = models.ForeignKey(Operation, verbose_name=_(u"Operation"),
+ related_name='context_record')
label = models.CharField(_(u"ID"), max_length=200)
description = models.TextField(_("Description"), blank=True, null=True)
length = models.IntegerField(_(u"Length (cm)"), blank=True, null=True)
diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py
index 7516fdcda..fce7c7bf3 100644
--- a/ishtar/furnitures/views.py
+++ b/ishtar/furnitures/views.py
@@ -472,7 +472,7 @@ show_contextrecord = show_item(models.ContextRecord, 'contextrecord')
get_contextrecord = get_item(models.ContextRecord,
'get_contextrecord', 'contextrecord',
extra_request_keys={'parcel__town':'parcel__town__pk',
- 'parcel__operation__year':'parcel__operation__year__contains',
+ 'operation__year':'operation__year__contains',
'datings__period':'datings__period__pk'},)
get_archaeologicalitem = get_item(models.Item,
'get_archaeologicalitem', 'item',
@@ -480,10 +480,10 @@ get_archaeologicalitem = get_item(models.Item,
extra_request_keys={
'base_items__context_record__parcel__town':
'base_items__context_record__parcel__town',
-'base_items__context_record__parcel__operation__year':
- 'base_items__context_record__parcel__operation__year__contains',
-'base_items__context_record__parcel__operation__code_patriarche':
- 'base_items__context_record__parcel__operation__code_patriarche',
+'base_items__context_record__operation__year':
+ 'base_items__context_record__operation__year__contains',
+'base_items__context_record__operation__code_patriarche':
+ 'base_items__context_record__operation__code_patriarche',
'dating__period':'dating__period__pk',
'base_items__item__description':'base_items__item__description__icontains',
'base_items__is_isolated':'base_items__is_isolated'})
diff --git a/ishtar/templates/sheet_contextrecord.html b/ishtar/templates/sheet_contextrecord.html
index 13c11bd5b..13fd786a3 100644
--- a/ishtar/templates/sheet_contextrecord.html
+++ b/ishtar/templates/sheet_contextrecord.html
@@ -5,7 +5,7 @@
{% trans "Context Record"%}
-{% if item.parcel.operation.code_patriarche %}
+{% if item.operation.code_patriarche %}
{%trans "Complete ID:"%}
{% else %}
{%trans "Patriarche OA code not yet recorded!"%}
@@ -44,35 +44,35 @@
{% if item.tpq_estimated %}{% trans "TPQ estimated:" %} {{ item.tpq_estimated }}
{%endif%}
{%endif%}
-{% if item.parcel.operation %}
+{% if item.operation %}
{% trans "Operation resume"%}
-{%trans "Year:"%} {{ item.parcel.operation.year }}
-{%trans "Numerical reference:"%} {{ item.parcel.operation.numeric_reference }}
-{% if item.parcel.operation.code_patriarche %}
+{%trans "Year:"%} {{ item.operation.year }}
+{%trans "Numerical reference:"%} {{ item.operation.numeric_reference }}
+{% if item.operation.code_patriarche %}
{%trans "Patriarche OA code:"%}
-{{ item.parcel.operation.code_patriarche }}
+{{ item.operation.code_patriarche }}
{% else %}{%trans "Patriarche OA code not yet recorded!"%}
{%endif%}
{%trans "Operation's name:"%}
-{{ item.parcel.operation.internal_reference }}
+{{ item.operation.internal_reference }}
{%trans "Head scientist:"%}
-{{ item.parcel.operation.in_charge.full_label }}
+{{ item.operation.in_charge.full_label }}
{%trans "State:"%}
-{% if item.parcel.operation.is_active %}
+{% if item.operation.is_active %}
{%trans "Active file"%}
{% else %}
{%trans "Closed operation"%}
-{%trans "Closing date:"%} {{ item.parcel.operation.closing.date }}
-{%trans "by" %} {{ item.parcel.operation.closing.user }}
+{%trans "Closing date:"%} {{ item.operation.closing.date }}
+{%trans "by" %} {{ item.operation.closing.user }}
{% endif %}
-{%trans "Type:"%} {{ item.parcel.operation.operation_type }}
-{%trans "Remains:"%} {{ item.parcel.operation.remains.all|join:", " }}
-{%trans "Periods:"%} {{ item.parcel.operation.periods.all|join:", " }}
-{% if item.parcel.operation.comment %}{%trans "Comment:"%} {{ item.parcel.operation.comment }}
{%endif%}
+{%trans "Type:"%} {{ item.operation.operation_type }}
+{%trans "Remains:"%} {{ item.operation.remains.all|join:", " }}
+{%trans "Periods:"%} {{ item.operation.periods.all|join:", " }}
+{% if item.operation.comment %}{%trans "Comment:"%} {{ item.operation.comment }}
{%endif%}
{% trans "Localisation"%}
-{%trans "Towns:"%} {{ item.parcel.operation.towns.all|join:", " }}
+{%trans "Towns:"%} {{ item.operation.towns.all|join:", " }}
{%trans "Related operation:"%}
-{{ item.parcel.operation }}
+{{ item.operation }}
{# TODO: Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related operation #}
{% else %}{%trans "No operation linked to this context unit!"%}
{% endif %}
@@ -85,7 +85,7 @@
{% trans "Authors" %}
{% trans "Localisation" %}
- {% for doc in item.parcel.operation.documents.all %}
+ {% for doc in item.operation.documents.all %}
{{ doc.title }}
{{doc.type}}
diff --git a/ishtar/templates/sheet_operation.html b/ishtar/templates/sheet_operation.html
index b4c251197..db9d22cee 100644
--- a/ishtar/templates/sheet_operation.html
+++ b/ishtar/templates/sheet_operation.html
@@ -129,7 +129,7 @@
{% for parcel in item.parcels.all %}
- {% for context_record in parcel.context_record.all %}
+ {% for context_record in item.context_record.all %}
{{ context_record.label }}
{{context_record.unit}}
@@ -159,8 +159,7 @@
{% trans "Parcel" %}
- {% for parcel in item.parcels.all %}
- {% for context_record in parcel.context_record.all %}
+ {% for context_record in item.context_record.all %}
{% for find in context_record.base_items.all %}
{{ find.full_label }}
@@ -185,9 +184,6 @@
{% empty %}
{% trans "No find associated to parcel" %} {{parcel.short_label}} {% trans "(no context record)" %}
{% endfor %}
- {% empty %}
- {% trans "No find associated to this operation (no parcel)" %}
- {% endfor %}
--
cgit v1.2.3