def new_entry(request): main = get_renderer(BASE_TEMPLATE).implementation() bibitex_form = BibitexForm.get_form() if 'submit' in request.POST: controls = request.POST.items() try: appstruct = bibitex_form.validate(controls) except deform.ValidationFailure, e: return{'main':main, 'form': e.render(), 'user':get_user(request), } bibitex = appstruct.copy() del(bibitex['document']) appstruct['bibitex'] = create_bibitex(bibitex) if appstruct['wiki']: appstruct['wiki_as_html'] = textile(appstruct['wiki']) else: appstruct['wiki_as_html'] = '' appstruct['modified_at'] = str(datetime.now()) bibitex = Bibitex.from_python(appstruct) bibitex.save(request.couchdb) indexer.index(bibitex._id,appstruct) return HTTPFound(location='/biblio/%s' % bibitex._id)
class BibitexForm(): base_schema = Bibitex.get_schema() base_schema['review'].widget = deform.widget.TextAreaWidget(cols=80, rows=15) @classmethod def get_form(cls): return deform.Form(cls.base_schema, buttons=('submit', ))
def new(request): bibitex_form = BibitexForm.get_form() if 'submit' in request.POST: controls = request.POST.items() try: appstruct = bibitex_form.validate(controls) except deform.ValidationFailure, e: return render_to_response('bibitex:form.pt', {'content': e.render()}) bibitex = Bibitex.from_python(appstruct) bibitex.save(db) return Response('Saved under id: %s' % bibitex._id)
def view_biblio(request): main = get_renderer(BASE_TEMPLATE).implementation() try: bibitex = Bibitex.get(request.couchdb, request.matchdict['id']) except ResourceNotFound: return Response('404') try: document_url = bibitex.document['filename'] except AttributeError: document_url = None metadata = bibitex.to_python() metadata['authors'] = normalize_name(metadata['authors']) return {'main':main, 'metadata':metadata, 'reference':bibitex.bibitex, 'wiki':bibitex.wiki_as_html, 'user':get_user(request), 'download':document_url, }
if appstruct['wiki']: appstruct['wiki_as_html'] = textile(appstruct['wiki']) else: appstruct['wiki_as_html'] = '' appstruct['modified_at'] = str(datetime.now()) bibitex = Bibitex.from_python(appstruct) bibitex.save(request.couchdb) indexer.index(bibitex._id,appstruct) return HTTPFound(location='/biblio/%s' % bibitex._id) else: if 'id' in request.matchdict: #edit bibitex = Bibitex.get(request.couchdb, request.matchdict['id']) return {'main':main, 'form': bibitex_form.render(bibitex.to_python()), 'user':get_user(request), } return {'main':main, 'form':bibitex_form.render(), 'user':get_user(request), } def view_biblio(request): main = get_renderer(BASE_TEMPLATE).implementation() try: bibitex = Bibitex.get(request.couchdb, request.matchdict['id'])
if 'submit' in request.POST: controls = request.POST.items() try: appstruct = bibitex_form.validate(controls) except deform.ValidationFailure, e: return render_to_response('bibitex:form.pt', {'content': e.render()}) bibitex = Bibitex.from_python(appstruct) bibitex.save(db) return Response('Saved under id: %s' % bibitex._id) else: if 'id' in request.matchdict: #edit bibitex = Bibitex.get(db, request.matchdict['id']) return render_to_response('bibitex:form.pt', {'content': bibitex_form.render(bibitex.to_python())}) return render_to_response('bibitex:form.pt', {'content': bibitex_form.render()}) def index(request): records = db.view('_all_docs', include_docs=True) return render_to_response('bibitex:index.pt', {'records':records})