MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/e6abx/getting_started_with_pyramid_a_notes_application/c18mjam/?context=3
r/Python • u/schaueho • Nov 15 '10
12 comments sorted by
View all comments
-12
Can't you make that a little more compact? Here is the same (entire core) rewritten with web2py (we added a validator too and wiki support):
#models/db.html from gluon.tools import Crud db=DAL('sqite://storage.sqlite') crud=Crud(globals(),db) db.define_table('note',Field('body','text',requires=IS_NOT_EMPTY())) #controllers/default.py def index(): # was main_view return dict(form=crud.create(db.note),notes=db(db.note).select()) def edit_note(): return dict(form=crud.update(db.note,db.note(request.args(0),next='index') or redirect(URL('index')))) #views/layout.html <!DOCTYPE html> <!-- NoteTaker/src/notetaker/templates/layout.html --> <html> <head> <title>NoteTaker</title> <link rel="stylesheet" href="{{=URL('static','style.css')}}" type="text/css" /> </head> <body> <header> <h1>NoteTaker :: {{ block title }}Main{{ end }}</h1> </header> <article> {{include}} </article> </body> </html> #views/default/index.html {{ extend "layout.html" }} <section id="notes-section"> <table> <thead> <tr><th>Id</th><th class="text">Text</th><th> </th></tr> </thead> <tbody> {{ for note in notes: }} <tr> <td>{{ note.id }}</td> <td>{{=MARKMIN(note.body)}}</td> <td><a href="{{=URL('edit_note', args=note.id)}}">edit</a></td> </tr> {{ pass }} </tbody> <tfoot> <td colspan="3">{{ =len(notes) }} entries</td> </tfoot> </table> </section> <section id="note-add-section"> {{=form}} </section> #view/default/edit_note.html {{ extend "layout.html" }} {{ block title }}Edit {{ =form.record.id }}{{ end }} {{=form}}
Works on GAE too if you replace 'sqite://storage.sqlite' with 'gae'.
0 u/pbreit Dec 11 '10 Should this line be: return dict(form=crud.update(db.note,db.note(request.args(0)),next='index')) or redirect(URL('index')) 1 u/mdipierro Dec 11 '10 oops. yes.
0
Should this line be: return dict(form=crud.update(db.note,db.note(request.args(0)),next='index')) or redirect(URL('index'))
1 u/mdipierro Dec 11 '10 oops. yes.
1
oops. yes.
-12
u/mdipierro Nov 15 '10 edited Nov 15 '10
Can't you make that a little more compact? Here is the same (entire core) rewritten with web2py (we added a validator too and wiki support):
Works on GAE too if you replace 'sqite://storage.sqlite' with 'gae'.