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
> > 

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

# coding: utf8

#########################################################################
## This is a samples controller
## - index is the default action of any application
## - user is required for authentication and authorization
## - download is for downloading files uploaded in the db (does streaming)
## - call exposes all registered services (none by default)
#########################################################################

def index():
    response.title = "Page View"
    """
    example action using the internationalization operator T and flash
    rendered by views/default/index.html or views/generic.html
    """
    page_articles = db((db.page.id==db.page_articles.page) & (db.article.id==db.page_articles.article))
    page = page_articles(db.page.id == request.args[0]).select(orderby=db.page_articles.placement)
    return dict(page = page)


def page_manager():
    response.title = "Page Manager"
    if len(request.args):
        pages = db(db.page.id==request.args[0]).select()
    if len(request.args) and len(pages):
        page_form = SQLFORM(db.page, pages[0], deletable=True)
    else:
        page_form = SQLFORM(db.page)
    if page_form.accepts(request.vars, session):
        response.flash = 'Action Committed Succesfully'
    elif page_form.errors:
        response.flash = 'Hmmm, something went wrong.'

    return dict(page_form=page_form)

def article_manager():
    response.title = "Article Manager"
    if len(request.args):
        articles = db(db.article.id==request.args[0]).select()
    if len(request.args) and len(articles):
        articles_form = SQLFORM(db.article, articles[0], deletable=True, upload=URL(r=request,f='download'))
    else:
        articles_form = SQLFORM(db.article)
    if articles_form.accepts(request.vars, session):
        response.flash = 'Action Commited Succesfully'
    elif articles_form.errors:
        response.flash = 'Hmmm, something went wrong.'
    all_articles = db().select(db.article.ALL, orderby= db.article.author)
    return dict(articles_form=articles_form, all_articles = all_articles)


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)
    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)

def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    """
    return dict(form=auth())


def download():
    """
    allows downloading of uploaded files
    http://..../[app]/default/download/[filename]
    """
    return response.download(request,db)


def call():
    """
    exposes services. for example:
    http://..../[app]/default/call/jsonrpc
    decorate with @services.jsonrpc the functions to expose
    supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
    """
    session.forget()
    return service()
# coding: utf8
#########################################################################
## This scaffolding model makes your app work on Google App Engine too
#########################################################################
db = DAL('sqlite://storage.sqlite')
#########################################################################
from gluon.tools import *
from datetime import datetime, date, time
now = datetime.utcnow()
today = date.today()

auth=Auth(globals(),db)                      # authentication/authorization
auth.settings.hmac_key='<your secret key>'
auth.define_tables()                         # creates all needed tables
crud=Crud(globals(),db)                      # for CRUD helpers using auth

db.define_table('author',
        Field('full_name', 'string', length=100),
        Field('current_position', requires=IS_IN_SET(['Editor', 'Reporter', 'Teacher', 'Admin'])),
        Field('avatar', 'upload', autodelete=True))

db.define_table('page',
        Field('name', 'string', length=25),
        Field('description', 'text'),
        Field('type', requires=IS_IN_SET(['Single Column', 'Two Column', 'Three Column'])),
        Field('created', 'datetime', default=now, readable=True, writable=False))

db.define_table('article',
        Field('title', 'string', length=100),
        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('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 - %(author)s')),
        Field('placement', 'integer'))

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')]

{{extend 'layout.html'}} {{=page_form}}
{{try:}}{{=H2(message)}}{{except:}}{{=BEAUTIFY(response._vars)}}{{pass}}

Reply via email to