[web2py] Re: Issue with defaultdict(list)

2018-03-16 Thread Drew Howell
After taking a break and working on another section, I finally found what 
was causing the issue. There was, indeed, an error elsewhere within that 
controller, which was causing me all the headache. I appreciate your guys' 
help! Thanks.

On Sunday, March 11, 2018 at 11:14:27 PM UTC-4, Drew Howell wrote:
>
> I seem to be having issues getting defaultdict to work within Web2Py. I am 
> using Web2Py version 2.16.1 (Python 2.7.11).
>
> Here is the code in my controller:
> from collections import defaultdict
> g = defaultdict(list)
> g['someKey'].append('someValue')
>
> Here is the error I'm getting:
>
> File "D:/web2py/applications/fpr/controllers/students.py" 
> <http://127.0.0.1:8000/admin/default/edit/fpr/controllers/students.py>, line 
> 14, in view
>  g['someKey'].append('someValue')
> AttributeError: 'dict' object has no attribute 'append'
>
> If I do the same thing in the Python Interpreter, I don't seem to get the 
> issue.
>
> >>> from collections import defaultdict
> >>> g = defaultdict(list)
> >>> g['k'].append('v')
> >>> print g['k']
> ['v']
>
> Am I implementing this wrong or is there some sort of issue with using 
> defaultdict(list) in Web2Py?
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.


[web2py] Re: Issue with defaultdict(list)

2018-03-12 Thread Drew Howell
I think I've narrowed it down to having an error somewhere in my 'students' 
controller.


   1. If I remove all other functions within that controller, it works.
   2. If I create a new controller and only have that function, it works.
   3. If I put the same exact code in another existing controller, it works.
   
I will have do some more testing to figure out where my actual problem 
lies.Will report back with any results.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.


[web2py] Re: Issue with defaultdict(list)

2018-03-12 Thread Drew Howell
I am running from source, but still seem to have the issue.

On Monday, March 12, 2018 at 1:55:51 AM UTC-4, Val K wrote:
>
> Hi! 
> If you're Windows user  it's requires to run web2py from source (not 
> web2py.exe) to get modules that are installed on your machine



I was doing some testing and it seems to work perfectly fine when I run it 
from default.py. However, any time I try to run it from the controller I 
need it in, it doesn't work. I even created the "test" function that worked 
for you, and I still get the "AttributeError: 'dict' object has no 
attribute 'append'". This one has really got me scratching my head. 

On Monday, March 12, 2018 at 7:14:59 AM UTC-4, Leonel Câmara wrote:
>
> This controller worked fine for me:
>
> def test():
> from collections import defaultdict
> g = defaultdict(list)
> g['somekey'].append('somevalue')
> return response.json(g)
>
>
>
> You probably have a bug in your view. You can show us the code if you want.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.


[web2py] Issue with defaultdict(list)

2018-03-11 Thread Drew Howell
I seem to be having issues getting defaultdict to work within Web2Py. I am 
using Web2Py version 2.16.1 (Python 2.7.11).

Here is the code in my controller:
from collections import defaultdict
g = defaultdict(list)
g['someKey'].append('someValue')

Here is the error I'm getting:

File "D:/web2py/applications/fpr/controllers/students.py" 
, line 
14, in view
 g['someKey'].append('someValue')
AttributeError: 'dict' object has no attribute 'append'

If I do the same thing in the Python Interpreter, I don't seem to get the issue.

>>> from collections import defaultdict
>>> g = defaultdict(list)
>>> g['k'].append('v')
>>> print g['k']
['v']

Am I implementing this wrong or is there some sort of issue with using 
defaultdict(list) in Web2Py?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.


[web2py] Re: Trouble Creating Update Form

2014-08-11 Thread Drew Howell
I seem to have a problem there. It returns None. 

However, I think I may have figured out a solution. I've managed to update 
the current day 'rating' & 'complete' fields and also the 'complete' field 
of the next day (making it current). Let me know if you see any problems 
with the way I ended up doing this...  Here is the code:

*Controller:*
def workouts():

r = db(db.workouts.complete == 1).select().first()  #select 
current day
form = SQLFORM(db.workouts, r, showid=False).process()  #create 
form to update 'rating'


