예제 #1
0
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')
예제 #2
0
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')
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
def hello_view(req):
    return render_response('index.jinja')
예제 #7
0
 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)
예제 #8
0
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)
예제 #9
0
def view_index(req):
    return render_response('index.jinja', pages=Page.query)
예제 #10
0
def main_view(req):
    s = get_store()
    return render_response('index.jinja',
        persons=s.find(Person).order_by('name'))
예제 #11
0
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)
예제 #12
0
def index_view(req):
    return render_response('notes_index.jinja',
        notes=session.query(Note).order_by(Note.id))
예제 #13
0
def index_view(req):
    return render_response('login.jinja')
예제 #14
0
def add_success_view(req):
    return render_response('notes_success.jinja')
예제 #15
0
 def _simple_view(req):
     return render_response('variables.html', hello='byebye')
예제 #16
0
 def _simple_view(req):
     return render_response('events.html')
예제 #17
0
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)