Esempio n. 1
0
def page_view(request):
    page_id = request.matchdict['page_id']
    page = request.context.page
    if not page:
        ## TODO: setup notfound view
        raise NotFound("No such page {0}".format(page_id))
    logged_in = authenticated_userid(request)
    api = get_template('ravel:templates/main.pt')
    commentschema = Comment()
    commentform = Form(commentschema,
                       action=route_url('comment_add', 
                                        request,
                                        page_id=page_id),
                       buttons=('submit',),
                       use_ajax=True)
    commentform['comment'].widget = widget.TextAreaWidget(rows=10, cols=60)
    print page.get('comments', None)
    return {
        'api' : api,
        'description' : page['description'],
        'edit_url' :  route_url('page_edit', request, page_id=page_id),
        'logged_in' : logged_in,
        'title' : page['title'],
        'body' : page['body'],
        'commentform' : commentform.render(),
        'comments' : page.get('comments', None)
        }
Esempio n. 2
0
def page_edit(request):
    page_id = request.matchdict['page_id']
    page = request.context.page
    if not page:
        ## TODO: setup notfound view
        raise NotFound("No such part {0}".format(page_id))
    logged_in = authenticated_userid(request)
    api = get_template('ravel:templates/main.pt')
    schema = request.context.schema
    form = Form(schema, buttons=('submit',))
    form['body'].widget = widget.TextAreaWidget(rows=10, cols=60)
    if request.method == "POST":
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
        except ValidationFailure, e:
            return {
                'api'   : api,
                'description' : 'Edit ' + page['title'],
                'form': e.render(),
                'logged_in' : logged_in,
                'title' : 'Edit ' + page['title'],
                }
        appstruct['_id'] = page['_id']
        appstruct['url_id'] = page_id
        oid = request.context.collection.save(appstruct, safe=True)
        logging.info("page_edit saved {0}".format(oid))
        return HTTPFound(location=route_url('page_view', request, page_id=page_id))
Esempio n. 3
0
def login(request):
    api = get_template("ravel:templates/main.pt")
    login_url = route_url('login', request)
    referrer = request.url
    if referrer == login_url:
        referrer = '/'
    came_from = request.params.get('came_from', referrer)
    message = login = password = ''
    if 'form.submitted' in request.params:
        login = request.params['login']
        password = request.params['password']
        try:
            user = request.root.db['users'].find({'username': login}).next()
        except StopIteration:
            user = None
        if user:
            if sha224(password).hexdigest() == user['password']:
                headers = remember(request, login)
                
                request.root.db.users.update({"_id" : user['_id']}, 
                                             {"$set" : {'last_login' : datetime.now() }})
                return HTTPFound(location=came_from,
                                 headers=headers)
        message = 'Login failed'
    return dict(
        api = api,
        came_from = came_from,
        login = login,
        logged_in = authenticated_userid(request),
        message = message,
        password = password,
        section = 'login',
        title = 'ravel | Log in',
        url = request.application_url + '/login',
        )
Esempio n. 4
0
def index(request):
    api = get_template("ravel:templates/main.pt")
    collection =  request.context.collection 
    page = collection.find_one({'url_id' : 'home'})
    logged_in = authenticated_userid(request)
    if page:
        title = page['title']
        description = page['description']
        body = page['body']
    else:
        page = dict(
            title = 'Home',
            description = "A zpug demo presentation app",
            body = '<p>Edit me again please</p>',
            url_id = 'home')
        collection.save(page)
        title = page['title']
        description = page['description']
        body = page['body']
        
    return {
        'api' : api,
        'body' : body,
        'description': description,
        'edit_url' :  route_url('page_edit', request, page_id="home"),
        'logged_in' : logged_in,
        'section' : 'home',
        'title': title,
        'comments' : None,
        'commentform' : None
        }
Esempio n. 5
0
def not_implemented(request):
    api = get_template('ravel:templates/main.pt')
    path = request.get('PATH_INFO').strip('/')
    logged_in = authenticated_userid(request)
    return {
        'api' : api,
        'description' : "An unimplemented page",
        'logged_in' : logged_in,
        'path': path,
        'title':'Not Implemented',
        }
Esempio n. 6
0
def article_listing(request):
    api = get_template('ravel:templates/main.pt')
    query_string = parse_qs(request.get("QUERY_STRING", None))
    batch_start = query_string.get('batch_start', 0)
    limit = query_string.get('limit', 10)
    collection = request.context.db.pages
    articles = collection.find().skip(int(batch_start)).limit(int(limit))
    return {
        'api' : api,
        'title' : "Article Listing",
        'description' : "A listing of articles",
        'logged_in' : authenticated_userid(request),
        'section' : 'articles',
        'articles' : articles,
        }
Esempio n. 7
0
def page_add(request):
    logged_in = authenticated_userid(request)
    api = get_template('ravel:templates/main.pt')
    schema = request.context.schema
    form = Form(schema, buttons=('submit',))
    form['body'].widget = widget.TextAreaWidget(rows=10, cols=60)
    if request.method == "POST":
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
        except ValidationFailure, e:
            return {
                'api'   : api,
                'description' : 'Add page',
                'form': e.render(),
                'logged_in' : logged_in,
                'title' : 'Edit page',
                }
        title_or_id = appstruct['title']
        url_id = insert_doc(request.context.collection, appstruct, title_or_id)
        oid = request.context.collection.save(appstruct, safe=True)
        logging.info("page_edit saved {0}".format(oid))
        return HTTPFound(location=route_url('page_view', request, page_id=url_id))
 def _callFUT(self, name):
     from pyramid.chameleon_zpt import get_template
     return get_template(name)
Esempio n. 9
0
 def _callFUT(self, name):
     from pyramid.chameleon_zpt import get_template
     return get_template(name)