Beispiel #1
0
def create_page_view(request):
    owner = authenticated_userid(request)
    user = User.get_user(owner)

    errors = []
    body = title = ''
    if request.method == 'POST':
        title = request.POST.get('title', '')
        body = request.POST.get('body', '')

        v = validate_page(title, body)
        title = v['title']
        body = v['body']
        errors += v['errors']

        if not errors:
            page = Page(title=title, uri=Page.websafe_uri(title), owner=user.id, body=body)
            DBSession.add(page)
            url = request.route_url('page', title=page.uri)
            return HTTPFound(location=url)

    return {
        'title': title,
        'owner': owner,
        'body': body,
        'errors': errors,
    }
Beispiel #2
0
def home_view(request):
    user_id = authenticated_userid(request)
    if user_id:
        user = User.by_id(user_id)
    else:
        user = None
    try:
        user_pages = DBSession.query(Page).filter(Page.owner == user.id).all()
    except:
        user_pages = None

    return {
        'user': user,
        'user_pages': user_pages,
        'request': request,
    }
Beispiel #3
0
def pages_view(request):
    pages = DBSession.query(Page).all()
    return {
        'pages': pages,
    }
Beispiel #4
0
    except Exception, e:
        log.debug('WARNING: {0}'.format(e))

    errors = []
    title = page.title
    body = page.body
    if request.method == 'POST':
        title = request.POST.get('title', '')
        body = request.POST.get('body', '')

        v = validate_page(title, body)
        title = v['title']
        body = v['body']
        errors += v['errors']

        if not errors:
            page.title = title
            page.body = body
            page.uri = Page.websafe_uri(title)
            DBSession.add(page)
            url = request.route_url('page', title=page.uri)
            return HTTPFound(location=url)

    return {
        'title': title,
        'owner': user.login,
        'body': body,
        'errors': errors,
    }