diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-11-30 13:20:53 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-11-30 13:20:53 +0100 |
commit | 8b666443667f92e014d70a4247c7885375bba610 (patch) | |
tree | 7e216f7c036ae568407d46359dea361f2a641098 /ishtar_common | |
parent | 62cac0ec03a96d5f358148cf6dff2a21ccf20854 (diff) | |
download | Ishtar-8b666443667f92e014d70a4247c7885375bba610.tar.bz2 Ishtar-8b666443667f92e014d70a4247c7885375bba610.zip |
Simple treatment form. Treatment listing. (refs #3365)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/tests.py | 31 | ||||
-rw-r--r-- | ishtar_common/views.py | 2 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 2 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 9 |
4 files changed, 42 insertions, 2 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 0c4bbda08..dbe3df4a5 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -75,6 +75,32 @@ def create_user(): return username, password, user +class WizardTestFormData(object): + """ + Test set to simulate wizard steps + """ + def __init__(self, name, form_datas, ignored=[], extra_tests=[]): + """ + :param name: explicit name of the test + :param form_datas: dict with data for each step - dict key are wizard + step name + :param ignored: steps to be ignored in wizard processing + :param extra_tests: list of extra tests. Theses tests must be functions + accepting two parameters: the current test object and the final step + response + """ + self.form_datas = form_datas + self.ignored = ignored[:] + self.extra_tests = extra_tests + + def tests(self, test_object, final_step_response): + """ + Specific tests for theses datas. Raise Exception if not OK. + """ + for test in self.extra_tests: + test(test_object, final_step_response) + + class WizardTest(object): url_name = None wizard_name = '' @@ -95,7 +121,9 @@ class WizardTest(object): def test_wizard(self): url = reverse(self.url_name) self.pre_wizard() - for form_data, ignored in self.form_datas: + for test_form_data in self.form_datas: + form_data = test_form_data.form_datas + ignored = test_form_data.ignored for idx, step in enumerate(self.steps): current_step, current_form = step if current_step in ignored: @@ -138,6 +166,7 @@ class WizardTest(object): '/{}/{}'.format(self.url_name, next_form)) else: response = self.client.post(url, data, follow=True) + test_form_data.tests(self, response) self.post_wizard() diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 8634125cd..cb6afe8c4 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -910,6 +910,8 @@ def get_item(model, func_name, default_name, extra_request_keys=[], keys = [keys] my_vals = [] for k in keys: + if k in model.EXTRA_REQUEST_KEYS: + k = model.EXTRA_REQUEST_KEYS[k] vals = [item] # foreign key may be divided by "." or "__" splitted_k = [] diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 1183836bc..be22bd3cb 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -581,6 +581,8 @@ class JQueryJqGrid(forms.RadioSelect): field_name += "__" field_name += f_name field_verbose_names.append(unicode(field_verbose_name)) + if not field_name: + field_name = "__".join(col_names) if field_name in col_labels: jq_col_names.append(unicode(col_labels[field_name])) elif col_names and col_names[0] in col_labels: diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index c065459f6..b9fba83b4 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -126,6 +126,8 @@ class Wizard(NamedUrlWizardView): current_obj_slug = '' file_storage = default_storage + saved_args = {} # argument to pass on object save + ''' # buggy and unecessary... def __init__(self, *args, **kwargs): @@ -543,12 +545,16 @@ class Wizard(NamedUrlWizardView): dct[dependant_item] = c_item if 'pk' in dct: dct.pop('pk') + saved_args = self.saved_args.copy() + for k in saved_args: + if k in dct: + saved_args[k] = dct.pop(k) obj = self.get_saved_model()(**dct) try: obj.full_clean() except ValidationError: return self.render(form_list[-1]) - obj.save() + obj.save(**saved_args) for k in adds: getattr(obj, k).add(adds[k]) # necessary to manage interaction between models like @@ -626,6 +632,7 @@ class Wizard(NamedUrlWizardView): self.request.session[self.current_obj_slug] = unicode(obj.pk) self.request.session[self.get_object_name(obj)] = unicode(obj.pk) dct = {'item': obj} + self.current_object = obj # force evaluation of lazy urls wizard_done_window = unicode(self.wizard_done_window) if wizard_done_window: |