summaryrefslogtreecommitdiff
path: root/archaeological_files
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2014-10-21 00:35:40 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2014-10-21 00:35:40 +0200
commit8a2d977a8a2dabb1513bb4f809fbf3ee5c641c72 (patch)
treea7fe5e03a2ca360c2e1e4af6e690d2d6e4bd4fcb /archaeological_files
parent57cdf8896f854de7ba573cfe8d5040155df1e656 (diff)
downloadIshtar-8a2d977a8a2dabb1513bb4f809fbf3ee5c641c72.tar.bz2
Ishtar-8a2d977a8a2dabb1513bb4f809fbf3ee5c641c72.zip
Dashboard: work on graphs for operations (refs #2076)
* add a new creation date field for operations * refactoring of management of dashboard forms * dashboard form for operations
Diffstat (limited to 'archaeological_files')
-rw-r--r--archaeological_files/forms.py5
-rw-r--r--archaeological_files/models.py44
2 files changed, 6 insertions, 43 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 68a004e4f..d2e31d80c 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -42,7 +42,7 @@ from ishtar_common.forms import FinalForm, FormSet, ClosingDateFormSelection, \
from ishtar_common.forms_common import get_town_field, get_person_field
from archaeological_operations.forms import AdministrativeActOpeForm, \
AdministrativeActOpeFormSelection, FinalAdministrativeActDeleteForm, \
- ParcelField
+ ParcelField, SLICING
from ishtar_common import widgets
GENERAL_CONTRACTOR, created = PersonType.objects.get_or_create(
@@ -122,7 +122,6 @@ class FileFormSelection(forms.Form):
raise forms.ValidationError(_(u"You should select a file."))
return cleaned_data
-SLICING = (("month",_(u"months")), ('year',_(u"years")),)
DATE_SOURCE = (('creation',_(u"Creation date")),
("reception",_(u"Reception date")))
@@ -143,6 +142,8 @@ class DashboardForm(forms.Form):
widget=widgets.JQueryDate, required=False)
def __init__(self, *args, **kwargs):
+ if 'prefix' not in kwargs:
+ kwargs['prefix'] = 'files'
super(DashboardForm, self).__init__(*args, **kwargs)
self.fields['saisine_type'].choices = models.SaisineType.get_types()
self.fields['file_type'].choices = models.FileType.get_types()
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index a649ceac1..4483e6401 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -30,7 +30,7 @@ from ishtar_common.utils import cached_label_changed, get_cache
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, OwnPerms, Person, Organization, Department, Town, \
- Dashboard, IshtarUser, ValueGetter, ShortMenuItem
+ Dashboard, DashboardFormItem, IshtarUser, ValueGetter, ShortMenuItem
class FileType(GeneralType):
class Meta:
@@ -61,7 +61,8 @@ if settings.COUNTRY == 'fr':
verbose_name_plural = u"Types Saisine"
ordering = ('label',)
-class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):
+class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,
+ DashboardFormItem):
TABLE_COLS = ['numeric_reference', 'year', 'internal_reference',
'file_type', 'saisine_type', 'towns', ]
year = models.IntegerField(_(u"Year"),
@@ -229,45 +230,6 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):
owns = super(File, cls).get_owns(user)
return sorted(owns.all(), key=lambda x:x.cached_label)
- @classmethod
- def get_periods(cls, slice='month', fltr={}, date_source='creation'):
- date_var = date_source + '_date'
- q = cls.objects.filter(**{date_var+'__isnull':False})
- if fltr:
- q = q.filter(**fltr)
- if slice == 'year':
- return [res[date_var].year for res in list(q.values(date_var
- ).annotate(Count("id")).order_by())]
- elif slice == 'month':
- return [(res[date_var].year, res[date_var].month)
- for res in list(q.values(date_var
- ).annotate(Count("id")).order_by())]
- return []
-
- @classmethod
- def get_by_year(cls, year, fltr={}, date_source='creation'):
- date_var = date_source + '_date'
- q = cls.objects.filter(**{date_var+'__isnull':False})
- if fltr:
- q = q.filter(**fltr)
- return q.filter(**{date_var+'__year':year})
-
- @classmethod
- def get_by_month(cls, year, month, fltr={}, date_source='creation'):
- date_var = date_source + '_date'
- q = cls.objects.filter(**{date_var+'__isnull':False})
- if fltr:
- q = q.filter(**fltr)
- q = q.filter(**{date_var+'__year':year, date_var+'__month':month})
- return q
-
- @classmethod
- def get_total_number(cls, fltr={}):
- q = cls.objects
- if fltr:
- q = q.filter(**fltr)
- return q.count()
-
def get_values(self, prefix=''):
values = super(File, self).get_values(prefix=prefix)
values['adminact_associated_file_towns_count'] = unicode(