summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_files/models.py6
-rw-r--r--archaeological_files/templates/ishtar/sheet_file.html22
-rw-r--r--archaeological_operations/models.py21
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html8
-rw-r--r--archaeological_operations/views.py2
5 files changed, 52 insertions, 7 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index a91f6ed69..1e2c36ed0 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2012-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -133,6 +133,10 @@ class File(BaseHistorizedItem, OwnPerms):
for k in ['internal_reference',] if getattr(self, k)]
return settings.JOINT.join(items)
+ def grouped_parcels(self):
+ from archaeological_operations.models import Parcel
+ return Parcel.grouped_parcels(list(self.parcels.all()))
+
@classmethod
def get_query_owns(cls, user):
return Q(history_modifier=user) & Q(end_date__isnull=True)
diff --git a/archaeological_files/templates/ishtar/sheet_file.html b/archaeological_files/templates/ishtar/sheet_file.html
index 1b58aa332..bdf0bd4ff 100644
--- a/archaeological_files/templates/ishtar/sheet_file.html
+++ b/archaeological_files/templates/ishtar/sheet_file.html
@@ -63,6 +63,28 @@
{% endif %}
<table>
+ <caption>{%trans "Associated parcels"%}</caption>
+ <tr>
+ <th>{% trans "Commune" %}</th>
+ <th>{% trans "Year" %}</th>
+ <th>{% trans "Section" %}</th>
+ <th>{% trans "Parcels" %}</th>
+ {#<th>{% trans "Owner" %}</th>#}
+ </tr>
+ {% for parcel in item.grouped_parcels %}
+ <tr>
+ <td class='string'>{{parcel.town}}</td>
+ <td>{{parcel.year}}</td>
+ <td>{{parcel.section}}</td>
+ <td>{{parcel.parcel_numbers|join:", "}}</td>
+ {#<td class='string'>{{operation.parcel.owner}}</td>#}
+ </tr>
+ {% empty %}
+ <tr><td colspan="4" class='no_items'>{% trans "No parcel associated to this operation" %}</td></tr>
+ {% endfor %}
+</table>
+
+<table>
<caption>{%trans "Admninistrative acts"%}</caption>
<tr>
<th>{% trans "Year" %}</th>
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 675666dbb..02ec1a912 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2012-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -18,6 +18,7 @@
# See the file COPYING for details.
import datetime
+from itertools import groupby
from django.conf import settings
from django.contrib.gis.db import models
@@ -137,6 +138,9 @@ class Operation(BaseHistorizedItem, OwnPerms):
unicode(self.operation_code))))
return settings.JOINT.join(items)
+ def grouped_parcels(self):
+ return Parcel.grouped_parcels(list(self.parcels.all()))
+
@classmethod
def get_available_operation_code(cls, year=None):
if not year:
@@ -328,6 +332,21 @@ class Parcel(LightHistorizedItem):
def __unicode__(self):
return self.short_label()
+ @staticmethod
+ def grouped_parcels(parcels):
+ sortkeyfn = lambda s:(getattr(s, 'year'), getattr(s, 'town'),
+ getattr(s, 'section'))
+ parcels.sort(key=sortkeyfn)
+ grouped = []
+ for keys, parcel_grp in groupby(parcels, key=sortkeyfn):
+ for idx, parcel in enumerate(parcel_grp):
+ if not idx:
+ grouped.append(parcel)
+ grouped[-1].parcel_numbers = []
+ grouped[-1].parcel_numbers.append(parcel.parcel_number)
+ grouped[-1].parcel_numbers.sort()
+ return grouped
+
def long_label(self):
items = [unicode(self.operation or self.associated_file)]
items += [unicode(item) for item in [self.section, self.parcel_number]
diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html
index 1698f0224..491304125 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -61,15 +61,15 @@
<th>{% trans "Commune" %}</th>
<th>{% trans "Year" %}</th>
<th>{% trans "Section" %}</th>
- <th>{% trans "Parcel" %}</th>
+ <th>{% trans "Parcels" %}</th>
{#<th>{% trans "Owner" %}</th>#}
</tr>
- {% for parcel in item.parcels.all %}
+ {% for parcel in item.grouped_parcels %}
<tr>
<td class='string'>{{parcel.town}}</td>
<td>{{parcel.year}}</td>
<td>{{parcel.section}}</td>
- <td>{{parcel.parcel_number}}</td>
+ <td>{{parcel.parcel_numbers|join:", "}}</td>
{#<td class='string'>{{operation.parcel.owner}}</td>#}
</tr>
{% empty %}
@@ -78,7 +78,7 @@
</table>
<table>
- <caption>{%trans "Admninistrative acts"%}</caption>
+ <caption>{%trans "Administrative acts"%}</caption>
<tr>
<th>{% trans "Year" %}</th>
<th>{% trans "Reference" %}</th>
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 84f208bf3..6e570fc97 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as