def submit_success(self, appstruct): model = Phase() model.project_id = self.context.id merge_session_with_post(model, appstruct) self.dbsession.add(model) redirect = self.request.route_path("project", id=model.project_id) return HTTPFound(redirect)
def submit_success(self, appstruct): """ Handle submission of the expense page, only on state change validation """ log.debug("Submitting expense sheet status form") # Comment is now stored in a specific table comment = None if appstruct.has_key("comment"): comment = appstruct.pop('comment') # here we merge all our parameters with the current expensesheet merge_session_with_post(self.request.context, appstruct) # We modifiy the expense status try: expense, status = self.set_expense_status(self.request.context) self._store_communication(comment) self.request.registry.notify(StatusChanged( self.request, expense, status, comment, )) except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): """ handle successfull submission of the form """ payment_obj = self.context # update the payment merge_session_with_post(payment_obj, appstruct) self.dbsession.merge(payment_obj) # Check the invoice status force_resulted = appstruct.pop('resulted', False) parent = payment_obj.parent parent = parent.check_resulted( force_resulted=force_resulted, user_id=self.request.user.id ) self.dbsession.merge(parent) come_from = appstruct.pop('come_from', None) if come_from is not None: redirect = come_from else: redirect = self.get_default_redirect() return HTTPFound(redirect)
def submit_success(self, appstruct): """ Handle successfull expense configuration :param appstruct: submitted datas """ all_ids = self.get_all_ids(appstruct) # We delete the elements that are no longer in the appstruct for (factory, polytype) in self.factories.values(): for element in factory.query().filter(factory.type == polytype): if element.id not in all_ids: element.active = False self.dbsession.merge(element) self.dbsession.flush() for key in ('code_journal', 'compte_cg'): cfg_key = self._get_config_key(key) self._set_config_value(appstruct, cfg_key, key) for key, (factory, polytype) in self.factories.items(): for data in appstruct[key]: if data.get('id') is not None: type_ = factory.get(data['id']) merge_session_with_post(type_, data) self.dbsession.merge(type_) else: type_ = factory() merge_session_with_post(type_, data) self.dbsession.add(type_) self.request.session.flash(self.validation_msg) return HTTPFound(self.request.route_path("admin_expense"))
def test_merge_session_with_post(): session = Mock() post = dict(id=12, name="Dupont", lastname="Jean", accounts=['admin', 'user']) merge_session_with_post(session, post) assert session.name == 'Dupont' assert "admin" in session.accounts
def submit_success(self, appstruct): """ Handle submission of the expense page, only on state change validation """ logger.debug("# Submitting expense sheet status form #") logger.debug(appstruct) # Comment is now stored in a specific table comment = None if "comment" in appstruct: comment = appstruct.pop("comment") # here we merge all our parameters with the current expensesheet merge_session_with_post(self.request.context, appstruct) # We modifiy the expense status try: logger.exception(u"Trying !!!") expense, status = self.set_expense_status(self.request.context) self._store_communication(comment) self.request.registry.notify(ExpenseStatusChanged(self.request, expense, status, comment)) except Forbidden, err: logger.exception(u"An access has been forbidden") self.request.session.flash(err.message, queue="error")
def submit_success(self, appstruct): """ Handle successfull submission of our edition form """ come_from = appstruct.pop('come_from') appstruct['timeslots'] = self._get_timeslots(appstruct) appstruct['datetime'] = appstruct['timeslots'][0].start_time participants_ids = set(appstruct.pop('participants', [])) appstruct['participants'] = [ user.User.get(id_) for id_ in participants_ids ] for timeslot in appstruct['timeslots']: timeslot.participants = appstruct['participants'] merge_session_with_post(self.context, appstruct) self.dbsession.merge(self.context) workshop_url = self.request.route_path( "workshop", id=self.context.id, _query=dict(action="edit") ) if not come_from: redirect = workshop_url else: msg = WORKSHOP_SUCCESS_MSG.format(workshop_url) self.session.flash(msg) redirect = come_from return HTTPFound(redirect)
def submit_success(self, appstruct): merge_session_with_post(self.context, appstruct) self.dbsession.merge(self.context) redirect = self.request.route_path( "project", id=self.context.project_id, ) return HTTPFound(redirect)
def persist_to_database(self, appstruct): """ Execute actions on the database """ # Inserting in the database file_object = self.factory() forms.merge_session_with_post(file_object, appstruct) self.request.dbsession.add(file_object) self.request.session.flash(self.valid_msg)
def submit_success(self, appstruct): model = Phase() model.project_id = self.context.id merge_session_with_post(model, appstruct) self.dbsession.add(model) self.dbsession.flush() redirect = self.request.route_path("project", id=model.project_id, _query={'phase': model.id}) return HTTPFound(redirect)
def new_activity(request, appstruct): """ Add a new activity in the database """ activity = Activity(status="planned") appstruct = handle_rel_in_appstruct(appstruct) merge_session_with_post(activity, appstruct) request.dbsession.add(activity) request.dbsession.flush() return activity
def _add_or_edit(self, datas, factory): """ Add or edit an element of the given factory """ if 'id' in datas: element = factory.get(datas['id']) merge_session_with_post(element, datas) element = self.dbsession.merge(element) else: element = factory() merge_session_with_post(element, datas) self.dbsession.add(element) return element
def persist_to_database(self, appstruct): """ Execute actions on the database """ # Inserting in the database file_object = self.factory() file_object.name = appstruct['name'] file_object.parent_id = self._parent().id forms.merge_session_with_post(file_object, appstruct) self.request.dbsession.add(file_object) self.request.dbsession.flush() self._update_file_requirements(file_object)
def submit_success(self, appstruct): """ fired on submit success, set Tvas """ # First we disable the elements that are no longer part of the # configuration self.disable_elements(Product, self.get_remaining_prod_ids(appstruct)) self.disable_elements(Tva, self.get_remaining_tva_ids(appstruct)) self.dbsession.flush() for data in appstruct['tvas']: products = data.pop('products') if 'id' in data: tva = Tva.get(data['id']) merge_session_with_post(tva, data) tva = self.dbsession.merge(tva) else: tva = Tva() merge_session_with_post(tva, data) self.dbsession.add(tva) for prod in products: if 'id' in prod: product = Product.get(prod['id']) product.tva = tva merge_session_with_post(product, prod) self.dbsession.merge(product) else: product = Product() merge_session_with_post(product, prod) product.tva = tva self.dbsession.add(product) self.request.session.flash(self.validation_msg) return HTTPFound(self.request.route_path("admin_tva"))
def persist_to_database(self, appstruct): """ Execute actions on the database """ # Inserting in the database file_object = self.factory() file_object.name = appstruct['name'] parent = self._parent() if hasattr(parent, "id"): file_object.parent_id = parent.id forms.merge_session_with_post(file_object, appstruct) self.request.dbsession.add(file_object) self.request.dbsession.flush() self.request.registry.notify(FileAdded(self.request, file_object))
def submit_success(self, appstruct): log.debug("Submitting cancelinvoice add") appstruct = get_cancel_invoice_dbdatas(appstruct) # Since the call to get_next_cancelinvoice_number commits the current # transaction, it needs to be called before creating our cancelinvoice, to # avoid missing arguments errors snumber = self.context.get_next_cancelinvoice_number() cinvoice = CancelInvoice() cinvoice.project = self.context cinvoice.owner = self.request.user cinvoice = merge_session_with_post(cinvoice, appstruct["cancelinvoice"]) cinvoice.set_sequence_number(snumber) cinvoice.set_number() cinvoice.set_name() try: cinvoice = self.set_task_status(cinvoice) cinvoice.invoice.check_resulted(user_id=self.request.user.id) self.dbsession.merge(cinvoice.invoice) # Line handling cinvoice = add_lines_to_cancelinvoice(cinvoice, appstruct) self.dbsession.add(cinvoice) self.dbsession.flush() self.session.flash(u"L'avoir a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): log.debug("Submitting invoice add") appstruct = get_invoice_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) invoice = Invoice( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) invoice = merge_session_with_post( invoice, appstruct["task"] ) try: invoice = self.set_task_status(invoice) # Line handling invoice = add_lines_to_invoice(invoice, appstruct) self.dbsession.add(invoice) self.dbsession.flush() self.session.flash(u"La facture a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def record_changes(request, appstruct, message, gotolist=False, query_options=None): """ Record changes on the current activity, changes could be : edition record :param obj request: The pyramid request (context should be an activity) :param dict appstruct: The submitted datas :param str message: The string to display on user message :param bool gotolist: Should we redirect the user to the list view :param dict query_options: In case of single activity page redirect, add those options to the url """ activity = merge_session_with_post(request.context, appstruct) request.dbsession.merge(activity) if message: request.session.flash(message) if gotolist: url = request.route_path('activities', ) else: url = request.route_path( "activity", id=request.context.id, _query=query_options, ) return HTTPFound(url)
def submit_success(self, appstruct): log.debug("Submitting invoice add") appstruct = get_invoice_dbdatas(appstruct) # Since the call to get_next_invoice_number commits the current # transaction, it needs to be called before creating our invoice, to # avoid missing arguments errors snumber = self.context.get_next_invoice_number() invoice = Invoice() invoice.project = self.context invoice.owner = self.request.user invoice = merge_session_with_post(invoice, appstruct["invoice"]) invoice.set_sequence_number(snumber) invoice.set_number() invoice.set_name() try: invoice = self.set_task_status(invoice) # Line handling invoice = add_lines_to_invoice(invoice, appstruct) self.dbsession.add(invoice) self.dbsession.flush() self.session.flash(u"La facture a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): log.debug("Submitting estimation add") appstruct = get_estimation_dbdatas(appstruct) # Next estimation number for current project snumber = self.context.get_next_estimation_number() estimation = Estimation() estimation.project = self.context estimation.owner = self.request.user estimation = merge_session_with_post( estimation, appstruct['task'] ) estimation.set_sequence_number(snumber) estimation.set_number() estimation.set_name() try: estimation = self.set_task_status(estimation) # Line handling estimation = add_lines_to_estimation(estimation, appstruct) self.dbsession.add(estimation) self.dbsession.flush() self.session.flash(u"Le devis a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): log.debug("Submitting invoice add") appstruct = get_invoice_dbdatas(appstruct) # Since the call to get_next_invoice_number commits the current # transaction, it needs to be called before creating our invoice, to # avoid missing arguments errors snumber = self.context.get_next_invoice_number() invoice = Invoice() invoice.project = self.context invoice.owner = self.request.user invoice = merge_session_with_post( invoice, appstruct["task"] ) invoice.set_sequence_number(snumber) invoice.set_number() invoice.set_name() try: invoice = self.set_task_status(invoice) # Line handling invoice = add_lines_to_invoice(invoice, appstruct) self.dbsession.add(invoice) self.dbsession.flush() self.session.flash(u"La facture a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def record_changes(request, appstruct, message, gotolist=False, query_options=None): """ Record changes on the current activity, changes could be : edition record :param obj request: The pyramid request (context should be an activity) :param dict appstruct: The submitted datas :param str message: The string to display on user message :param bool gotolist: Should we redirect the user to the list view :param dict query_options: In case of single activity page redirect, add those options to the url """ activity = merge_session_with_post(request.context, appstruct) request.dbsession.merge(activity) if message: request.session.flash(message) if gotolist: url = request.route_path( 'activities', ) else: url = request.route_path( "activity", id=request.context.id, _query=query_options, ) return HTTPFound(url)
def submit_success(self, appstruct): log.debug("Submitting estimation add") appstruct = get_estimation_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) estimation = Estimation( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) estimation = merge_session_with_post( estimation, appstruct['task'] ) try: # Line handling estimation = add_lines_to_estimation(estimation, appstruct) self.dbsession.add(estimation) self.dbsession.flush() estimation = self.set_task_status(estimation) self.session.flash(u"Le devis a bien été ajouté.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): log.debug("Submitting cancelinvoice add") appstruct = get_cancel_invoice_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) cinvoice = CancelInvoice( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) cinvoice = merge_session_with_post(cinvoice, appstruct["task"]) try: cinvoice = self.set_task_status(cinvoice) cinvoice.invoice.check_resulted(user_id=self.request.user.id) self.dbsession.merge(cinvoice.invoice) # Line handling cinvoice = add_lines_to_cancelinvoice(cinvoice, appstruct) self.dbsession.add(cinvoice) self.dbsession.flush() self.session.flash(u"L'avoir a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): log.debug("Submitting cancelinvoice add") appstruct = get_cancel_invoice_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) cinvoice = CancelInvoice( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) cinvoice = merge_session_with_post( cinvoice, appstruct["task"] ) try: cinvoice = self.set_task_status(cinvoice) cinvoice.invoice.check_resulted(user_id=self.request.user.id) self.dbsession.merge(cinvoice.invoice) # Line handling cinvoice = add_lines_to_cancelinvoice(cinvoice, appstruct) self.dbsession.add(cinvoice) self.dbsession.flush() self.session.flash(u"L'avoir a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def _get_timeslots(self, appstruct): datas = appstruct.pop('timeslots') objects = [] datas.sort(key=lambda val: val['start_time']) for data in datas: id_ = data.pop('id', None) if id_ is None: # New timeslots objects.append(models.Timeslot(**data)) else: # existing timeslots obj = self._retrieve_workshop_timeslot(id_) merge_session_with_post(obj, data) objects.append(obj) return objects
def submit_success(self, appstruct): """ Handle successfull submission of our edition form """ come_from = appstruct.pop('come_from') appstruct['timeslots'] = self._get_timeslots(appstruct) appstruct['datetime'] = appstruct['timeslots'][0].start_time participants_ids = set(appstruct.pop('participants', [])) appstruct['participants'] = [ user.User.get(id_) for id_ in participants_ids ] for timeslot in appstruct['timeslots']: timeslot.participants = appstruct['participants'] trainers_ids = set(appstruct.pop('trainers', [])) appstruct['trainers'] = [ user.User.get(id_) for id_ in trainers_ids ] try: appstruct['owner'] = user.User.get(appstruct['owner']) except KeyError: # case of read-only owner pass merge_session_with_post( self.context, appstruct, remove_empty_values=False, ) self.dbsession.merge(self.context) workshop_url = self.request.route_path( "workshop", id=self.context.id, _query=dict(action="edit") ) if not come_from: redirect = workshop_url else: msg = WORKSHOP_SUCCESS_MSG.format(workshop_url) self.session.flash(msg) redirect = come_from return HTTPFound(redirect)
def submit_success(self, appstruct): """ Create a new workshop """ come_from = appstruct.pop('come_from') timeslots_datas = appstruct.pop('timeslots') for i in timeslots_datas: i.pop('id', None) timeslots_datas.sort(key=lambda val: val['start_time']) appstruct['datetime'] = timeslots_datas[0]['start_time'] appstruct['timeslots'] = [ models.Timeslot(**data) for data in timeslots_datas ] participants_ids = set(appstruct.pop('participants', [])) appstruct['participants'] = [ user.User.get(id_) for id_ in participants_ids ] for timeslot in appstruct['timeslots']: timeslot.participants = appstruct['participants'] trainers_ids = set(appstruct.pop('trainers', [])) appstruct['trainers'] = [user.User.get(id_) for id_ in trainers_ids] # Current user by default if (self.request.has_permission('edit_owner.event') and appstruct.get('owner')): appstruct['owner'] = user.User.get(appstruct['owner']) else: appstruct['owner'] = user.User.get(self.request.user.id) workshop_obj = models.Workshop(**appstruct) workshop_obj = merge_session_with_post( workshop_obj, appstruct, remove_empty_values=False, ) self.dbsession.add(workshop_obj) self.dbsession.flush() workshop_url = self.request.route_path("workshop", id=workshop_obj.id, _query=dict(action="edit")) if not come_from: redirect = workshop_url else: msg = WORKSHOP_SUCCESS_MSG.format(workshop_url) self.session.flash(msg) redirect = come_from return HTTPFound(redirect)
def submit_success(self, appstruct): """ handle successfull submission of the form """ payment_obj = self.context # update the payment merge_session_with_post(payment_obj, appstruct) self.dbsession.merge(payment_obj) # Check the invoice status force_resulted = appstruct.pop('resulted', False) parent = payment_obj.parent parent = parent.check_resulted(force_resulted=force_resulted, user_id=self.request.user.id) self.dbsession.merge(parent) come_from = appstruct.pop('come_from', None) if come_from is not None: redirect = come_from else: redirect = self.get_default_redirect() return HTTPFound(redirect)
def submit_success(self, appstruct): """ Edit the database entry and return redirect """ self.request.context.activities = fetch_activities_objects(appstruct) company = merge_session_with_post(self.request.context, appstruct) company = self.dbsession.merge(company) self.dbsession.flush() message = u"Votre entreprise a bien été modifiée" self.session.flash(message) # Clear all informations stored in session by the tempstore used for the # file upload widget self.request.session.pop("substanced.tempstore") self.request.session.changed() return HTTPFound(self.request.route_path("company", id=company.id))
def submit_success(self, appstruct): """ Edit the database entry and return redirect """ self.request.context.activities = fetch_activities_objects(appstruct) company = merge_session_with_post(self.request.context, appstruct) company = self.dbsession.merge(company) self.dbsession.flush() message = u"Votre entreprise a bien été modifiée" self.session.flash(message) # Clear all informations stored in session by the tempstore used for the # file upload widget self.request.session.pop('substanced.tempstore') self.request.session.changed() return HTTPFound(self.request.route_path("company", id=company.id))
def submit_success(self, appstruct): """ Edit the database entry and return redirect """ user_id = appstruct.get("user_id") company = Company() company.activities = fetch_activities_objects(appstruct) company = merge_session_with_post(company, appstruct) if user_id is not None: user_account = User.get(user_id) if user_account is not None: company.employees.append(user_account) self.dbsession.add(company) self.dbsession.flush() message = u"L'entreprise '{0}' a bien été ajoutée".format(company.name) self.session.flash(message) return HTTPFound(self.request.route_path("company", id=company.id))
def submit_success(self, appstruct): """ Edit the database entry and return redirect """ user_id = appstruct.get('user_id') company = Company() company.activities = fetch_activities_objects(appstruct) company = merge_session_with_post(company, appstruct) if user_id is not None: user_account = User.get(user_id) if user_account is not None: company.employees.append(user_account) self.dbsession.add(company) self.dbsession.flush() message = u"L'entreprise '{0}' a bien été ajoutée".format(company.name) self.session.flash(message) return HTTPFound(self.request.route_path("company", id=company.id))
def submit_success(self, appstruct): log.debug("Submitting estimation edit") appstruct = get_estimation_dbdatas(appstruct) # Since the call to get_next_estimation_number commits the current # transaction, it needs to be called before creating our estimation, to # avoid missing arguments errors estimation = self.context estimation = merge_session_with_post(estimation, appstruct["estimation"]) try: estimation = self.set_task_status(estimation) # Line handling estimation = add_lines_to_estimation(estimation, appstruct) estimation = self.dbsession.merge(estimation) self.dbsession.flush() self.session.flash(u"Le devis a bien été modifié.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): """ Add/Edit a turnover projection in the database """ appstruct['year'] = self.year appstruct['company_id'] = self.request.context.id query = self.turnover_projections() query = query.filter(TurnoverProjection.month == appstruct['month']) result = query.first() projection = result or TurnoverProjection() projection = merge_session_with_post(projection, appstruct) if projection.id is not None: projection = self.request.dbsession.merge(projection) else: self.request.dbsession.add(projection) url = get_current_url(self.request) return HTTPFound(url)
def submit_success(self, appstruct): log.debug("Submitting estimation add") appstruct = get_estimation_dbdatas(appstruct) # Next estimation number for current project snumber = self.context.get_next_estimation_number() estimation = Estimation() estimation.project = self.context estimation.owner = self.request.user estimation = merge_session_with_post(estimation, appstruct["estimation"]) estimation.set_sequence_number(snumber) estimation.set_number() estimation.set_name() try: estimation = self.set_task_status(estimation) # Line handling estimation = add_lines_to_estimation(estimation, appstruct) self.dbsession.add(estimation) self.dbsession.flush() self.session.flash(u"Le devis a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def put(self): """ Rest put method : update a line """ logger.debug("In the put method") line = self.getOne() appstruct = self.request.json_body try: appstruct = self.schema.deserialize(appstruct) except colander.Invalid, err: traceback.print_exc() logger.exception(" - Erreur") logger.exception(appstruct) raise RestError(err.asdict(), 400) line = merge_session_with_post(line, appstruct) self.request.dbsession.merge(line) self.request.dbsession.flush() return self.model_wrapper(line) class RestExpenseKmLine(RestExpenseLine): """ Rest iface for Expense kilometric lines Lines are compound by : * km : number of kilometers * start : the start point * end : the end point * date : the date * description : the description of the displacement context """
def submit_success(self, appstruct): """ Create a new workshop """ come_from = appstruct.pop('come_from') timeslots_datas = appstruct.pop('timeslots') for i in timeslots_datas: i.pop('id', None) timeslots_datas.sort(key=lambda val: val['start_time']) appstruct['datetime'] = timeslots_datas[0]['start_time'] appstruct['timeslots'] = [ models.Timeslot(**data) for data in timeslots_datas ] participants_ids = set(appstruct.pop('participants', [])) appstruct['participants'] = [ user.User.get(id_) for id_ in participants_ids ] for timeslot in appstruct['timeslots']: timeslot.participants = appstruct['participants'] trainers_ids = set(appstruct.pop('trainers', [])) appstruct['trainers'] = [ user.User.get(id_) for id_ in trainers_ids ] # Current user by default if ( self.request.has_permission('edit_owner.event') and appstruct.get('owner') ): appstruct['owner'] = user.User.get(appstruct['owner']) else: appstruct['owner'] = user.User.get(self.request.user.id) workshop_obj = models.Workshop(**appstruct) workshop_obj = merge_session_with_post( workshop_obj, appstruct, remove_empty_values=False, ) self.dbsession.add(workshop_obj) self.dbsession.flush() workshop_url = self.request.route_path( "workshop", id=workshop_obj.id, _query=dict(action="edit") ) if not come_from: redirect = workshop_url else: msg = WORKSHOP_SUCCESS_MSG.format(workshop_url) self.session.flash(msg) redirect = come_from return HTTPFound(redirect)
def persist_to_database(self, appstruct): forms.merge_session_with_post(self.context, appstruct) self.request.dbsession.merge(self.context) self._update_file_requirements(self.context, action="update")
def persist_to_database(self, appstruct): forms.merge_session_with_post(self.context, appstruct) self.request.dbsession.merge(self.context) self.request.registry.notify(FileUpdated(self.request, self.context))
def persist_to_database(self, appstruct): forms.merge_session_with_post(self.request.context, appstruct) self.request.dbsession.merge(self.request.context) self.request.session.flash(self.valid_msg)
def put(self): """ Rest put method : update a line """ log.debug("In the put method") line = self.getOne() appstruct = self.request.json_body try: appstruct = self.schema.deserialize(appstruct) except colander.Invalid, err: import traceback traceback.print_exc() log.exception(" - Erreur") raise RestError(err.asdict(), 400) line = merge_session_with_post(line, appstruct) self.request.dbsession.merge(line) self.request.dbsession.flush() return self.model_wrapper(line) def holidays_json(request): """ json view for holidays """ holidays = [HolidayJson(holiday) for holiday in Holiday.query()\ .filter(Holiday.user_id==request.context.id)] return dict(holidays=holidays, user_id=str(request.context.id))