summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/forms.py43
-rw-r--r--archaeological_operations/views.py7
-rw-r--r--archaeological_operations/wizards.py98
3 files changed, 82 insertions, 66 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 691b0c90c..b1f2e053b 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -26,16 +26,13 @@ from itertools import groupby
from django import forms
from django.conf import settings
from django.core import validators
-from django.core.exceptions import ObjectDoesNotExist
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 _, pgettext_lazy
from django.utils.safestring import mark_safe
from ishtar_common.models import valid_id, PersonType, Person, Town, \
- DocumentTemplate, Organization, OrganizationType
+ DocumentTemplate, Organization, OrganizationType
from ishtar_common.wizards import MultiValueDict
@@ -48,15 +45,14 @@ import models
from widgets import ParcelWidget, SelectParcelWidget
from ishtar_common import widgets
-from ishtar_common.forms import BaseFormSet, FinalForm, FormSet, \
- ClosingDateFormSelection, formset_factory, get_now, reverse_lazy, \
- get_form_selection, TableSelect
-from ishtar_common.forms_common import TownForm, TownFormSet, TownFormset, \
- AuthorFormset, SourceForm, SourceSelect, \
- SourceDeletionForm, get_town_field
+from ishtar_common.forms import FinalForm, FormSet, formset_factory, get_now, \
+ reverse_lazy, get_form_selection, TableSelect
+from ishtar_common.forms_common import TownFormSet, SourceForm, SourceSelect, \
+ get_town_field
from archaeological_operations.utils import parse_parcels
+
class ParcelField(forms.MultiValueField):
def __init__(self, *args, **kwargs):
if 'widget' not in kwargs:
@@ -66,19 +62,22 @@ class ParcelField(forms.MultiValueField):
def compress(data_list):
return u"-".join(data_list)
+
class ParcelForm(forms.Form):
form_label = _("Parcels")
base_model = 'parcel'
- associated_models = {'parcel':models.Parcel, 'town':models.Town,}
+ associated_models = {'parcel': models.Parcel, 'town': models.Town, }
town = forms.ChoiceField(label=_("Town"), choices=(), required=False,
validators=[valid_id(models.Town)])
year = forms.IntegerField(label=_("Year"), required=False,
- validators=[validators.MinValueValidator(1900),
- validators.MaxValueValidator(2100)])
+ validators=[validators.MinValueValidator(1900),
+ validators.MaxValueValidator(2100)])
section = forms.CharField(label=_(u"Section"), required=False,
- validators=[validators.MaxLengthValidator(4)])
- parcel_number = forms.CharField(label=_(u"Parcel number"), required=False,
- validators=[validators.MaxLengthValidator(6)])
+ validators=[validators.MaxLengthValidator(4)])
+ parcel_number = forms.CharField(
+ label=_(u"Parcel number"), required=False,
+ validators=[validators.MaxLengthValidator(6)])
+
def __init__(self, *args, **kwargs):
towns = None
if 'data' in kwargs and 'TOWNS' in kwargs['data']:
@@ -524,12 +523,12 @@ class DashboardForm(forms.Form):
class OperationFormGeneral(forms.Form):
form_label = _(u"General")
base_model = 'archaeological_site'
- associated_models = {'scientist':Person,
- 'in_charge':Person,
- 'cira_rapporteur':Person,
- 'operator':Organization,
- 'operation_type':models.OperationType,
- 'archaeological_site':models.ArchaeologicalSite}
+ associated_models = {'scientist': Person,
+ 'in_charge': Person,
+ 'cira_rapporteur': Person,
+ 'operator': Organization,
+ 'operation_type': models.OperationType,
+ 'archaeological_site': models.ArchaeologicalSite}
pk = forms.IntegerField(required=False, widget=forms.HiddenInput)
scientist = forms.IntegerField(label=_("Head scientist"),
widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person',
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index a8ded32cf..5e7288caa 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -18,21 +18,23 @@
# See the file COPYING for details.
import json
-import os
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
-from django.template.defaultfilters import slugify
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
+from ishtar_common.forms import ClosingDateFormSelection
+from ishtar_common.forms_common import AuthorFormset, TownFormset, \
+ SourceDeletionForm
from wizards import *
from forms import *
import models
+
def autocomplete_patriarche(request, non_closed=True):
if (not request.user.has_perm('ishtar_common.view_operation',
models.Operation)
@@ -56,6 +58,7 @@ def autocomplete_patriarche(request, non_closed=True):
for operation in operations])
return HttpResponse(data, mimetype='text/plain')
+
def autocomplete_archaeologicalsite(request):
if (not request.user.has_perm(
'archaeological_operations.view_archaeologicalsite',
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py
index 9e6b9d03a..644bc7390 100644
--- a/archaeological_operations/wizards.py
+++ b/archaeological_operations/wizards.py
@@ -27,30 +27,28 @@ from django.utils.translation import ugettext_lazy as _
from ishtar_common.forms import reverse_lazy
from ishtar_common.wizards import Wizard, ClosingWizard, DeletionWizard, \
- SourceWizard
+ SourceWizard
import models
-from forms import ParcelForm, GenerateDocForm
+from forms import GenerateDocForm
FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS
if FILES_AVAILABLE:
from archaeological_files.models import File
+
class OperationWizard(Wizard):
model = models.Operation
object_parcel_type = 'operation'
parcel_step_key = 'parcelsgeneral-'
# step contening the current(s) town(s)
town_step_keys = ['towns-', 'townsgeneral-']
- town_input_id = 'town' # input id of the current(s) town(s)
- multi_towns = True # true if current town are multi
+ town_input_id = 'town' # input id of the current(s) town(s)
+ multi_towns = True # true if current town are multi
wizard_done_window = reverse_lazy('show-operation')
def get_template_names(self):
templates = super(OperationWizard, self).get_template_names()
current_step = self.steps.current
- if current_step.startswith('towns-'):
- #templates = ['ishtar/wizard/towns_wizard.html'] + templates
- pass
if current_step.startswith(self.parcel_step_key):
templates = ['ishtar/wizard/parcels_wizard.html'] + templates
return templates
@@ -88,10 +86,10 @@ class OperationWizard(Wizard):
elif step.startswith('parcels-') and self.get_current_file():
# if a file is acciated to the operation add the button "Add all"
context['add_all'] = True
- if step.startswith('parcels') and\
+ if step.startswith('parcels') and \
hasattr(self, 'automatic_parcel_association'):
context['automatic_parcel_association'] = \
- self.automatic_parcel_association
+ self.automatic_parcel_association
# reminder of the current file
reminder = self.get_reminder()
if reminder:
@@ -112,7 +110,7 @@ class OperationWizard(Wizard):
towns = [(town.pk, unicode(town)) for town in file.towns.all()]
except (ValueError, ObjectDoesNotExist):
pass
- return sorted(towns, key=lambda x:x[1])
+ return sorted(towns, key=lambda x: x[1])
def get_available_parcels(self, file):
self.automatic_parcel_association = False
@@ -136,7 +134,7 @@ class OperationWizard(Wizard):
self.automatic_parcel_association = True
except (ValueError, ObjectDoesNotExist):
pass
- return sorted(parcels, key=lambda x:x[1])
+ return sorted(parcels, key=lambda x: x[1])
def get_form(self, step=None, data=None, files=None):
"""
@@ -147,14 +145,13 @@ class OperationWizard(Wizard):
else:
data = {}
if not step:
- #step = self.determine_step(request, storage)
step = self.steps.current
form = self.get_form_list()[step]
# manage the dynamic choice of towns
if step.startswith('towns') and hasattr(form, 'management_form'):
data['TOWNS'] = self.get_towns()
elif step.startswith(self.parcel_step_key) \
- and hasattr(form, 'management_form'):
+ and hasattr(form, 'management_form'):
file = self.get_current_file()
if file:
data['PARCELS'] = self.get_available_parcels(file)
@@ -162,12 +159,13 @@ class OperationWizard(Wizard):
town_ids = []
for town_step_key in self.town_step_keys:
town_form_key = town_step_key + self.url_name
- town_ids = self.session_get_value(town_form_key,
- self.town_input_id,
- multi=self.multi_towns) or []
- if town_ids:
+ town_ids = self.session_get_value(
+ town_form_key, self.town_input_id,
+ multi=self.multi_towns) or []
+ if town_ids and type(town_ids) == unicode:
+ town_ids = town_ids.split(',')
break
- if not self.multi_towns and town_ids:
+ if type(town_ids) not in (list, tuple):
town_ids = [town_ids]
towns = []
for town_id in town_ids:
@@ -176,7 +174,7 @@ class OperationWizard(Wizard):
towns.append((town.pk, unicode(town)))
except (ValueError, ObjectDoesNotExist):
pass
- data['TOWNS'] = sorted(towns, key=lambda x:x[1])
+ data['TOWNS'] = sorted(towns, key=lambda x: x[1])
data = data or None
form = super(OperationWizard, self).get_form(step, data, files)
return form
@@ -188,7 +186,7 @@ class OperationWizard(Wizard):
datas = super(OperationWizard, self).get_formated_datas(forms)
# if the general town form is used the advertissement is relevant
has_no_af = [form.prefix for form in forms
- if form.prefix == 'townsgeneral-operation'] and True
+ if form.prefix == 'townsgeneral-operation'] and True
if has_no_af:
datas = [[_(u"Warning: No Archaelogical File is provided. "
u"If you have forget it return to the first step."), []]]\
@@ -259,21 +257,26 @@ class OperationWizard(Wizard):
request.POST = post_data
return super(OperationWizard, self).post(*args, **kwargs)
+
class OperationModificationWizard(OperationWizard):
modification = True
+
class OperationClosingWizard(ClosingWizard):
model = models.Operation
fields = ['year', 'operation_code', 'operation_type', 'associated_file',
'in_charge', 'scientist', 'start_date', 'excavation_end_date',
'comment', 'towns', 'remains']
+
class OperationDeletionWizard(DeletionWizard):
model = models.Operation
fields = OperationClosingWizard.fields
+
class OperationSourceWizard(SourceWizard):
model = models.OperationSource
+
def get_form_initial(self, step, data=None):
initial = super(OperationSourceWizard, self).get_form_initial(step)
# put default index and operation_id field in the main source form
@@ -297,14 +300,16 @@ class OperationSourceWizard(SourceWizard):
initial['hidden_operation_id'] = operation_id
if 'index' not in initial:
max_val = models.OperationSource.objects.filter(
- operation__pk=operation_id).aggregate(
- Max('index'))["index__max"]
+ operation__pk=operation_id).aggregate(
+ Max('index'))["index__max"]
initial['index'] = max_val and (max_val + 1) or 1
return initial
+
class OperationSourceDeletionWizard(DeletionWizard):
model = models.OperationSource
- fields = ['operation', 'title', 'source_type', 'authors',]
+ fields = ['operation', 'title', 'source_type', 'authors']
+
class OperationAdministrativeActWizard(OperationWizard):
edit = False
@@ -317,8 +322,10 @@ class OperationAdministrativeActWizard(OperationWizard):
# and '_deletion' so it is creation
operation_id = self.session_get_value(form_key, "pk")
try:
- return ((_(u"Operation"),
- unicode(models.Operation.objects.get(pk=operation_id))),)
+ return (
+ (_(u"Operation"),
+ unicode(models.Operation.objects.get(pk=operation_id))),
+ )
except models.Operation.DoesNotExist:
return
else:
@@ -337,8 +344,8 @@ class OperationAdministrativeActWizard(OperationWizard):
def get_context_data(self, form, **kwargs):
# manage document generation
- context = super(OperationAdministrativeActWizard, self
- ).get_context_data(form, **kwargs)
+ context = super(OperationAdministrativeActWizard,
+ self).get_context_data(form, **kwargs)
step = self.steps.current
if step.startswith('final-'):
general_form_key = 'administrativeact-' + self.url_name
@@ -349,7 +356,7 @@ class OperationAdministrativeActWizard(OperationWizard):
pass
if act_type and act_type.associated_template.count():
context['extra_form'] = GenerateDocForm(
- choices=act_type.associated_template.all())
+ choices=act_type.associated_template.all())
return context
def get_associated_item(self, dct):
@@ -386,7 +393,7 @@ class OperationAdministrativeActWizard(OperationWizard):
r = r[k]
else:
break
- if k == keys[-1]: # the whole list as been traversed
+ if k == keys[-1]: # the whole list as been traversed
wizard_done_window = unicode(self.wizard_done_window)
if wizard_done_window:
dct['wizard_done_window'] = wizard_done_window
@@ -399,29 +406,34 @@ class OperationAdministrativeActWizard(OperationWizard):
context_instance=RequestContext(self.request))
return res
+
class OperationEditAdministrativeActWizard(OperationAdministrativeActWizard):
model = models.AdministrativeAct
edit = True
+
def get_associated_item(self, dct):
return self.get_current_object().operation
+
class AdministrativeActDeletionWizard(ClosingWizard):
wizard_templates = {
- 'final-operation_administrativeactop_deletion':\
- 'ishtar/wizard/wizard_adminact_deletion.html',
- 'final-file_administrativeactfile_deletion':\
- 'ishtar/wizard/wizard_adminact_deletion.html'}
+ 'final-operation_administrativeactop_deletion':
+ 'ishtar/wizard/wizard_adminact_deletion.html',
+ 'final-file_administrativeactfile_deletion':
+ 'ishtar/wizard/wizard_adminact_deletion.html'}
model = models.AdministrativeAct
fields = ['act_type', 'in_charge', 'operator', 'scientist', 'signatory',
- 'operation', 'associated_file', 'signature_date', 'act_object',]
+ 'operation', 'associated_file', 'signature_date', 'act_object']
if settings.COUNTRY == 'fr':
fields += ['ref_sra']
def done(self, form_list, **kwargs):
obj = self.get_current_object()
obj.delete()
- return render_to_response('ishtar/wizard/wizard_delete_done.html', {},
- context_instance=RequestContext(self.request))
+ return render_to_response(
+ 'ishtar/wizard/wizard_delete_done.html', {},
+ context_instance=RequestContext(self.request))
+
def is_preventive(form_name, model, type_key='operation_type', key=''):
def func(self):
@@ -431,11 +443,11 @@ def is_preventive(form_name, model, type_key='operation_type', key=''):
'step_data' not in request.session[storage.prefix] or \
form_name not in request.session[storage.prefix]['step_data'] or\
form_name + '-' + type_key not in \
- request.session[storage.prefix]['step_data'][form_name]:
+ request.session[storage.prefix]['step_data'][form_name]:
return False
try:
- typ = request.session[storage.prefix]['step_data']\
- [form_name][form_name+'-'+type_key]
+ typ = request.session[storage.prefix][
+ 'step_data'][form_name][form_name+'-'+type_key]
if type(typ) in (list, tuple):
typ = typ[0]
typ = int(typ)
@@ -444,11 +456,13 @@ def is_preventive(form_name, model, type_key='operation_type', key=''):
return False
return func
+
def is_not_preventive(form_name, model, type_key='operation_type', key=''):
def func(self):
return not is_preventive(form_name, model, type_key, key)(self)
return func
+
def has_associated_file(form_name, file_key='associated_file', negate=False):
def func(self):
request = self.request
@@ -457,11 +471,11 @@ def has_associated_file(form_name, file_key='associated_file', negate=False):
'step_data' not in request.session[storage.prefix] or \
form_name not in request.session[storage.prefix]['step_data'] or\
form_name + '-' + file_key not in \
- request.session[storage.prefix]['step_data'][form_name]:
+ request.session[storage.prefix]['step_data'][form_name]:
return negate
try:
- file_id = request.session[storage.prefix]['step_data']\
- [form_name][form_name+'-'+file_key]
+ file_id = request.session[storage.prefix][
+ 'step_data'][form_name][form_name+'-'+file_key]
if type(file_id) in (list, tuple):
file_id = file_id[0]
file_id = int(file_id)