if form.accepted:
r2 = db(db.workouts.complete == 2).select().first()  #select 
next day
r.update_record(complete=0)  #update 
current day
r2.update_record(complete=1) #update 
next day
response.flash = 'record updated'
elif form.errors:
   response.flash = 'form has errors'

rows = db(db.workouts).select()

return locals()

As far as I can tell it seems to work how I want it to. You've been more 
than helpful, Massimo. Thanks, again!



On Monday, August 11, 2014 12:10:59 PM UTC-4, Massimo Di Pierro wrote:
>
> Try print/log the value of r in your code. Perhaps do a {{=r}} and see if 
> there record you are trying to edit is there.
>
> On Sunday, 10 August 2014 15:57:02 UTC-5, Drew Howell wrote:
>>
>> It's still creating a new record rather than updating. So I've still got 
>> something wrong. I need to look over the code and see if I can find 
>> anything that sticks out.
>>
>> On Sunday, August 10, 2014 4:07:57 PM UTC-4, Massimo Di Pierro wrote:
>>>
>>> I agree that you only seem to need one form. If this is the case there 
>>> should not be problems. Can you confirm?
>>>
>>> Massimo
>>>
>>> On Sunday, 10 August 2014 12:58:06 UTC-5, Drew Howell wrote:
>>>>
>>>> The purpose of the app/page is to track progress of a workout routine. 
>>>> It is a 5 week / 35 day schedule. I have all the "static" information 
>>>> stored in the table (Day, Week, Workout Name), but there are 2 other 
>>>> fields 
>>>> in the table that would need to be updated: "rating" which is where you 
>>>> rate your performance (1-4) entered via radio buttons, and "completed" 
>>>> which can be either 0, 1, or 2 (0=complete, 1=current, 2=locked) and is 
>>>> automatically changed to 0 when the form is submitted.
>>>>
>>>> I am generating the page by iterating through the records in the table 
>>>> and displaying them (see here for example 
>>>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>).
>>>>  
>>>> I realize now that I really only need 1 form, which is for the current 
>>>> day. 
>>>> The user will select a radio button and click submit. It should then 
>>>> update 
>>>> the "rating" field as well as the "completed" field. After the form is 
>>>> submitted the page is generated again, but the next day will be the 
>>>> "current" day with the form. I apologize if that's confusing, but the best 
>>>> way to understand it is looking at the example 
>>>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>
>>>> .
>>>>
>>>> This is what I'm doing in my workouts.html View:
>>>>
>>>> {{for row in rows:}}
>>>> {{if row.complete == 0:}}
>>>> // completed day layout
>>>> {{elif row.complete == 1:}}
>>>> // current day layout
>>>> {{=form}}
>>>> {{else:}}
>>>> ///locked day layout
>>>> {{pass}}
>>>> {{pass}}
>>>>
>>>>
>>>> On Sunday, August 10, 2014 1:27:17 PM UTC-4, Massimo Di Pierro wrote:
>>>>>
>>>>> That's it then. You cannot have multiple forms on the same type on one 
>>>>> page unless they refer to different tables. There are other ways but it 
>>>>> really depends on what you are trying to do. Can you explain in words 
>>>>> what 
>>>>> is the page supposed to do.
>>>>>
>>>>>
>>>>> On Sunday, 10 August 2014 11:11:05 UTC-5, Drew Howell wrote:
>>>>>>
>>>>>> I made the changes and switched to using {{=form}}, but It's still 
>>>>>&g

[web2py] Re: Trouble Creating Update Form

2014-08-10 Thread Drew Howell
It's still creating a new record rather than updating. So I've still got 
something wrong. I need to look over the code and see if I can find 
anything that sticks out.

