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))
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
def contentRaw(request): """ Display a raw content paste. """ paste = Paste.get(request.matchdict['idContent']) # TODO type/mime return paste.content
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))
def edit(request): """ Edit a paste. """ paste = Paste.get(request.matchdict['idContent']) return {'lexers': lexers(), 'paste': paste,}
def previous(): """ Return the list of the 10 previous paste. """ try: previousPastes = Paste.view('paste/all', limit=10).all() except: previousPastes = [] return previousPastes
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,}
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,}
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()
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))
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))
def __call__(self, context, request): try: request.paste = Paste.get(request.matchdict['idContent']) return True except couchdbkit.exceptions.ResourceNotFound: return False
def previous(): """ Return the list of the 10 previous paste. """ previousPastes = Paste.view('paste/all', limit=10).all() return previousPastes
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')
def previous(): """ Return the list of the 10 previous paste. """ previousPastes = Paste.view('paste/all', limit=10, descending=True).all() return previousPastes
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.