diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-01-18 05:36:31 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-01-18 05:36:31 +0100 |
commit | 3ae6feef8730ee29010ae53a6879c4b88313ae51 (patch) | |
tree | 137b02b567e515825c358a9677f2679072b321fd /ishtar/furnitures/forms.py | |
parent | d0dee00918622fde2bdcaf32109b0a1e51410715 (diff) | |
download | Ishtar-3ae6feef8730ee29010ae53a6879c4b88313ae51.tar.bz2 Ishtar-3ae6feef8730ee29010ae53a6879c4b88313ae51.zip |
Close operations (refs #16)
Diffstat (limited to 'ishtar/furnitures/forms.py')
-rw-r--r-- | ishtar/furnitures/forms.py | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index cb94e2889..caab07e8c 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -102,7 +102,12 @@ class Wizard(NamedUrlSessionFormWizard): files=storage.get_step_files(form_key)) form_obj.is_valid() final_form_list.append(form_obj) + last_form = final_form_list[-1] context.update({'datas':self.get_formated_datas(final_form_list)}) + if hasattr(last_form, 'confirm_msg'): + context.update({'confirm_msg':last_form.confirm_msg}) + if hasattr(last_form, 'confirm_end_msg'): + context.update({'confirm_end_msg':last_form.confirm_end_msg}) return context def get_formated_datas(self, forms): @@ -911,8 +916,6 @@ class OperationFormGeneral(forms.Form): choices=models.OperationType.get_types()) start_date = forms.DateField(label=_(u"Start date"), required=False, widget=widgets.JQueryDate) - end_date = forms.DateField(label=_(u"End date"), required=False, - widget=widgets.JQueryDate) year = forms.IntegerField(label=_("Year"), initial=lambda:datetime.datetime.now().year, validators=[validators.MinValueValidator(1900), @@ -1015,3 +1018,54 @@ operation_modification_wizard = OperationWizard([ ('remains-operation_modification', RemainFormSet), ('final-operation_modification', FinalForm)], url_name='operation_modification',) + +class OperationDateFormSelection(forms.Form): + form_label = _("Closing date") + end_date = forms.DateField(label=_(u"Closing date"), + widget=widgets.JQueryDate) + +class OperationClosingWizard(Wizard): + model = models.Operation + fields = ['year', 'operation_code', 'operation_type', 'associated_file', + 'in_charge', 'start_date', 'end_date', 'comment', 'towns', 'remains'] + + def get_formated_datas(self, forms): + datas = super(OperationClosingWizard, self).get_formated_datas(forms) + current_obj = None + for form in forms: + if not hasattr(form, "cleaned_data"): + continue + for key in form.cleaned_data: + if key == 'pk': + model = form.associated_models['pk'] + current_obj = model.objects.get(pk=form.cleaned_data['pk']) + if not current_obj: + return datas + res = {} + for field in self.model._meta.fields + self.model._meta.many_to_many: + if field.name not in self.fields: + continue + value = getattr(current_obj, field.name) + if not value: + continue + if hasattr(value, 'all'): + value = ", ".join([unicode(item) for item in value.all()]) + if not value: + continue + else: + value = unicode(value) + res[field.name] = (field.verbose_name, value, '') + for field in self.fields: + if field in res: + datas[0][1].append(res[field]) + return datas + +class FinalOperationClosingForm(FinalForm): + confirm_msg = " " + confirm_end_msg = _(u"Would you like to close this operation?") + +operation_closing_wizard = OperationClosingWizard([ + ('selec-operation_closing', OperationFormSelection), + ('date-operation_closing', OperationDateFormSelection), + ('final-operation_closing', FinalOperationClosingForm)], + url_name='operation_closing',) |