def index(self, request): form = AddPasteForm(request.form) if form.validate_on_submit(): e = PasteEntry(text=form.text.data, language=form.language.data or None, title=form.title.data, author=request.user) if form.parent.data: e.parent_id = form.parent.data db.session.commit() return redirect_to(e) parent_id = request.args.get('reply_to', None) if parent_id is not None and parent_id.isdigit(): parent = PasteEntry.query.get(int(parent_id)) form = AddPasteForm( **{ 'title': parent.title, 'language': parent.language, 'text': parent.text, 'parent': parent.id }) return { 'form': form, }
def create_pastebin_test_data(): from inyoka.core.auth.models import User from inyoka.paste.models import PasteEntry u = User.query.get(u'admin') e1 = PasteEntry(text=u'print "Hello World"', author=u, language=u'python') db.session.commit() e1.children.append( PasteEntry(text=u'print "hello world"', author=u, language=u'python')) db.session.commit()
def show_tree(self, request, id): """Display the tree of some related pastes.""" paste = PasteEntry.resolve_root(id) if paste is None: raise exc.NotFound() return {'paste': paste, 'current': id}