def person_edit(id): btn_label = 'Update' hide_form = False form = TodoForm() todo_service = TodoService(db_session) local_user = get_local_user(user) if not todo_service.has_permission_from_id(id, local_user): return abort(403) if request.method == 'GET': record = todo_service.get_one(id) if record is not None: form.process(obj=record) else: abort(404) if form.validate_on_submit(): record = {} record['todo'] = form.data['todo'] record['description'] = form.data['description'] id = form.data['id'] try: todo_service.update(id, **record) except Exception as e: logger.error('Unable to update record: {0} with error: {1}'.format(record, e)) else: g.notifications.add_success(u'ToDo: {0} successfully updated.'.format( record['todo'])) hide_form = True else: g.notifications.add_wtf_errors(form) return render_template('add_edit.html', form=form, btn_label=btn_label, hide_form=hide_form)
def todo_delete(id): hide_form = False msg = u'' form = DeleteForm() todo_service = TodoService(db_session) local_user = get_local_user(user) if not todo_service.has_permission_from_id(id, local_user): return abort(403) if request.method == 'GET': record = todo_service.get_one(id) if record is not None: form.process(obj=record) msg = u'Are you sure you want to delete the ToDo: {0}?'.format( record.todo) else: abort(404) if form.validate_on_submit(): id = form.data['id'] try: todo_service.delete(id) except Exception as e: logger.error('Unable to delete record with error: {1}'.format(e)) else: g.notifications.add_success(u'ToDo successfully deleted.') hide_form = True return render_template('delete.html', form=form, msg=msg, hide_form=hide_form)