On 9/8/06, Enrico Morelli <[EMAIL PROTECTED]> wrote:
> I offer you an italian pizza for another suggestion. Please, you are
> free to tell me if I disturb you.
Thank you, I do like pizzas :) -- Don't worry, if I didn't have time
to help I wouldn't :)
> The administrator can insert the user that he wants in the input fields.
> Now, when the admin press Save button the program receive a
> dictionary (**kw) in the form:
> {'day' : ['user','user','','','user',......],
> 'day' : ['user','user','','','user',......],
> ..}
>
> Where day is 1 to how many days has the month, and the array for
> each day contains the values for the instruments (the username if there
> is an user or an empty string) in the instrument table order.
>
> I'm in trouble to save or update the plan table with the data coming
> from the form.
>
> At the first time I'd tried:
>
> for k,v in kw.items():
> for instr in self.instruments:
>
> newdata=self.mysession.query(PlanEntry).selectfirst(and_(self.plan.c.year==year,
> self.plan.c.month==month, self.plan.c.day==k,
> self.plan.c.instrument_id==instr.instrument_id))
Isn't there something missing here? I don't see any use of "v" for example.
If I'm understanding correctly what you want to do, something like this:
instruments = self.mysession.query(Instrument).select()
for day,nameslist in kw.items():
for name, instr in zip(nameslist, instruments):
# First see if the instrument is already planned
# this leaves pe = None if it wasn't
pe = self.mysession.query(PlanEntry).get_by(
year=year, month=month, day=day,
instrument_id=instr.instrument_id)
if pe is None and name = '':
continue # nothing to do
elif pe is None:
# since name != '' - create a new entry
pe = PlanEntry()
pe.year, pe.month, pe.day = year, month, day
pe.instrument = instr
pe.data = name
self.mysession.save(pe)
elif name == None:
# Here pe is not None (existing plan) but name is ''
# so we need to remove the entry
self.mysession.delete(pe)
else:
# existing entry and name != '', update the entry
pe.data = name
Arnar
> to associate to each newdata the new entries and save its.
> But I think that this is a bad approach. In your opinion there are some
> other ways to do this?
>
> Thanks again for your help.
> --
> -------------------------------------------------------------------
> (o_
> (o_ //\ Coltivate Linux che tanto Windows si pianta da solo.
> (/)_ V_/_
> +------------------------------------------------------------------+
> | ENRICO MORELLI | email: [EMAIL PROTECTED] |
> | * * * * | phone: +39 055 4574269 |
> | University of Florence | fax : +39 055 4574253 |
> | CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY |
> +------------------------------------------------------------------+
>
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users