def edit_submit_view(req, nid): # find note note = session.query(Note).get(nid) # TODO: check if note exists note.title = req.form.get('title') note.note = req.form.get('text') note.importance = req.form.get('importance') session.add(note) session.commit() return render_response('notes_success.jinja')
def add_view(req): # validate form title = req.form.get('title', 'kT') text = req.form.get('text') prio = req.form.get('importance') if not text: text = "kT" note = Note(title, text, prio) session.add(note) session.commit() return render_response('notes_success.jinja')
def view_edit(req, page_name): page = _get_page(page_name) if req.method == 'POST': if page is None: page = Page(name=page_name) page.save() rev = Revision(page=page, text=req.form.get('text')) rev.save() session.commit() return redirect_to('show', page_name=page.name) else: if page is not None: page_name = page.name return render_response('edit.jinja', page=page, page_name=page_name)
def add_edit_view(req, nid=None): if nid is None: form = NotesForm(req.form) # Validate form if req.method == 'POST' and form.validate(): # No validation errors, save note and redirect to success page note = Note( req.form.get('title'), req.form.get('note'), req.form.get('importance') ) db.add(note) db.commit() return redirect(url_for('example/success')) return render_response('notes_add.jinja', form=form) else: # Find note note = db.query(Note).get(nid) # Check if note exists if note is None: return Response('Not Found', status=404) # Form with values form = NotesForm(req.form, title = note.title, note = note.note, importance = note.importance ) # Validate form if req.method == 'POST' and form.validate(): # No validation errors, update note and redirect to success page note.title = req.form.get('title') note.note = req.form.get('note') note.importance = req.form.get('importance') db.add(note) db.commit() return redirect(url_for('example/success')) return render_response('notes_edit.jinja', note=note, form=form)
def view_login(request): """Show a login page.""" error = None form = UserForm(request.form) if request.method == 'POST': if form.validate(): username = form.username.data password = form.password.data if username and check_username_password(username, password): login(username) return redirect('/') error = ('Incorrect password.') return render_response('auth_login.jinja', error=error, auth_form=form)
def hello_view(req): return render_response('index.jinja')
def render_response(self, template_name, **kw): kw['url_local'] = self.url_local kw['url_shared'] = self.url_shared return render_response(template_name, **kw)
def view_show(req, page_name): page = _get_page(page_name) if page is None: return redirect_to('edit', page_name=page_name) return render_response('show.jinja', page=page)
def view_index(req): return render_response('index.jinja', pages=Page.query)
def main_view(req): s = get_store() return render_response('index.jinja', persons=s.find(Person).order_by('name'))
def edit_view(req, nid): # find note note = session.query(Note).get(nid) # TODO: check if note exists return render_response('notes_edit.jinja', note=note)
def index_view(req): return render_response('notes_index.jinja', notes=session.query(Note).order_by(Note.id))
def index_view(req): return render_response('login.jinja')
def add_success_view(req): return render_response('notes_success.jinja')
def _simple_view(req): return render_response('variables.html', hello='byebye')
def _simple_view(req): return render_response('events.html')
def index_view(req): notes = db.query(Note).order_by(Note.id.desc()).all() form = NotesForm(req.form) return render_response('notes_index.jinja', notes=notes, form=form)