It looks like you took the IS_IN_SET off of page_articles.placement:
db.define_table('page_articles',
Field('page', requires=IS_IN_DB(db,db.page.id,'%(name)s')),
Field('article', requires=IS_IN_DB(db,db.article.id,'%(title)s
- %(author)s')),
Field('placement', 'integer'))
Try adding it back and let me know.
On Sep 23, 2:05 pm, Jason Brower <[email protected]> wrote:
> I didn't think I did, at least not anything I thought would influence
> it. Here is what you would need.
> Best Regards,
> Jason Brower
>
> On Wed, 2009-09-23 at 11:29 -0700, mr.freeze wrote:
> > It works on the model and controller code you posted. Is it different
> > than what you're using?
>
> > On Sep 23, 1:19 pm, Jason Brower <[email protected]> wrote:
> > > I get the following error with this code...
> > > "SyntaxError: widget cannot determine options of
> > > page_articles.placement" - Line 64 of Default.py
> > > ---LINE 64 IS LABELED---
> > > def page_creator():
> > > response.title = "Page Creator"
> > > if len(request.args):
> > > pages = db(db.page_articles.id==request.args[0]).select()
> > > if len(request.args) and len(pages):
> > > page_form = SQLFORM(db.page_articles, pages[0], deletable=True)
> > > else:
> > > page_form = SQLFORM(db.page_articles)#<--- This is line 64
> > > if page_form.accepts(request.vars, session):
> > > response.flash = 'Action Commited Succesfully'
> > > elif page_form.errors:
> > > response.flash = 'Hmmm, something went wrong.'
> > > all_pages = db((db.page.id==db.page_articles.page) &
> > > (db.article.id==db.page_articles.article))
> > > return dict(page_form=page_form, all_pages=all_pages)
> > > ----
> > > And what you gave me...> if request.vars.page and request.vars.placement:
> > > > existing =
> > > > db((db.page_articles.page==request.vars.page)&(db.page_articles.placement==request.vars.placement))
> > > > db.page_articles.placement.requires = [IS_IN_SET(range(1,21)),
> > > > IS_NOT_IN_DB(existing, 'page_articles.placement')]
>
> > > Thanks for the help,
> > > Jason
>
> > > On Wed, 2009-09-23 at 08:37 -0700, mr.freeze wrote:
> > > > Here you go. You will need to force it to render with
> > > > SQLFORM.widgets.options.widget because IS_IN_SET won't render as a
> > > > dropdown when used with other validators. In your model:
>
> > > > db.page_articles.placement.widget = SQLFORM.widgets.options.widget
>
> > > > if request.vars.page and request.vars.placement:
> > > > existing = db((db.page_articles.page==request.vars.page)&
>
> > > > (db.page_articles.placement==request.vars.placement))
> > > > db.page_articles.placement.requires = [IS_IN_SET(range
> > > > (1,21)),IS_NOT_IN_DB(existing, 'page_articles.placement')]
>
> > > > On Sep 22, 9:55 pm, Jason Brower <[email protected]> wrote:
> > > > > Woah... way beyond me here.
> > > > > My tables are like this...
> > > > > ---
> > > > > db.define_table('page',
> > > > > Field('name', 'string', length=25),
> > > > > Field('description', 'text'),
> > > > > Field('created', 'datetime', default=now, readable=True,
> > > > > writable=False))
>
> > > > > db.define_table('article',
> > > > > Field('title', 'string', length=25),
> > > > > Field('text', 'text'),
> > > > > Field('media', 'upload', autodelete= True),
> > > > > Field('created', 'datetime', default=now, readable=True,
> > > > > writable=False),
> > > > > Field('types', requires=IS_IN_SET(['One', 'Two', 'Three'])),
> > > > > Field('columns', requires=IS_IN_SET(['One', 'Two', 'Three'])),
> > > > > Field('author',
> > > > > requires=IS_IN_DB(db,db.author.id,'%(full_name)s')))
>
> > > > > db.define_table('page_articles',
> > > > > Field('page', requires=IS_IN_DB(db,db.page.id,'%(name)s')),
> > > > > Field('article',
> > > > > requires=IS_IN_DB(db,db.article.id,'%(title)s')),
> > > > > Field('placement', requires=IS_IN_SET(range(1,21)))
> > > > > ---
> > > > > By how do I declare the request.var.page and request.var.placement in
> > > > > the model. Should it be the the controller?
> > > > > If so here is that page just in case....
> > > > > ---
> > > > > def page_creator():
> > > > > if len(request.args):
> > > > > pages = db(db.page_articles.id==request.args[0]).select()
> > > > > if len(request.args) and len(pages):
> > > > > page_form = SQLFORM(db.page_articles, pages[0],
> > > > > deletable=True)
> > > > > else:
> > > > > page_form = SQLFORM(db.page_articles)
> > > > > if page_form.accepts(request.vars, session):
> > > > > response.flash = 'Action Commited Succesfully'
> > > > > elif page_form.errors:
> > > > > response.flash = 'Hmmm, something went wrong.'
> > > > > all_pages = db((db.page.id==db.page_articles.page) &
> > > > > (db.article.id==db.page_articles.article))
> > > > > return dict(page_form=page_form, all_pages=all_pages)
> > > > > ---
> > > > > Thanks in advance guys,
> > > > > Jason
>
> > > > > On Tue, 2009-09-22 at 12:55 -0700, mr.freeze wrote:
> > > > > > If you can describe your constraint with as a DAL set, you can pass
> > > > > > it
> > > > > > to IS_NOT_IN_DB. Maybe something like this?
>
> > > > > > existing = db((db.page.number==request.vars.page)&
> > > > > > (db.placement.code==request.vars.placement))
> > > > > > db.article.number.requires = IS_NOT_IN_DB(existing,'article.number')
>
> > > > > > On Sep 22, 12:59 pm, Jason Brower <[email protected]> wrote:
> > > > > > > I have three major fields in a table:
> > > > > > > Page, Article and Placement
> > > > > > > I want to make sure that the placement is unique to that article
> > > > > > > so...
> > > > > > > Page1, Article1, 1
> > > > > > > Page2, Article2, 1
> > > > > > > Page1, Article3, 2
> > > > > > > But it will not alow placement of...
> > > > > > > Page1, Article4, 1
> > > > > > > or...
> > > > > > > Page1, Article1, 3
>
> > > > > > > I hope that makes sence.
> > > > > > > Regards,
> > > > > > > Jason Brower
>
>
>
> default.py
> 3KViewDownload
>
> db.py
> 2KViewDownload
>
> page_creator.html
> < 1KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---