summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-16 18:39:42 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-16 18:39:42 +0200
commit7f871c7698c56dce6f398e850a08d5619cebd243 (patch)
treeaed266494a442ca241137370e7df7dc965febf5f
parent48691eebe6c933ffb3a9d41ba0ee09ff7d574a2d (diff)
downloadIshtar-7f871c7698c56dce6f398e850a08d5619cebd243.tar.bz2
Ishtar-7f871c7698c56dce6f398e850a08d5619cebd243.zip
Correct the database link between context records and operations (closes #482)
-rw-r--r--ishtar/furnitures/forms_context_records.py8
-rw-r--r--ishtar/furnitures/forms_items.py7
-rw-r--r--ishtar/furnitures/models.py2
-rw-r--r--ishtar/furnitures/views.py10
-rw-r--r--ishtar/templates/sheet_contextrecord.html36
-rw-r--r--ishtar/templates/sheet_operation.html8
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 @@
<h3>{% trans "Context Record"%}</h3>
-{% if item.parcel.operation.code_patriarche %}
+{% if item.operation.code_patriarche %}
<p><label>{%trans "Complete ID:"%}</label>
{% else %}
<p class='alert'><label>{%trans "Patriarche OA code not yet recorded!"%}</label></p>
@@ -44,35 +44,35 @@
{% if item.tpq_estimated %}<p><label>{% trans "TPQ estimated:" %}</label> <span class='value'>{{ item.tpq_estimated }}</span></p>{%endif%}
{%endif%}
-{% if item.parcel.operation %}
+{% if item.operation %}
<h3>{% trans "Operation resume"%}</h3>
-<p><label>{%trans "Year:"%}</label> <span class='value'>{{ item.parcel.operation.year }}</span></p>
-<p><label>{%trans "Numerical reference:"%}</label> <span class='value'>{{ item.parcel.operation.numeric_reference }}</span></p>
-{% if item.parcel.operation.code_patriarche %}
+<p><label>{%trans "Year:"%}</label> <span class='value'>{{ item.operation.year }}</span></p>
+<p><label>{%trans "Numerical reference:"%}</label> <span class='value'>{{ item.operation.numeric_reference }}</span></p>
+{% if item.operation.code_patriarche %}
<p><label>{%trans "Patriarche OA code:"%}</label>
-<span class='value'>{{ item.parcel.operation.code_patriarche }}</span></p>
+<span class='value'>{{ item.operation.code_patriarche }}</span></p>
{% else %}<p class='alert'><label>{%trans "Patriarche OA code not yet recorded!"%}</label></p>
{%endif%}
<p><label>{%trans "Operation's name:"%}</label>
-<span class='value'>{{ item.parcel.operation.internal_reference }}</span></p>
+<span class='value'>{{ item.operation.internal_reference }}</span></p>
<p><label>{%trans "Head scientist:"%}</label>
-<span class='value'>{{ item.parcel.operation.in_charge.full_label }}</span></p>
+<span class='value'>{{ item.operation.in_charge.full_label }}</span></p>
<p><label>{%trans "State:"%}</label>
-{% if item.parcel.operation.is_active %}
+{% if item.operation.is_active %}
<span class='value'>{%trans "Active file"%}</span></p>
{% else %}
<span class='value'>{%trans "Closed operation"%}</span></p>
-<p><label>{%trans "Closing date:"%}</label> <span class='value'>{{ item.parcel.operation.closing.date }}
-<strong>{%trans "by" %}</strong> {{ item.parcel.operation.closing.user }}</span></p>
+<p><label>{%trans "Closing date:"%}</label> <span class='value'>{{ item.operation.closing.date }}
+<strong>{%trans "by" %}</strong> {{ item.operation.closing.user }}</span></p>
{% endif %}
-<p><label>{%trans "Type:"%}</label> <span class='value'>{{ item.parcel.operation.operation_type }}</span></p>
-<p><label>{%trans "Remains:"%}</label> <span class='value'>{{ item.parcel.operation.remains.all|join:", " }}</span></p>
-<p><label>{%trans "Periods:"%}</label> <span class='value'>{{ item.parcel.operation.periods.all|join:", " }}</span></p>
-{% if item.parcel.operation.comment %}<p><label>{%trans "Comment:"%}</label> <span class='value'>{{ item.parcel.operation.comment }}</span></p>{%endif%}
+<p><label>{%trans "Type:"%}</label> <span class='value'>{{ item.operation.operation_type }}</span></p>
+<p><label>{%trans "Remains:"%}</label> <span class='value'>{{ item.operation.remains.all|join:", " }}</span></p>
+<p><label>{%trans "Periods:"%}</label> <span class='value'>{{ item.operation.periods.all|join:", " }}</span></p>
+{% if item.operation.comment %}<p><label>{%trans "Comment:"%}</label> <span class='value'>{{ item.operation.comment }}</span></p>{%endif%}
<h3>{% trans "Localisation"%}</h3>
-<p><label>{%trans "Towns:"%}</label> <span class='value'>{{ item.parcel.operation.towns.all|join:", " }}</span></p>
+<p><label>{%trans "Towns:"%}</label> <span class='value'>{{ item.operation.towns.all|join:", " }}</span></p>
<p><label>{%trans "Related operation:"%}</label>
-<span class='value'><a href="#" onclick='load_window("{% url show-operation item.parcel.operation.pk ''%}");'>{{ item.parcel.operation }}</a></span></p>
+<span class='value'><a href="#" onclick='load_window("{% url show-operation item.operation.pk ''%}");'>{{ item.operation }}</a></span></p>
{# TODO: Displayed as Year/index/Commune/Common_name This should be a link to the file sheet of the related operation #}
{% else %}<p class='alert'><label>{%trans "No operation linked to this context unit!"%}</label></p>
{% endif %}
@@ -85,7 +85,7 @@
<th>{% trans "Authors" %}</th>
<th>{% trans "Localisation" %}</th>
</tr>
- {% for doc in item.parcel.operation.documents.all %}
+ {% for doc in item.operation.documents.all %}
<tr>
<td>{{ doc.title }}</td>
<td class='string'>{{doc.type}}</td>
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 @@
<th class='link'>&nbsp;</th>
</tr>
{% for parcel in item.parcels.all %}
- {% for context_record in parcel.context_record.all %}
+ {% for context_record in item.context_record.all %}
<tr>
<td>{{ context_record.label }}</td>
<td class='string'>{{context_record.unit}}</td>
@@ -159,8 +159,7 @@
<th>{% trans "Parcel" %}</th>
<th class='link'>&nbsp;</th>
</tr>
- {% 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 %}
<tr>
<td>{{ find.full_label }}</td>
@@ -185,9 +184,6 @@
{% empty %}
<tr><td colspan="9" class='no_items'>{% trans "No find associated to parcel" %} {{parcel.short_label}} {% trans "(no context record)" %}</td></tr>
{% endfor %}
- {% empty %}
- <tr><td colspan="9" class='no_items'>{% trans "No find associated to this operation (no parcel)" %}</td></tr>
- {% endfor %}
</table>