It works!

Thank you very much!

On 4 nov, 22:03, howesc <how...@umich.edu> wrote:
> your problem is where you put the query in the IS_IN_DB.  try
> modifying to put the query in the first spot.  something like:
>
>                          requires=IS_IN_DB(db((db.file_asset.type ==
> db.file_asset_type.id) &
>
> (db.file_asset_type.name=='Album Art')),
>                                            db.file_asset.id, '%
> (name)s')),
>
> (no that is not from your example, but a clipping from one of my
> models)
>
> cfh
>
> On Nov 4, 11:16 am, demetrio <dgzabal...@gmail.com> wrote:
>
> > Hi everyone!
>
> > I'm doing an app with fullcalendar (http://arshaw.com/fullcalendar/)
> > and now i'm with all the events and calendar cruds.
>
> > Its time to add some logic to the crud.create() of the events, an only
> > let the user to add events in his/her calendars, not in ALL the
> > calendars.
>
> > I have this:
>
> > db.define_table('calendars',
> >     Field('name', 'string', required=True, notnull=True),
> >     #Field('project_id', 'reference', default=None, required=True),
> >     format='%(name)s')
>
> > db.define_table('events',
> >     Field('title', 'string', required=True, notnull=True,
> > label=T('Title')),
> >     Field('place', 'string', label=T('Place')),
> >     Field('description', 'text', label=T('Description')),
> >     Field('init_date', 'datetime', required=True, label=T('Init
> > date')),
> >     Field('end_date', 'datetime', required=True, label=T('End date')),
> >     Field('calendar_id', 'reference calendars', label=T('Calendar')),
> >     Field('all_day', 'boolean', default=False, required=True,
> > label=T('All day')),
> >     format='%(title)s'
> >     )
>
> > db.define_table('user_calendars',
> >     Field('calendar', 'reference calendars', required=True,
> > notnull=True, label=T('Calendar')),
> >     Field('color', 'string', default="blue", required=True,
> > label=T('Color')),
> >     Field('fullcalendar_class', 'string', required=True,
> > writable=False, readable=False),
> >     Field('permissions', 'string', required=True,
> > label=T('Permissions'), requires=IS_IN_SET(['r', 'rw', 'owner'],
> > zero=None)),
> >     Field('user_id', 'reference auth_user', required=True,
> > notnull=True, label=T('User')),
> >     format='')
>
> > With that model defined, in the events crud, will appear ALL the
> > calendars, so i have tried to do something like this:
>
> > def create():
> >     query = ((db.user_calendars.calendar == db.calendars.id)  &
> > (db.user_calendars.user_id == auth.user.id)  &
> > ((db.user_calendars.permissions =="owner") |
> > (db.user_calendars.permissions=="rw")))
> >     db.events.calendar_id.requires =IS_IN_DB(db, query, zero=None )
> >     return dict(form=crud.create(db.events))
>
> > And i found that the IS_IN_DB doesn't admit SQL queries xD
>
> > the query is something like: "give me all my calendars and the ones
> > where i can write"
>
> > Is there any "quick" and optimal solution to make all of this in the
> > controller? or i have to customize the crud form in the view?.
>
> > Thanks in advance!
>
>

Reply via email to