On Sunday, August 10, 2014 4:07:57 PM UTC-4, Massimo Di Pierro wrote:
>
> I agree that you only seem to need one form. If this is the case there 
> should not be problems. Can you confirm?
>
> Massimo
>
> On Sunday, 10 August 2014 12:58:06 UTC-5, Drew Howell wrote:
>>
>> The purpose of the app/page is to track progress of a workout routine. It 
>> is a 5 week / 35 day schedule. I have all the "static" information stored 
>> in the table (Day, Week, Workout Name), but there are 2 other fields in the 
>> table that would need to be updated: "rating" which is where you rate your 
>> performance (1-4) entered via radio buttons, and "completed" which can be 
>> either 0, 1, or 2 (0=complete, 1=current, 2=locked) and is automatically 
>> changed to 0 when the form is submitted.
>>
>> I am generating the page by iterating through the records in the table 
>> and displaying them (see here for example 
>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>).
>>  
>> I realize now that I really only need 1 form, which is for the current day. 
>> The user will select a radio button and click submit. It should then update 
>> the "rating" field as well as the "completed" field. After the form is 
>> submitted the page is generated again, but the next day will be the 
>> "current" day with the form. I apologize if that's confusing, but the best 
>> way to understand it is looking at the example 
>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>
>> .
>>
>> This is what I'm doing in my workouts.html View:
>>
>> {{for row in rows:}}
>> {{if row.complete == 0:}}
>> // completed day layout
>> {{elif row.complete == 1:}}
>> // current day layout
>> {{=form}}
>> {{else:}}
>> ///locked day layout
>> {{pass}}
>> {{pass}}
>>
>>
>> On Sunday, August 10, 2014 1:27:17 PM UTC-4, Massimo Di Pierro wrote:
>>>
>>> That's it then. You cannot have multiple forms on the same type on one 
>>> page unless they refer to different tables. There are other ways but it 
>>> really depends on what you are trying to do. Can you explain in words what 
>>> is the page supposed to do.
>>>
>>>
>>> On Sunday, 10 August 2014 11:11:05 UTC-5, Drew Howell wrote:
>>>>
>>>> I made the changes and switched to using {{=form}}, but It's still 
>>>> creating a new record. I just realized I didn't post a part of the view 
>>>> that might be causing the issue. I have multiple forms on a single page.
>>>>
>>>> ...
>>>>
>>>> {{=for row in rows:}}
>>>>
>>>> {{=form}}
>>>>
>>>> {{pass}}
>>>>
>>>> ...
>>>>
>>>> Could that be causing the issue? I went ahead and uploaded what I have 
>>>> to Python Anywhere to help illustrate what I'm trying to do. You can check 
>>>> it out here 
>>>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts> 
>>>> (the 
>>>> layout is slightly broken because of the vertical radio buttons, but that 
>>>> will be fixed next).
>>>>
>>>>
>>>>
>>>>
>>>> On Saturday, August 9, 2014 10:33:02 PM UTC-4, Massimo Di Pierro wrote:
>>>>>
>>>>> One problem is that you want to select after you process the form:
>>>>>
>>>>> def workouts():
>>>>> r = db.workouts(request.args(0))
>>>>> form = SQLFORM(db.workouts, r).process()
>>>>>
>>>>> if form.accepted:
>>>>>response.flash = 'form accepted'
>>>>> elif form.errors:
>>>>>response.flash = 'form has errors'
>>>>>
>>>>> rows = db(db.workouts).select()
>>>>> return locals()
>>>>>
>>>>> Also instead of using a custom form (unless you really need one), I 
>>>>> suggest you do {{=form}} in view and 
>>>>>
>>>>> make the fields that you do not need in the form Field(..., 
>>>>> readable=False, writable=False)
>>>>

[web2py] Re: Trouble Creating Update Form

2014-08-10 Thread Drew Howell
The purpose of the app/page is to track progress of a workout routine. It 
is a 5 week / 35 day schedule. I have all the "static" information stored 
in the table (Day, Week, Workout Name), but there are 2 other fields in the 
table that would need to be updated: "rating" which is where you rate your 
performance (1-4) entered via radio buttons, and "completed" which can be 
either 0, 1, or 2 (0=complete, 1=current, 2=locked) and is automatically 
changed to 0 when the form is submitted.

I am generating the page by iterating through the records in the table and 
displaying them (see here for example 
<https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>). 
I realize now that I really only need 1 form, which is for the current day. 
The user will select a radio button and click submit. It should then update 
the "rating" field as well as the "completed" field. After the form is 
submitted the page is generated again, but the next day will be the 
"current" day with the form. I apologize if that's confusing, but the best 
way to understand it is looking at the example 
<https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts.html>
.

