Ejemplo n.º 1
0
def add(request):
    """
    Adding a new content.

    if ok return to the oneContent page.
    """
    username = request.POST['username']
    password = ''

    now = datetime.datetime.now()
    expire = request.POST['expire']

    expireDate = None

    if expire:
        delta = expireChoice[expire]

        if delta:
            expireDate = now + delta

    if username:
        password = bcrypt.hashpw(request.POST['password'], bcrypt.gensalt())

    paste = Paste(title=request.POST['title'],
                  content=request.POST['content'],
                  created=now,
                  typeContent=request.POST['type'],
                  username=username,
                  password=password,
                  expire=expireDate)
    paste.save()

    request.session.flash(u"Add ok")  # TODO translatoion

    return HTTPFound(request.route_path('oneContent', idContent=paste._id))
Ejemplo n.º 2
0
def newPaste(request, language, content, parent_id, filename, mimetype,
             private):
    """
    xmlprc methods for paste.

    first usage in bpythpn :
    language contains 'pycon'
    content containt the content to paste
    private content true
    others are empty.

    signature found here :
    http://dev.pocoo.org/hg/lodgeit-main/file/22a108f3aa85/lodgeit/lib/webapi.py#l64
    """
    now = datetime.datetime.now()

    delta = expireChoice['1day']
    expireDate = now + delta

    if not mimetype:
        mimetype = settings['default_mimetype']

    paste = Paste(title='',
                  content=content,
                  created=now,
                  typeContent=mimetype,
                  username='',
                  password='',
                  expire=expireDate)
    paste.save()

    return paste._id
Ejemplo n.º 3
0
def contentRaw(request):
    """
    Display a raw content paste.
    """
    paste = Paste.get(request.matchdict['idContent'])
    # TODO type/mime
    return paste.content
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
def contentRaw(request):
    """
    Display a raw content paste.
    """
    paste = Paste.get(request.matchdict['idContent'])
    # TODO type/mime
    return paste.content
Ejemplo n.º 6
0
def edit(request):
    """
    Edit a paste.
    """
    paste = Paste.get(request.matchdict['idContent'])

    return {'lexers': lexers(),
            'paste': paste,}
Ejemplo n.º 7
0
def edit(request):
    """
    Edit a paste.
    """
    paste = Paste.get(request.matchdict['idContent'])

    return {'lexers': lexers(),
            'paste': paste,}
Ejemplo n.º 8
0
def previous():
    """
    Return the list of the 10 previous paste.
    """
    try:
        previousPastes = Paste.view('paste/all',  limit=10).all()
    except:
        previousPastes = []
    return previousPastes
Ejemplo n.º 9
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,}
Ejemplo n.º 10
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,}
Ejemplo n.º 11
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,}
Ejemplo n.º 12
0
def main():
    """
    Purge old paste.
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--conf', help='paulla.paste conf file')

    args = parser.parse_args()

    config = ConfigParser.RawConfigParser()
    config.read(args.conf)

    logging.config.fileConfig(args.conf)
    logger = logging.getLogger('purge')

    server = couchdbkit.Server(config.get('app:main', 'couchdb.url'))
    db = server.get_or_create_db(config.get('app:main', 'couchdb.db'))
    Paste.set_db(db)

    oldPastes = Paste.view('old/all').all()

    for paste in oldPastes:
        logger.info("deleting %s", paste._id)
        paste.delete()
Ejemplo n.º 13
0
def add(request):
    """
    Adding a new content.

    if ok return to the oneContent page.
    """
    username = request.POST['username']
    password = ''


    now = datetime.datetime.now()
    expire = request.POST['expire']

    expireDate = None

    if expire:
        delta = expireChoice[expire]

        if delta:
            expireDate = now + delta

    if username:
      password = _buildPassword(username, now, request.POST['password'])

    paste = Paste(title=request.POST['title'],
                  content=request.POST['content'],
                  created=now,
                  typeContent=request.POST['type'],
                  username=username,
                  password=password,
                  expire=expireDate)
    paste.save()

    request.session.flash(u"Add ok") # TODO translatoion

    return HTTPFound(request.route_path('oneContent', idContent=paste._id))
Ejemplo n.º 14
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,}
Ejemplo n.º 15
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))
Ejemplo n.º 16
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))
Ejemplo n.º 17
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))
Ejemplo n.º 18
0
 def __call__(self, context, request):
     try:
         request.paste = Paste.get(request.matchdict['idContent'])
         return True
     except couchdbkit.exceptions.ResourceNotFound:
         return False
Ejemplo n.º 19
0
def previous():
    """
    Return the list of the 10 previous paste.
    """
    previousPastes = Paste.view('paste/all',  limit=10).all()
    return previousPastes
Ejemplo n.º 20
0
from paulla.paste.models import Paste
from paulla.paste.paste_predicate import PastePredicate

settings = get_current_registry().settings

expireChoice = {
    "never": None,
    "1day": datetime.timedelta(days=1),
    "1week": datetime.timedelta(days=7),
    "1month": datetime.timedelta(days=31)
}

# couchdb connection
server = couchdbkit.Server(settings['couchdb.url'])
db = server.get_or_create_db(settings['couchdb.db'])
Paste.set_db(db)

formatter = HtmlFormatter(linenos=True, full=True, cssclass="source")


@view_config(route_name='home', renderer='templates/home.pt')
def home(request):
    """
    Home page.

    first page to be called.
    """
    return {'lexers': lexers()}


@view_config(route_name='addContent', renderer='json')
Ejemplo n.º 21
0
def previous():
    """
    Return the list of the 10 previous paste.
    """
    previousPastes = Paste.view('paste/all', limit=10, descending=True).all()
    return previousPastes
Ejemplo n.º 22
0
from paulla.paste.models import Paste


settings = get_current_registry().settings

expireChoice = {"never": None,
                "1day": datetime.timedelta(days=1),
                "1week": datetime.timedelta(days=7),
                "1month": datetime.timedelta(days=31)
                }

# couchdb connection
server = couchdbkit.Server(settings['couchdb.url'])
db = server.get_or_create_db(settings['couchdb.db'])
Paste.set_db(db)

formatter = HtmlFormatter(linenos=True, full=True, cssclass="source")

@view_config(route_name='home', renderer='templates/home.pt')
def home(request):
    """
    Home page.

    first page to be called.
    """
    return {'lexers': lexers()}

def _buildPassword(username, createdTime, password):
    """
    Build sha1 of password.