i see what is happening... i do not know how to get around it, but on
forms.py - you are populating categories from your model.categories(),
but the problem is when you first import the module, it's populating
from the original list - it does not see the updated list.
it may be a modelling problem.
if branko or justin davis were around, they could spot this
immediately.
i'll email them and ask them to look at this, but i'm certain that is
what is going on.

On May 17, 12:11 pm, ProfessionalIT <[email protected]> wrote:
> Friend Greg,
>
> On May 17, 12:01 pm, Greg Milby <[email protected]> wrote:
>
> > *is your list a static/html list? if so - you may have to restart the
> > webserver  to get it to refresh the list
> > *-----------------------
>
> No, No, is a dynamic page, see:
>
> my forms.py
>
> from web import form
> import model
>
> search_category_form = form.Form(
>         form.Textbox('search', size=20, description="Description:"),
>         form.Button('Pesquisa'),
>     )
>
> category_form = form.Form(
>     form.Textbox('description', form.notnull, size=150,
> description="Description:"),
>     form.Button('Salva'),
> )
>
> category_list = model.get_categories()
> category_options = [(row.id, row.description) for row in
> category_list]
> post_form = form.Form(
>     form.Textbox('title', form.notnull, size=30, description="Post
> title:"),
>     form.Dropdown('category', category_options),
>     form.Textarea('content', form.notnull, rows=30, cols=80,
> description="Post content:"),
>     form.Button('Post entry'),
> )
>
> my model.py
>
> import web, datetime
>
> db = web.database(dbn='postgres', host='***********', db='**********',
> user='***********', pw='**********')
>
> def get_categories(search=None):
>     if search != '' and search != 'NULL' and search != None:
>         return db.select('categories', where='description=$search',
> vars=locals())
>     else:
>         return db.select('categories')
>
> def get_category(id):
>     try:
>         return db.select('categories', where='id=$id', vars=locals())
> [0]
>     except IndexError:
>         return None
>
> def new_category(description):
>     db.insert('categories', description=description)
>
> def update_category(id, description):
>     db.update('categories', where="id=$id", vars=locals(),
> description=description)
>
> def del_category(id):
>     db.delete('categories', where="id=$id", vars=locals())
>
> def get_posts():
>     return db.select('entries', order='id DESC')
>
> def get_post(id):
>     try:
>         return db.select('entries', where='id=$id', vars=locals())[0]
>     except IndexError:
>         return None
>
> def new_post(title, text, category):
>     db.insert('entries', title=title, content=text,
> posted_on=datetime.datetime.utcnow(), category=category)
>
> def del_post(id):
>     db.delete('entries', where="id=$id", vars=locals())
>
> def update_post(id, title, text, category):
>     db.update('entries', where="id=$id", vars=locals(),
>         title=title, content=text, category=category)
>
> my code.py
>
> #!/usr/bin/python
>
> """ Basic blog using webpy 0.3 """
> import web
> import model
> import forms
>
> ### Url mappings
>
> urls = (
>     '/', 'Index',
>     '/categories/(.*)', 'Categories',
>     '/view_category/(\d+)', 'ViewCategory',
>     '/new_category', 'NewCategory',
>     '/edit_category/(\d+)', 'EditCategory',
>     '/delete_category/(\d+)', 'DeleteCategory',
>     '/view_post/(\d+)', 'ViewPost',
>     '/new_post', 'NewPost',
>     '/delete_post/(\d+)', 'DeletePost',
>     '/edit_post/(\d+)', 'EditPost',
> )
>
> ### Templates
> t_globals = {
>     'datestr': web.datestr}
>
> render = web.template.render('templates', base='base',
> globals=t_globals)
>
> class Index:
>
>     def GET(self):
>         """ Show page """
>         posts = model.get_posts()
>         return render.index(posts)
>
> class Categories:
>
>     def GET(self, search=None):
>         """ Show Categories """
>         form = forms.search_category_form()
>         categories = model.get_categories(search)
>         return render.categories(categories, form)
>
>     def POST(self, search=None):
>         form = forms.search_category_form()
>         if not form.validates():
>             return render.categories(form)
>         search=form.d.search
>         categories = model.get_categories(search)
>         return render.categories(categories, form)
>
> class ViewCategory:
>
>     def GET(self, id):
>         """ View single category """
>         category = model.get_category(int(id))
>         return render.view_category(category)
>
> class NewCategory:
>
>     def GET(self):
>         form = forms.category_form()
>         return render.categoria(form)
>
>     def POST(self):
>         form = forms.category_form()
>         if not form.validates():
>             return render.categoria(form)
>         model.new_category(form.d.description)
>         raise web.seeother('/')
>
> class EditCategory:
>
>     def GET(self, id):
>         category = model.get_category(int(id))
>         form = forms.category_form()
>         form.fill(category)
>         return render.edit_category(category, form)
>
>     def POST(self, id):
>         form = forms.category_form()
>         category = model.get_category(int(id))
>         if not form.validates():
>             return render.edit_category(category, form)
>         model.update_category(int(id), form.d.description)
>         raise web.seeother('/')
>
> class DeleteCategory:
>
>     def POST(self, id):
>         model.del_category(int(id))
>         raise web.seeother('/')
>
> class ViewPost:
>
>     def GET(self, id):
>         """ View single post """
>         post = model.get_post(int(id))
>         return render.view(post)
>
> class NewPost:
>
>     def GET(self):
>         form = forms.post_form()
>         return render.new(form)
>
>     def POST(self):
>         form = forms.post_form()
>         if not form.validates():
>             return render.new(form)
>         model.new_post(form.d.title, form.d.content, form.d.category)
>         raise web.seeother('/')
>
> class DeletePost:
>
>     def POST(self, id):
>         model.del_post(int(id))
>         raise web.seeother('/')
>
> class EditPost:
>
>     def GET(self, id):
>         post = model.get_post(int(id))
>         form = forms.post_form()
>         form.fill(post)
>         return render.edit(post, form)
>
>     def POST(self, id):
>         form = forms.post_form()
>         post = model.get_post(int(id))
>         if not form.validates():
>             return render.edit(post, form)
>         model.update_post(int(id), form.d.title, form.d.content,
> form.d.category)
>         raise web.seeother('/')
>
> app = web.application(urls, globals())
> web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func,
> addr)
>
> if __name__ == '__main__':
>     app.run()
>
> --
> You received this message because you are subscribed to the Google Groups 
> "web.py" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/webpy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to