This is what I'm doing in my workouts.html View:

{{for row in rows:}}
{{if row.complete == 0:}}
// completed day layout
{{elif row.complete == 1:}}
// current day layout
{{=form}}
{{else:}}
///locked day layout
{{pass}}
{{pass}}


On Sunday, August 10, 2014 1:27:17 PM UTC-4, Massimo Di Pierro wrote:
>
> That's it then. You cannot have multiple forms on the same type on one 
> page unless they refer to different tables. There are other ways but it 
> really depends on what you are trying to do. Can you explain in words what 
> is the page supposed to do.
>
>
> On Sunday, 10 August 2014 11:11:05 UTC-5, Drew Howell wrote:
>>
>> I made the changes and switched to using {{=form}}, but It's still 
>> creating a new record. I just realized I didn't post a part of the view 
>> that might be causing the issue. I have multiple forms on a single page.
>>
>> ...
>>
>> {{=for row in rows:}}
>>
>> {{=form}}
>>
>> {{pass}}
>>
>> ...
>>
>> Could that be causing the issue? I went ahead and uploaded what I have to 
>> Python Anywhere to help illustrate what I'm trying to do. You can check 
>> it out here 
>> <https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts> (the 
>> layout is slightly broken because of the vertical radio buttons, but that 
>> will be fixed next).
>>
>>
>>
>>
>> On Saturday, August 9, 2014 10:33:02 PM UTC-4, Massimo Di Pierro wrote:
>>>
>>> One problem is that you want to select after you process the form:
>>>
>>> def workouts():
>>> r = db.workouts(request.args(0))
>>> form = SQLFORM(db.workouts, r).process()
>>>
>>> if form.accepted:
>>>response.flash = 'form accepted'
>>> elif form.errors:
>>>response.flash = 'form has errors'
>>>
>>> rows = db(db.workouts).select()
>>> return locals()
>>>
>>> Also instead of using a custom form (unless you really need one), I 
>>> suggest you do {{=form}} in view and 
>>>
>>> make the fields that you do not need in the form Field(..., 
>>> readable=False, writable=False)
>>>
>>> On Saturday, 9 August 2014 20:01:51 UTC-5, Drew Howell wrote:
>>>>
>>>> I'm new to Web2Py, so I am creating a (what I thought was a) simple app 
>>>> that tracks progress of a workout routine. I have a database (db.workouts) 
>>>> that has information such as Workout Name, Rating, Completed, etc. I have 
>>>> 2 
>>>> fields(rating, completed) I would like to update via a form. I have tried 
>>>> a 
>>>> couple different methods, but can't seem to get anything to work 
>>>> correctly. 
>>>> The other fields are already entered in the table and should not be 
>>>> changed.
>>>>
>>>> "Rating" should be updated by a set of radio buttons and "Completed" 
>>>> should be set to 0 when the form is submitted (0=complete, 1=current, 
>>>> 2=locked). I have created the form, but have done something wrong because, 
>>>> when it is submitted, a new record is created rather than updating the 
>>>> existing one. 
>>>>
>>>> *Here is my code:*
>>>>
>>>> *Model

[web2py] Re: Trouble Creating Update Form

2014-08-10 Thread Drew Howell
I made the changes and switched to using {{=form}}, but It's still creating 
a new record. I just realized I didn't post a part of the view that might 
be causing the issue. I have multiple forms on a single page.

...

{{=for row in rows:}}

{{=form}}

{{pass}}

...

Could that be causing the issue? I went ahead and uploaded what I have to 
Python Anywhere to help illustrate what I'm trying to do. You can check it 
out here 
<https://drewhowell.pythonanywhere.com/TwoFiveTracker/default/workouts> (the 
layout is slightly broken because of the vertical radio buttons, but that 
will be fixed next).




