wow!! many many thanks.. :)

On Tue, Jul 2, 2013 at 10:15 AM, Anthony <abasta...@gmail.com> wrote:

> You left out some critical code from the original question -- your
> Javascript sends each post request twice:
>
>     function send_data(id){
>         $.post("{{=URL('contest','flip_contest_status')}}", {id: id} );
>         $.post("{{=URL('contest','flip_contest_status')}}", {id: id} )
>             .done(function(data) {
>                 window.location.replace("{{URL('contest','configure')}}");
>             });
>     }
>
> If you delete that first $.post line, everything seems to work fine. One
> other problem, though:
>
> def flip_contest_status():
>     id = request.post_vars.
> id
>     row = db(db.contest.id == 13).select(db.contest.running, db.contest.
> name).first()
>
> You probably forgot to revert after debugging, but above you have
> hard-coded and id of 13 into the query.
>
> Anthony
>
> On Monday, July 1, 2013 10:55:17 PM UTC-4, Ahmad Faiyaz wrote:
>
>> here is the database definition:
>>
>> db.define_table('contest', Field('name', length=128 ),
>> Field('contest_host', length=128,), Field('duration', 'time' ),
>> Field('time_passed','time', default = 0), Field('rank_frozen','time',
>> default = 0), Field('running',length= 10, readable=False, default = "no"),
>> Field('lang'))
>>
>> db.contest.name.requires = 
>> [IS_NOT_IN_DB(db,db.contest.**name<http://db.contest.name>),
>> IS_NOT_EMPTY()]
>> db.contest.contest_host.**requires = [IS_NOT_EMPTY()]
>> db.contest.duration.requires = [IS_NOT_EMPTY()]
>> db.contest.lang.requires=IS_**IN_SET(['C', 'C++', 'JAVA', 'Python'],
>> multiple=True)
>> db.contest.lang.widget = hmultiselect_widget
>>
>>
>> then here is my controller which will show the SQLFORM Grid:
>> @auth.requires_permission('**manage')
>> def configure():
>>     grid = SQLFORM.grid(db.contest,fields = [db.contest.id,
>> db.contest.name, db.contest.contest_host, db.contest.duration,
>> db.contest.time_passed , db.contest.rank_frozen],**create=False, links =
>> [contest_buttons] ,  details=False )
>>     return dict(grid = grid)
>>
>> Then here is my code which will flip the value of db.contest.running
>> def flip_contest_status():
>>     id = request.post_vars.id
>>     row = db(db.contest.id == id).select(db.contest.running,
>> db.contest.name).first()
>>     value = ""
>>     if row.running == 'no':
>>         value = 'yes'
>>         #session.flash = row.running
>>     elif row.running == 'yes':
>>         value = 'no'
>>         #session.flash = row.running
>>     else:
>>         abd = "sd"
>>     db(db.contest.id == id).update(running = value)
>>     session.flash = row.running
>>     return locals()
>>
>>
>> Here is my db.contest table:
>>
>> contest.id<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.id>
>> contest.name<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.name>
>> contest.contest_host<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.contest_host>
>> contest.duration<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.duration>
>> contest.time_passed<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.time_passed>
>> contest.rank_frozen<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.rank_frozen>
>> contest.running<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.running>
>> contest.lang<http://localhost:8000/SAI_BETA/appadmin/select/db?orderby=contest.lang>
>> 13 <http://localhost:8000/SAI_BETA/appadmin/update/db/contest/13> Testme
>> 07:33:5306:33:54 06:33:55no|C++| 
>> 14<http://localhost:8000/SAI_BETA/appadmin/update/db/contest/14>
>> faiyaz26 me06:34:2307:34:2206:34:25 no|C|
>>
>> I used session.flash to check what kind of value is fetching, and it is
>> showing *yes* for contest.id = 13 and 14
>>
>> If i update the value of db.contest.running for db.contest.id =13 to yes
>> from no, it shows *no* then
>>
>> what to do then ?
>>
>> You can download the whole w2p file from here:
>> https://dl.dropboxusercontent.**com/u/34972503/web2py.app.SAI_**BETA.w2p<https://dl.dropboxusercontent.com/u/34972503/web2py.app.SAI_BETA.w2p>
>>
>> username: administrator
>> pass: admin1234
>>
>> then go to contest/configure to check !! use start , stop button to
>> update the status.
>>
>> On Tue, Jul 2, 2013 at 8:40 AM, Anthony <abas...@gmail.com> wrote:
>>
>>> Can you show the code you are now using and describe the workflow of how
>>> the record gets updated and how you are then attempting to view the updated
>>> record?
>>>
>>> Anthony
>>>
>>> On Monday, July 1, 2013 8:37:32 PM UTC-4, Ahmad Faiyaz wrote:
>>>
>>>> weird things happening, when i check the db table with appadmin, it
>>>> shows for contest.running = yes [ updated the value with sqlform.grid ] ,
>>>> but when i fetch the row with DAL on app, it shows contest.running = no [
>>>> which is the default ]
>>>>
>>>> why ?
>>>>
>>>> On Tue, Jul 2, 2013 at 6:18 AM, Ahmad Faiyaz <faiy...@gmail.com> wrote:
>>>>
>>>>> thanks, but it sometimes work, sometimes doesn't !! what can be the
>>>>> problem !
>>>>>
>>>>> On Tue, Jul 2, 2013 at 5:34 AM, Alex <mrau...@gmail.com> wrote:
>>>>>
>>>>>> from the documentation:
>>>>>> update_record should not be confused with
>>>>>> >>> row.update(name='Curt')
>>>>>> because for a single row, the method update updates the row object
>>>>>> but not the database record, as in the case of update_record
>>>>>>
>>>>>> so you should use update_record instead. or even better:
>>>>>> db(db.contest.id == id ).update(running = value)
>>>>>>
>>>>>> which only results in one sql statement.
>>>>>>
>>>>>> Alex
>>>>>>
>>>>>> Am Dienstag, 2. Juli 2013 00:23:16 UTC+2 schrieb Ahmad Faiyaz:
>>>>>>
>>>>>>> Hello,
>>>>>>> i am trying to update a row on a db table, but it is not updating,
>>>>>>> what is the problem ?
>>>>>>>
>>>>>>> my db table definition:
>>>>>>> db.define_table('contest', Field('name', length=128 ),
>>>>>>> Field('contest_host', length=128,), Field('duration', 'time' ),
>>>>>>> Field('time_passed','time', default = 0), Field('rank_frozen','time',
>>>>>>> default = 0), Field('running',length= 10, readable=False, default = 
>>>>>>> "no"),
>>>>>>> Field('lang'))
>>>>>>>
>>>>>>> My update function:
>>>>>>>
>>>>>>> def flip_contest_status():
>>>>>>>     id = request.post_vars.id
>>>>>>>     row = db(db.contest.id == id ).select().first()
>>>>>>>     value = "no"
>>>>>>>     con =  row.running
>>>>>>>     if con is "no":
>>>>>>>         value = "yes"
>>>>>>>     db(db.contest.id == id ).select().first().update(**runn**ing =
>>>>>>> value)
>>>>>>>     session.flash = row.name + " mode changed to "+ value
>>>>>>>     return locals()
>>>>>>>
>>>>>>> it doesn't update my db row !!
>>>>>>>
>>>>>>> What to do ?
>>>>>>>
>>>>>>>  --
>>>>>>
>>>>>> ---
>>>>>> You received this message because you are subscribed to a topic in
>>>>>> the Google Groups "web2py-users" group.
>>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>>>>>> to**pic/web2py/1YuETESUji8/**unsubsc**ribe<https://groups.google.com/d/topic/web2py/1YuETESUji8/unsubscribe>
>>>>>> .
>>>>>>  To unsubscribe from this group and all its topics, send an email to
>>>>>> web2py+un...@**googlegroups.com.
>>>>>>
>>>>>> For more options, visit 
>>>>>> https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
>>>>>> .
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Regards,
>>>>> Ahmad Faiyaz
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Regards,
>>>> Ahmad Faiyaz
>>>>
>>>  --
>>>
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "web2py-users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>>> topic/web2py/1YuETESUji8/**unsubscribe<https://groups.google.com/d/topic/web2py/1YuETESUji8/unsubscribe>
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> web2py+un...@**googlegroups.com.
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>
>>
>>
>> --
>>
>> Regards,
>> Ahmad Faiyaz
>>
>  --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/1YuETESUji8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 

Regards,
Ahmad Faiyaz

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to