I recently lost some php code and I wanted to redo it in web2py instead of 
php so I am trying to convert from php/mysql to web2py.

In php, I pulled database data for 3 lists.  The 3 lists are 3 different 
kinds of ingredients.  

For each kind of ingredient - alcohol, mixer, garnish - I made a check box. 
 This check box will say "match using ingredient kind X"

Under each checkbox "match using ingredient kind X" there was a list of the 
options.  for example kind alcohol would have under it Vodka, rum, gin, 
etc.   Next to vodka, rum and gin would be another series of checkboxes.  

So in php I said, 
print <checkbox><checkbox label = "match alcohol">
for each item in list alcohol print <li><checkbox information><checkbox 
label></li>

repeat for mixer and garnish

Using a # symbol to represent a checkbox this would be what the screen 
looks like to the user:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# match alcohol        #match mixer             #match garnish
   #rum                         #coke                         #orange
   #vodka                      #tonic                         #lime
   #gin                          #orange juice              #lemon

SUBMIT BUTTON
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Note a user was permitted to say match mixer and then indicate that he 
wanted to exclude all mixers by not selecting one of the mixer ingredients 
 -- there was also some javascript logic managing checkbox status that 
shouldn't impact the question

Now after submit, back end would say something like 

if match alcohol, then add all checked alcohol.id to a set
if match mixer....same 
if match garnish...same

now write a db query with the sets that pulls a list of drinks that make an 
exact match to those ingredient

I ran into the issue of just passing the list to the view in order to 
generate an html form with check boxes and not having the data submit back 
to the controller.  In reading, I came to the belief that I should be 
creating a form in the controller and passing the form to the view instead. 
However, I have only seen static examples of creating a form in the 
controller and my attempts to dynamically generate this form from database 
data have resulted in various errors.

So I want to make the view above from data stored in the database and end 
with the data from the checkboxes stored into a python set (and not alter 
my database data). 

As such, I'm not sure what method I should be doing in order to solve this 
task in web2py. 

I hope that I have defined the problem in a clearer fashion this time.







On Monday, November 19, 2012 12:43:47 PM UTC-6, Amber Doctor wrote:
>
> I'm trying to determine the best way to code the following situation in 
> web2py.
>
> Currently I have a model that has this in it:
>
> db.define_table('ingredient',
>                 Field('ingredient_name', 'string', required=True),
>                 Field('kind_ref', 'reference kind', required=True, 
> requires=IS_IN_DB(db, 'kind.id','%(kind_name)s')),
>                 Field('type_ref', 'reference ingredient_type', 
> required=True, requires=IS_IN_DB(db, 'ingredient_type.id
> ','%(type_name)s')),
>                 Field('subtype_ref', 'reference ingredient_subtype', 
> required=True, requires=IS_IN_DB(db, 'ingredient_subtype.id
> ','%(subtype_name)s')),
>                 Field('brand_ref', 'reference ingredient_brand', 
> required=True, requires=IS_IN_DB(db, 'ingredient_brand.id
> ','%(brand_name)s')),
>                 Field('is_approved', 'boolean', default=True),
>                 Field('for_match', 'boolean', default=True),
>                 Field('ingredient_so', 'integer', default=50),
>                 format='%(ingredient_name)s'
>                 )
>
> db.define_table('drink_recipe_ingredients',
>                 Field('drink_recipe_ref', 'reference drink_recipe', 
> requires=IS_IN_DB(db, 'drink_recipe.id','%(drink_recipe_name)s')),
>                 Field('ingredient_ref', 'reference ingredient', 
> requires=IS_IN_DB(db, 'ingredient.id','%(ingredient_name)s')),
>                 Field('quantity'),
>                 Field('unit_ref', 'reference unit', requires=IS_IN_DB(db, '
> unit.id','%(unit_of_measure)s')),
>                 Field('is_approved', 'boolean', default=True),
>                 Field('drink_recipe_ingredients_so', 'integer', default=50)
>                 )
>
>
> from a pseudo use case perspective what I want to do is:
> 1) back end grab 3 sets of data (one for kind, 1,2,3) kinda like: 
>  alcohols = db((db.ingredient.kind_ref=='1') & 
> (db.ingredient.for_match==True) & 
> (db.ingredient.is_approved==True)).select()
> 2) front end display a check box that indicates that you are or are not 
> including information from those three sets of information - "category 
> selector"
> 3) display those three lists of items with check boxes next to each item 
> in the list
> 4) let the user select the check boxes and submit
> 5) in the back end - use the "category selector" and the checked items in 
> each category to create another query that pulls information from the 
> drink_recipe_ingredients table
>
> no data gathered is stored in the database.  more than one user can be 
> executing this behavior at the same time.
>
> Any advice on the best way to this would be great.
>

-- 



Reply via email to