On Saturday, August 9, 2014 10:33:02 PM UTC-4, Massimo Di Pierro wrote:
>
> One problem is that you want to select after you process the form:
>
> def workouts():
> r = db.workouts(request.args(0))
> form = SQLFORM(db.workouts, r).process()
>
> if form.accepted:
>response.flash = 'form accepted'
> elif form.errors:
>response.flash = 'form has errors'
>
> rows = db(db.workouts).select()
> return locals()
>
> Also instead of using a custom form (unless you really need one), I 
> suggest you do {{=form}} in view and 
>
> make the fields that you do not need in the form Field(..., 
> readable=False, writable=False)
>
> On Saturday, 9 August 2014 20:01:51 UTC-5, Drew Howell wrote:
>>
>> I'm new to Web2Py, so I am creating a (what I thought was a) simple app 
>> that tracks progress of a workout routine. I have a database (db.workouts) 
>> that has information such as Workout Name, Rating, Completed, etc. I have 2 
>> fields(rating, completed) I would like to update via a form. I have tried a 
>> couple different methods, but can't seem to get anything to work correctly. 
>> The other fields are already entered in the table and should not be changed.
>>
>> "Rating" should be updated by a set of radio buttons and "Completed" 
>> should be set to 0 when the form is submitted (0=complete, 1=current, 
>> 2=locked). I have created the form, but have done something wrong because, 
>> when it is submitted, a new record is created rather than updating the 
>> existing one. 
>>
>> *Here is my code:*
>>
>> *Model:*
>>
>> db.define_table('workouts',
>> Field('stage'),
>> Field('w', type="integer"),
>> Field('workout'),
>> Field('complete', type="integer"),
>> Field('d', type="integer"),
>> Field('rating', requires=IS_IN_SET([1, 2, 3, 4 ]), 
>> widget=SQLFORM.widgets.radio.widget),
>> auth.signature
>> )
>>
>> *Controller:*
>>
>> def workouts():
>> rows = db(db.workouts).select()
>> 
>> r = db.workouts(request.args(0))
>> form = SQLFORM(db.workouts, r)
>>
>> if form.process().accepted:
>>response.flash = 'form accepted'
>> elif form.errors:
>>response.flash = 'form has errors'
>>
>> return locals()
>>
>> *View:*
>>
>> ...
>>
>> {{=form.custom.begin}}
>> {{=form.custom.widget.rating}}
>> {{=form.custom.submit}} 
>> {{=form.custom.end}}
>>
>> ...
>>
>>
>> As I mentioned earlier, I am new and I may be going about this completely 
>> the wrong way. So any help would be greatly appreciated. I can provide more 
>> information if needed. Thanks.
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.


[web2py] Trouble Creating Update Form

2014-08-09 Thread Drew Howell
I'm new to Web2Py, so I am creating a (what I thought was a) simple app 
that tracks progress of a workout routine. I have a database (db.workouts) 
that has information such as Workout Name, Rating, Completed, etc. I have 2 
fields(rating, completed) I would like to update via a form. I have tried a 
couple different methods, but can't seem to get anything to work correctly. 
The other fields are already entered in the table and should not be changed.

"Rating" should be updated by a set of radio buttons and "Completed" should 
be set to 0 when the form is submitted (0=complete, 1=current, 2=locked). I 
have created the form, but have done something wrong because, when it is 
submitted, a new record is created rather than updating the existing one. 

*Here is my code:*

*Model:*

db.define_table('workouts',
Field('stage'),
Field('w', type="integer"),
Field('workout'),
Field('complete', type="integer"),
Field('d', type="integer"),
Field('rating', requires=IS_IN_SET([1, 2, 3, 4 ]), 
widget=SQLFORM.widgets.radio.widget),
auth.signature
)

*Controller:*

def workouts():
rows = db(db.workouts).select()

r = db.workouts(request.args(0))
form = SQLFORM(db.workouts, r)

if form.process().accepted:
   response.flash = 'form accepted'
elif form.errors:
   response.flash = 'form has errors'

return locals()

*View:*

...

{{=form.custom.begin}}
{{=form.custom.widget.rating}}
{{=form.custom.submit}} 
{{=form.custom.end}}

...


As I mentioned earlier, I am new and I may be going about this completely 
the wrong way. So any help would be greatly appreciated. I can provide more 
information if needed. Thanks.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.