On Aug21, 7:21am, Marco <saf...@gmail.com> wrote:
> Hello everyone.
>
> I am working with a controller for ratings on an item. The item
> details come from a legacy database, and the ratings are stored in a
> separate database. In the ratings database, alongside the ordinal
> ratings I store the identifier of the item it refers to. I am using
> the CRUD module to automagically generate the form I require. However,
> I would like one particular field, the 'item_id' field, to be pre-
> filled, invisible to and non-editable by the user. The item_id is the
> first and only parameter to the ratings controller.
>
> My current approach is to set the Field properties readable and
> writable to False, and then modifying db.ratings.item_id.default with
> each invocation to the controller. Is this a safe practice, or is it
> possible that in a use case with two concurrent users, one user may
> see the changes caused by the other user?
>
> My next question is, is there a better way to do this? It almost feels
> like there should be a hidden widget of some sort, but how would I
> pass it the required value, since it varies according to the
> parameters given to the controller? I am very new to this, so I may
> have made some simple beginner mistakes and am very open to any design
> suggestions.
>
> I include a sketch of my controller below for reference.
>
> Thanks in advance.
>
> Cheers
> Marco
>
> @auth.requires_login()
> def rate():
>   item_id = request.args(0)
>   target = db.item[item_id]
>
>   # target not valid, redirect to summary
>   if not target: redirect(URL(r=request, f='summary'))
>
>   ratings = db.ratings
>   ratings.item_id.default = target_id
>   prev = db((ratings.annotator_id==auth.user.id) &
> (ratings.item_id==item_id)).select()
>   if len(prev) == 0:
>     form = crud.create(ratings, next=URL(r=request,f='summary'))
>   else:
>     form = crud.update(uq, prev[0], next=URL(r=request,f='summary'),
> deletable=False)
>
>   return dict(form=form, target=target)


It is safe to modify db.yourtable.yourfield.default to different value
with each invocation to the controller.  In web2py each definition are
excuted on the fly. It is an unusual design but really make things
funny.

Is there a better way to do this?  I don't know one yet.

Regards,
Iceberg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to