示例#1
0
def update(request):
    """
    Updating a paste.

    return to display if succed.
    return to edit if fail.
    """
    paste = Paste.get(request.matchdict['idContent'])

    password = _buildPassword(paste.username, paste.created,
                              request.POST['password'])

    if password == paste.password:
        paste.title = request.POST['title']
        paste.content = request.POST['content']

        paste.save()

        request.session.flash(u"Updated")  # TODO translatoion

        return HTTPFound(request.route_path('oneContent', idContent=paste._id))

    request.session.flash(u"Wrong password")  # TODO translatoion

    return HTTPFound(request.route_path('edit', idContent=paste._id))
示例#2
0
def contentRaw(request):
    """
    Display a raw content paste.
    """
    paste = Paste.get(request.matchdict['idContent'])
    # TODO type/mime
    return paste.content
示例#3
0
def contentRaw(request):
    """
    Display a raw content paste.
    """
    paste = Paste.get(request.matchdict['idContent'])
    # TODO type/mime
    return paste.content
示例#4
0
def edit(request):
    """
    Edit a paste.
    """
    paste = Paste.get(request.matchdict['idContent'])

    return {'lexers': lexers(),
            'paste': paste,}
示例#5
0
def edit(request):
    """
    Edit a paste.
    """
    paste = Paste.get(request.matchdict['idContent'])

    return {'lexers': lexers(),
            'paste': paste,}
示例#6
0
def content(request):
    """
    Display a content Paste.
    """
    paste = Paste.get(request.matchdict['idContent'])
    lexer = get_lexer_by_name(paste.typeContent, stripall=True)

    result = highlight(paste['content'], lexer, formatter)

    return {'paste': paste,
            'content': result,}
示例#7
0
def content(request):
    """
    Display a content Paste.
    """
    paste = Paste.get(request.matchdict['idContent'])
    lexer = get_lexer_by_name(paste.typeContent, stripall=True)

    result = highlight(paste['content'], lexer, formatter)

    return {'paste': paste,
            'content': result,}
示例#8
0
def deleteConfirm(request):
    """
    Ask confirmation on delete.
    """
    paste = Paste.get(request.matchdict['idContent'])

    if not(paste.username and paste.password):
        return HTTPFound(request.route_path('oneContent', idContent=paste._id))

    lexer = get_lexer_by_name(paste.typeContent, stripall=True)

    result = highlight(paste['content'], lexer, formatter)

    return {'paste': paste,
            'content': result,}
示例#9
0
def deleteConfirm(request):
    """
    Ask confirmation on delete.
    """
    paste = Paste.get(request.matchdict['idContent'])

    if not(paste.username and paste.password):
        return HTTPFound(request.route_path('oneContent', idContent=paste._id))

    lexer = get_lexer_by_name(paste.typeContent, stripall=True)

    result = highlight(paste['content'], lexer, formatter)

    return {'paste': paste,
            'content': result,}
示例#10
0
def delete(request):
    """
    Delete a paste.

    return to / if succed
    return to deleteConfigm is fail.
    """
    paste = Paste.get(request.matchdict['idContent'])

    password = _buildPassword(paste.username, paste.created,
                              request.POST['password'])

    if password == paste.password:

        paste.delete()

        request.session.flash(u"Deleted")  # TODO translatoion

        return HTTPFound(request.route_path('home', ))

    request.session.flash(u"Wrong password")  # TODO translatoion

    return HTTPFound(request.route_path('deleteConfirm', idContent=paste._id))
示例#11
0
def delete(request):
    """
    Delete a paste.

    return to / if succed
    return to deleteConfigm is fail.
    """
    paste = Paste.get(request.matchdict['idContent'])

    password = _buildPassword(paste.username,
                              paste.created,
                              request.POST['password'])

    if password == paste.password:

        paste.delete()

        request.session.flash(u"Deleted") # TODO translatoion

        return HTTPFound(request.route_path('home', ))

    request.session.flash(u"Wrong password") # TODO translatoion

    return HTTPFound(request.route_path('deleteConfirm', idContent=paste._id))
示例#12
0
def update(request):
    """
    Updating a paste.

    return to display if succed.
    return to edit if fail.
    """
    paste = Paste.get(request.matchdict['idContent'])

    password = _buildPassword(paste.username, paste.created, request.POST['password'])

    if password == paste.password:
        paste.title = request.POST['title']
        paste.content = request.POST['content']

        paste.save()

        request.session.flash(u"Updated") # TODO translatoion

        return HTTPFound(request.route_path('oneContent', idContent=paste._id))

    request.session.flash(u"Wrong password") # TODO translatoion

    return HTTPFound(request.route_path('edit', idContent=paste._id))
示例#13
0
 def __call__(self, context, request):
     try:
         request.paste = Paste.get(request.matchdict['idContent'])
         return True
     except couchdbkit.exceptions.ResourceNotFound:
         return False