summaryrefslogtreecommitdiff
path: root/ishtar_common/wizards.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/wizards.py')
-rw-r--r--ishtar_common/wizards.py80
1 files changed, 46 insertions, 34 deletions
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 49abe606f..1ac28d640 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-2016 É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
@@ -90,6 +90,25 @@ def check_rights_condition(rights):
return False
return func
+# buggy and unecessary at least for the moment...
+"""
+def _check_right(step, condition=True):
+ '''Return a method to check the right for a specific step'''
+ def check_right(self):
+ cond = condition
+ if callable(condition):
+ cond = condition(self)
+ if not cond:
+ return False
+ return True
+ # TODO: to be check
+ if not hasattr(self.request.user, 'ishtaruser'):
+ return False
+ return self.request.user.ishtaruser.has_right(
+ ('administrator', step), session=self.request.session)
+ return check_right
+"""
+
class Wizard(NamedUrlWizardView):
model = None
@@ -105,32 +124,16 @@ class Wizard(NamedUrlWizardView):
filter_owns = {}
current_obj_slug = ''
- @staticmethod
- def _check_right(step, condition=True):
- '''Return a method to check the right for a specific step'''
- def check_right(self):
- cond = condition
- if callable(condition):
- cond = condition(self)
- if not cond:
- return False
- return True
- # TODO: to be check
- if not hasattr(self.request.user, 'ishtaruser'):
- return False
- return self.request.user.ishtaruser.has_right(
- ('administrator', step), session=self.request.session)
- return check_right
-
+ '''
+ # buggy and unecessary...
def __init__(self, *args, **kwargs):
"""Check right for each step of the wizard"""
super(Wizard, self).__init__(*args, **kwargs)
for form_key in self.form_list.keys()[:-1]:
- condition = True
- if form_key in self.condition_dict:
- condition = self.condition_dict.get(form_key, True)
- cond = self._check_right(form_key, condition)
+ condition = self.condition_dict.get(form_key, True)
+ cond = _check_right(form_key, condition)
self.condition_dict[form_key] = cond
+ '''
def dispatch(self, request, *args, **kwargs):
self.current_right = kwargs.get('current_right', None)
@@ -659,19 +662,23 @@ class Wizard(NamedUrlWizardView):
frm = form.form
if callable(frm):
frm = frm()
- required_fields = [ki for ki in frm.fields
- if frm.fields[ki].required]
- base_key = None
- if required_fields:
- base_key = required_fields[-1]
- elif frm.fields.keys():
- base_key = frm.fields.keys()[-1]
- init = self.get_form_initial(step, data=data)
+
total_field = 0
- if base_key:
- total_field = len([key for key in data.keys()
- if base_key in key.split('-')
- and data[key]])
+ if hasattr(frm, 'count_valid_fields'):
+ total_field = frm.count_valid_fields(data)
+ else:
+ required_fields = [ki for ki in frm.fields
+ if frm.fields[ki].required]
+ base_key = None
+ if required_fields:
+ base_key = required_fields[-1]
+ elif frm.fields.keys():
+ base_key = frm.fields.keys()[-1]
+ if base_key:
+ total_field = len([key for key in data.keys()
+ if base_key in key.split('-')
+ and data[key]])
+ init = self.get_form_initial(step, data=data)
if init and not to_delete and (
not hasattr(self, 'form_initialized') or
not self.form_initialized):
@@ -1129,6 +1136,11 @@ class PersonDeletionWizard(DeletionWizard):
'final-person_deletion': 'ishtar/wizard/wizard_person_deletion.html'}
+class IshtarUserDeletionWizard(DeletionWizard):
+ model = models.IshtarUser
+ fields = model.TABLE_COLS
+
+
class OrganizationWizard(Wizard):
model = models.Organization