def before(self, form): BaseFormView.before(self, form) self.request.actionmenu.add( ViewLink( label=u"Revenir à la facture", path="/invoices/{id}.html", id=self.context.id, _anchor="payment", ) ) appstruct = [] for tva_value, value in self.context.topay_by_tvas().items(): tva = Tva.by_value(tva_value) appstruct.append( { 'tva_id': tva.id, 'amount': floor_to_precision( value, precision=2, dialect_precision=5 ) } ) if len(appstruct) == 1: form.set_appstruct(appstruct[0]) else: form.set_appstruct({'tvas': appstruct})
def test_more_vars_called(get_csrf_request_with_db): req = get_csrf_request_with_db() form = BaseFormView(req) form.schema = DummySchema() form.add_template_vars = ('arg',) form.arg = u"Test arg" result = form.__call__() assert(result['arg'] == u"Test arg")
def submit_failure(self, e): errors = e.error.asdict() if 'month' in errors and 'year' in errors: appstruct = self.request.POST sheet = self._find_existing(appstruct) if sheet is not None: return self.redirect(sheet) BaseFormView.submit_failure(self, e)
def __init__(self, context, request): BaseFormView.__init__(self, request) self.model_type = self.request.GET['model_type'] self.quotechar = self.request.GET['quotechar'] self.delimiter = self.request.GET['delimiter'] if self.model_type not in self.model_types: raise HTTPForbidden() # We first count the number of elements in the file self.filepath = get_current_csv_filepath(self.request) # We build a field - model attr associator self.associator = get_csv_import_associator(self.model_type) _csv_obj = get_current_csv(self.filepath, self.delimiter, self.quotechar) self.headers = [header for header in _csv_obj.fieldnames if header]
def submit_failure(self, e): errors = e.error.asdict() if 'month' in errors and 'year' in errors: appstruct = self.request.POST sheet = self._find_existing(appstruct) if sheet is not None: sheet = self.context self.request.session.flash( u"Impossible de dupliquer cette note de dépenses." u"Une note de dépense existe déjà pour la période " u"de {0} {1}.".format( strings.month_name(appstruct['month']), appstruct['year'], ), 'error') return self.redirect(self.context) BaseFormView.submit_failure(self, e)
def submit_failure(self, e): errors = e.error.asdict() if 'month' in errors and 'year' in errors: appstruct = self.request.POST sheet = self._find_existing(appstruct) if sheet is not None: sheet = self.context self.request.session.flash( u"Impossible de dupliquer cette note de dépenses." u"Une note de dépense existe déjà pour la période " u"de {0} {1}.".format( strings.month_name(appstruct['month']), appstruct['year'], ), 'error' ) return self.redirect(self.context) BaseFormView.submit_failure(self, e)
def _more_template_vars(self): """ Add template vars to the response dict List the attributes configured in the add_template_vars attribute and add them """ result = BaseFormView._more_template_vars(self) result['title'] = self.title result['company'] = self.company result['tvas'] = self.tvas result['load_options_url'] = self.load_options_url result['load_catalog_url'] = self.load_catalog_url return result
def test_more_vars_called(get_csrf_request_with_db): req = get_csrf_request_with_db() form = BaseFormView(req) form.schema = DummySchema() form.add_template_vars = ('arg', ) form.arg = u"Test arg" result = form.__call__() assert (result['arg'] == u"Test arg")
def before(self, form): BaseFormView.before(self, form) self.request.actionmenu.add( ViewLink( label=u"Revenir à la facture", path="/invoices/{id}.html", id=self.context.id, _anchor="payment", )) appstruct = [] for tva_value, value in self.context.topay_by_tvas().items(): tva = Tva.by_value(tva_value) appstruct.append({ 'tva_id': tva.id, 'amount': floor_to_precision(value, precision=2, dialect_precision=5) }) if len(appstruct) == 1: form.set_appstruct(appstruct[0]) else: form.set_appstruct({'tvas': appstruct})
def __init__(self, *args, **kwargs): BaseFormView.__init__(self, *args, **kwargs) ensure_doctypes_rel(self.current_userdatas.id, self.request)
def __init__(self, *args, **kwargs): BaseFormView.__init__(self, *args, **kwargs) self.form_config = UserFormConfigState(self.session)
def test_init(get_csrf_request_with_db): req = get_csrf_request_with_db() form = BaseFormView(req) assert (form.dbsession == req.dbsession) assert (form.session == req.session)
def before(self, form): BaseFormView.before(self, form) populate_actionmenu(self.request) task_add_js.need()
def before(self, form): BaseFormView.before(self, form) task_add_js.need()