summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-27 12:58:36 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-27 12:58:36 +0100
commit585fdd5e71d397a188af3285658795a1feee9516 (patch)
treefd7f7bf2661e890ff9fb0846aeea8dfecb07fa23
parentfbd88abd65711bfb6698ec6e4a365d90d1eea837 (diff)
downloadIshtar-585fdd5e71d397a188af3285658795a1feee9516.tar.bz2
Ishtar-585fdd5e71d397a188af3285658795a1feee9516.zip
Manage administrativ act registers (refs #1587)
* specific wizard * csv export * new actions
-rw-r--r--archaeological_operations/forms.py29
-rw-r--r--archaeological_operations/ishtar_menu.py13
-rw-r--r--archaeological_operations/models.py28
-rw-r--r--archaeological_operations/urls.py8
-rw-r--r--archaeological_operations/views.py12
5 files changed, 81 insertions, 9 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 0faad26a9..246fa88a6 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -30,7 +30,7 @@ from django.db.models import Max
from django.forms.formsets import DELETION_FIELD_NAME, TOTAL_FORM_COUNT
from django.shortcuts import render_to_response
from django.template import RequestContext
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from django.utils.safestring import mark_safe
from ishtar_common.models import valid_id, PersonType, Person, Town, \
@@ -682,3 +682,30 @@ class GenerateDocForm(forms.Form):
super(GenerateDocForm, self).__init__(*args, **kwargs)
self.fields['doc_generation'].choices = [('', u'-'*9)] + \
[(choice.pk , unicode(choice)) for choice in choices]
+
+class AdministrativeActRegisterSelect(TableSelect):
+ signature_date__year = forms.IntegerField(label=_(u"Year"))
+ act_type = forms.ChoiceField(label=_("Act type"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActRegisterSelect, self).__init__(*args, **kwargs)
+ self.fields['act_type'].choices = models.ActType.get_types()
+ self.fields['act_type'].help_text = models.ActType.get_help()
+
+class AdministrativeActRegisterFormSelection(forms.Form):
+ form_label = pgettext_lazy('admin act register',u"Register")
+ associated_models = {'pk':models.AdministrativeAct}
+ currents = {'pk':models.AdministrativeAct}
+ pk = forms.IntegerField(label="", required=False,
+ widget=widgets.JQueryJqGrid(reverse_lazy('get-administrativeact'),
+ AdministrativeActRegisterSelect, models.AdministrativeAct,
+ table_cols='TABLE_COLS',
+ source_full=reverse_lazy('get-administrativeact-full')),
+ validators=[valid_id(models.AdministrativeAct)])
+
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ if 'pk' not in cleaned_data or not cleaned_data['pk']:
+ raise forms.ValidationError(_(u"You should select an administrative"
+ " act."))
+ return cleaned_data
diff --git a/archaeological_operations/ishtar_menu.py b/archaeological_operations/ishtar_menu.py
index 6015ae43a..5fa3ab433 100644
--- a/archaeological_operations/ishtar_menu.py
+++ b/archaeological_operations/ishtar_menu.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
@@ -17,7 +17,7 @@
# See the file COPYING for details.
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from ishtar_common.menu_base import SectionItem, MenuItem
@@ -90,6 +90,15 @@ MENU_SECTIONS = [
])
]),
),
+ (35, SectionItem('administrativact_management', _(u"Administrative Act"),
+ childs=[
+ MenuItem('administrativact_register',
+ pgettext_lazy('admin act register',u"Register"),
+ model=models.AdministrativeAct,
+ access_controls=['view_administrativeact',
+ 'view_own_administrativeact']),
+ ])
+ ),
(102, SectionItem('dashboard', _(u"Dashboard"),
childs=[
MenuItem('dashboard_main', _(u"General informations"),
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 7648dd6bf..bbffe023f 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -25,6 +25,7 @@ from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed
+from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _, ugettext
from ishtar_common.utils import cached_label_changed
@@ -390,8 +391,8 @@ class ActType(GeneralType):
ordering = ('label',)
class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
- TABLE_COLS = ['act_type', 'associated_file', 'operation',
- 'associated_file.towns', 'operation.towns']
+ TABLE_COLS = ['year', 'index', 'act_type', 'signature_date',
+ 'associated_file', 'operation']
TABLE_COLS_FILE = ['act_type', 'associated_file', 'associated_file.towns',]
TABLE_COLS_OPE = ['act_type', 'operation', 'operation.towns']
act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
@@ -441,6 +442,22 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
for item in [self.operation, self.associated_file, self.act_object]
if item])
+ @property
+ def year(self):
+ if not self.signature_date:
+ return None
+ return self.signature_date.year
+ year_lbl = _(u"Year")
+
+ @property
+ def towns(self):
+ if self.associated_file:
+ return self.associated_file.towns.all()
+ elif self.operation:
+ return self.operation.towns.all()
+ return []
+ towns_lbl = _(u"Towns")
+
def get_filename(self, operation=False):
filename = ''
if operation and self.operation:
@@ -473,13 +490,14 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
if not self.index:
c_index = 1
q = AdministrativeAct.objects.filter(act_type__indexed=True,
- signature_date__year=year).order_by("-index")
+ signature_date__year=year,
+ index__isnull=False).order_by("-index")
if q.count():
- c_index = q.all()[0].index
+ c_index = q.all()[0].index + 1
self.index = c_index
if self.act_type.indexed:
conflict = AdministrativeAct.objects.filter(act_type__indexed=True,
- signature_date__year=year
+ signature_date__year=year,
index=self.index)
if self.pk:
conflict = conflict.exclude(pk=self.pk)
diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py
index e6a561f02..5f52254bd 100644
--- a/archaeological_operations/urls.py
+++ b/archaeological_operations/urls.py
@@ -52,6 +52,9 @@ urlpatterns = patterns('',
views.operation_closing_wizard, name='operation_closing'),
url(r'operation_deletion/(?P<step>.+)?$',
views.operation_deletion_wizard, name='operation_deletion'),
+ url(r'administrativact_register/(?P<step>.+)?$',
+ views.administrativact_register_wizard,
+ name='administrativact_register'),
)
urlpatterns += patterns('archaeological_operations.views',
@@ -71,6 +74,11 @@ urlpatterns += patterns('archaeological_operations.views',
'show_operation', name='show-historized-operation'),
url(r'get-administrativeactop/(?P<type>.+)?$',
'get_administrativeactop', name='get-administrativeactop'),
+ url(r'get-administrativeact/(?P<type>.+)?$',
+ 'get_administrativeact', name='get-administrativeact'),
+ url(r'get-administrativeact-full/(?P<type>.+)?$',
+ 'get_administrativeact', name='get-administrativeact-full',
+ kwargs={'full':True}),
url(r'generatedoc-administrativeactop/(?P<pk>.+)?/(?P<template_pk>.+)?$',
'generatedoc_administrativeactop',
name='generatedoc-administrativeactop'),
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index f48c55f57..e2fa5c868 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -24,7 +24,7 @@ from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template.defaultfilters import slugify
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from ishtar_common.views import get_item, show_item, revert_item, new_item
from ishtar_common.wizards import SearchWizard
@@ -149,6 +149,10 @@ get_administrativeactop = get_item(models.AdministrativeAct,
'operation__towns':'operation__towns__pk',
'act_type__intented_to':'act_type__intented_to'})
+get_administrativeact = get_item(models.AdministrativeAct,
+ 'get_administrativeact', 'administrativeact',
+ extra_request_keys={})
+
def dashboard_operation(request, *args, **kwargs):
"""
Operation dashboard
@@ -286,6 +290,12 @@ operation_administrativeactop_deletion_wizard = \
label=_(u"Operation: administrative act deletion"),
url_name='operation_administrativeactop_deletion',)
+administrativact_register_wizard = SearchWizard.as_view([
+ ('general-administrativact_register',
+ AdministrativeActRegisterFormSelection)],
+ label=pgettext_lazy('admin act register',u"Register"),
+ url_name='administrativact_register',)
+
def generatedoc_administrativeactop(request, pk, template_pk=None):
if (not request.user.has_perm('ishtar_common.view_operation',
models.Operation)