summaryrefslogtreecommitdiff
path: root/ishtar_common/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-08-19 15:12:43 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-08-19 15:12:43 +0200
commit2c2480a1410c3445572936a70159efda5cc854f4 (patch)
tree840ab617f2927fec8143f6005cfd2d498d1c738f /ishtar_common/forms.py
parent032ac535ce0de17e7b92d9ba7207d49d8f3e21c6 (diff)
downloadIshtar-2c2480a1410c3445572936a70159efda5cc854f4.tar.bz2
Ishtar-2c2480a1410c3445572936a70159efda5cc854f4.zip
Archaeological files: change planning service management
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r--ishtar_common/forms.py63
1 files changed, 35 insertions, 28 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index e6f21ae5b..a5abdddcd 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -22,27 +22,18 @@ Forms definition
"""
import datetime
import re
-from itertools import groupby
from django import forms
-from django.conf import settings
-from django.contrib.auth.models import User
-from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.core import validators
-from django.core.exceptions import ObjectDoesNotExist
-from django.core.mail import send_mail
-from django.db.models import Max
-from django.forms.formsets import formset_factory, BaseFormSet, \
- DELETION_FIELD_NAME
-from django.shortcuts import render_to_response
-from django.template import Context, RequestContext, loader
+from django.forms.formsets import BaseFormSet, DELETION_FIELD_NAME
from django.utils import formats
from django.utils.functional import lazy
from django.utils.translation import ugettext_lazy as _
# from formwizard.forms import NamedUrlSessionFormWizard
+
class NamedUrlSessionFormWizard(forms.Form):
def __init__(self, form_list, condition_list={}, url_name=''):
self.form_list = dict(form_list)
@@ -59,8 +50,11 @@ import widgets
reverse_lazy = lazy(reverse, unicode)
regexp_name = re.compile(r"^[,:/\w\-'\"() \&\[\]@]+$", re.UNICODE)
-name_validator = validators.RegexValidator(regexp_name,
-_(u"Enter a valid name consisting of letters, spaces and hyphens."), 'invalid')
+name_validator = validators.RegexValidator(
+ regexp_name,
+ _(u"Enter a valid name consisting of letters, spaces and hyphens."),
+ 'invalid')
+
class FloatField(forms.FloatField):
"""
@@ -71,14 +65,17 @@ class FloatField(forms.FloatField):
value = value.replace(',', '.').replace('%', '')
return super(FloatField, self).clean(value)
+
class FinalForm(forms.Form):
final = True
form_label = _(u"Confirm")
+
class FinalDeleteForm(FinalForm):
confirm_msg = " "
confirm_end_msg = _(u"Are you sure you want to delete?")
+
class FormSet(BaseFormSet):
def check_duplicate(self, key_names, error_msg=""):
"""Check for duplicate items in the formset"""
@@ -91,7 +88,8 @@ class FormSet(BaseFormSet):
form = self.forms[i]
if not form.is_valid():
continue
- item = [key_name in form.cleaned_data and form.cleaned_data[key_name]
+ item = [key_name in form.cleaned_data and
+ form.cleaned_data[key_name]
for key_name in key_names]
if not [v for v in item if v]:
continue
@@ -104,6 +102,7 @@ class FormSet(BaseFormSet):
form.fields[DELETION_FIELD_NAME].label = ''
form.fields[DELETION_FIELD_NAME].widget = widgets.DeleteWidget()
+
class TableSelect(forms.Form):
def __init__(self, *args, **kwargs):
super(TableSelect, self).__init__(*args, **kwargs)
@@ -113,19 +112,23 @@ class TableSelect(forms.Form):
def get_input_ids(self):
return self.fields.keys()
+
def get_now():
format = formats.get_format('DATE_INPUT_FORMATS')[0]
value = datetime.datetime.now().strftime(format)
return value
+
class ClosingDateFormSelection(forms.Form):
form_label = _("Closing date")
end_date = forms.DateField(label=_(u"Closing date"),
widget=widgets.JQueryDate)
-def get_form_selection(class_name, label, key, model, base_form, get_url,
- not_selected_error=_(u"You should select an item."), new=False,
- new_message=_(u"Add a new item")):
+
+def get_form_selection(
+ class_name, label, key, model, base_form, get_url,
+ not_selected_error=_(u"You should select an item."), new=False,
+ new_message=_(u"Add a new item")):
"""
Generate a class selection form
class_name -- name of the class
@@ -137,15 +140,17 @@ def get_form_selection(class_name, label, key, model, base_form, get_url,
new -- can add new items
new_message -- message of link to add new items
"""
- attrs = {'_main_key':key,
- '_not_selected_error':not_selected_error,
- 'form_label':label,
- 'associated_models':{key:model},
- 'currents':{key:model},}
- attrs[key] = forms.IntegerField(label="", required=False,
+ attrs = {'_main_key': key,
+ '_not_selected_error': not_selected_error,
+ 'form_label': label,
+ 'associated_models': {key: model},
+ 'currents': {key: model}}
+ attrs[key] = forms.IntegerField(
+ label="", required=False,
validators=[models.valid_id(model)],
widget=widgets.JQueryJqGrid(reverse_lazy(get_url), base_form, model,
new=new, new_message=new_message))
+
def clean(self):
cleaned_data = self.cleaned_data
if self._main_key not in cleaned_data \
@@ -155,19 +160,21 @@ def get_form_selection(class_name, label, key, model, base_form, get_url,
attrs['clean'] = clean
return type(class_name, (forms.Form,), attrs)
+
class DocumentGenerationForm(forms.Form):
"""
Form to generate document by choosing the template
"""
- _associated_model = None # ex: AdministrativeAct
- _associated_object_name = '' # ex: 'archaeological_operations.models.AdministrativeAct'
+ _associated_model = None # ex: AdministrativeAct
+ # ex: 'archaeological_operations.models.AdministrativeAct'
+ _associated_object_name = ''
document_template = forms.ChoiceField(label=_("Template"), choices=[])
def __init__(self, *args, **kwargs):
super(DocumentGenerationForm, self).__init__(*args, **kwargs)
self.fields['document_template'].choices = \
- models.DocumentTemplate.get_tuples(
- dct={'associated_object_name':self._associated_object_name})
+ models.DocumentTemplate.get_tuples(
+ dct={'associated_object_name': self._associated_object_name})
def save(self, object_pk):
try:
@@ -176,7 +183,7 @@ class DocumentGenerationForm(forms.Form):
return
try:
template = models.DocumentTemplate.objects.get(
- pk=self.cleaned_data.get('document_template'))
+ pk=self.cleaned_data.get('document_template'))
except models.DocumentTemplate.DoesNotExist:
return
return template.publish(c_object)