Perfect, the .list() is the answer.

With DynamoDB call:

adminobject = admintable.query(
>       Account__eq = 'admins',
>       Stamp__gt = int(yesterday),
>       limit=10
>     )
> adminlist=list()
> for x in adminlistobject:
>     adminlist.append(x)
>
> return render.blacklist(adminlist)



On Sat, Oct 5, 2013 at 8:17 AM, Jim Gregory <[email protected]> wrote:

> I think the problem is the loop with the console print statement.  To save
> memory when querying a database, web.py returns an iterator that can be
> used only once.  Once you iterate over all the results, it is empty:
>
> >>> import web
> >>> from models.databases import db
> >>> x = db.query('SELECT * FROM sales_order WHERE order_date > 2013-08-15
> LIMIT 5')
> 0.03 (3): SELECT * FROM sales_order WHERE order_date > 2013-08-15 LIMIT 5
> >>> for i in x:
> >>>     print i.id
> >>>
> 20025
> 20026
> 20027
> 20028
> 20029
> >>> for i in x:
> >>>     print i.id
> >>>
> (nothing)
>
> Looping through the results prior to calling the template consumes them.
> When you call the template, the results are empty
>
> To solve your problem, you can either remove the loop or retrieve your
> results as a list.  Doing the latter option will allow you to retrieve your
> data multiple times:
>
> >>> x = db.query('SELECT * FROM sales_order WHERE order_date > 2013-08-15
> LIMIT 5').list()    # <-- Note the '.list()'
> 0.03 (3): SELECT * FROM sales_order WHERE order_date > 2013-08-15 LIMIT 5
> >>> for i in x:
> >>>     print i.id
> >>>
> 20025
> 20026
> 20027
> 20028
> 20029
> >>> for i in x:
> >>>     print i.id
> >>>
> 20025
> 20026
> 20027
> 20028
> 20029
>
> Let me know if this works.
>
> -Jim
>
>
>
> On Friday, October 4, 2013 3:46:53 PM UTC-5, Vasiliy Boulytchev wrote:
>
>> Jim, I assure you admin_list is fine...  I can loop through it after
>> creation and print to console for debug.  In any case, here is how im
>> making it (DynamoDB):
>>
>>
>>     admins = Table('admins')
>>     # Query
>>     admin_list = admins(
>>       Account__eq = 'admins',
>>       Stamp__gt = int(yesterday),
>>       limit=10
>>     )
>>
>> This gives me the output
>>    for x in admin_list:
>>       print x['Email'], x['Date']
>>
>> So, its definitely something with the templates.  The method above is
>> proven to work on other portions of the site.  So its not a new concept.
>>
>> Thanks!
>>
>>
>> On Fri, Oct 4, 2013 at 10:31 AM, Jim Gregory <[email protected]> wrote:
>>
>>> How is admin_list created?  Could you show your code?
>>>
>>> -Jim
>>>
>>>
>>> On Friday, October 4, 2013 9:21:18 AM UTC-5, Vasiliy Boulytchev wrote:
>>>
>>>> Jim,
>>>>   Taking the $var x:1 out did not solve this.  Same behavior, no
>>>> change.  Any other ideas why this is so?
>>>>
>>>>
>>>> On Fri, Oct 4, 2013 at 8:34 AM, Jim Gregory <[email protected]> wrote:
>>>>
>>>>> I *think* its because you are assigning x = 1 at the top of the
>>>>> template, which causes your for loop to fail because '1' is not in
>>>>> admin_list.
>>>>>
>>>>> - Jim
>>>>>
>>>>>
>>>>> On Thursday, October 3, 2013 12:53:22 PM UTC-5, Vasiliy Boulytchev
>>>>> wrote:
>>>>>>
>>>>>>  Gents, for whatever reason, I am not seeing templates rendering the
>>>>>> passed-in dictionary. This is working properly on another page of mine, 
>>>>>> and
>>>>>> the output is correct in console. What is the problem?
>>>>>>
>>>>>> My Python Class:
>>>>>>
>>>>>> class Admins:
>>>>>>   def GET(self):
>>>>>>     for x in admin_list:
>>>>>>       print x['Email'], x['Date']
>>>>>>     return render.adminlist(admin_list = admin_list)
>>>>>>
>>>>>> (console output)
>>>>>>
>>>>>> adminlist.html
>>>>>>
>>>>>> $def with (admin_list)
>>>>>> $var title: Admin List.
>>>>>> $var x: 1
>>>>>>
>>>>>> $for x in admin_list:
>>>>>>    <h2> $x['Email'] </h2></h2>
>>>>>>
>>>>>> Output is empty :( Can someone please please please help? Thanks!
>>>>>> http://stackoverflow.com/**quest****ions/19165518/web-py-not-**parsi*
>>>>>> ***ng-dictionary<http://stackoverflow.com/questions/19165518/web-py-not-parsing-dictionary>
>>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "web.py" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to webpy+un...@**googlegroups.com.
>>>>> To post to this group, send email to [email protected].
>>>>>
>>>>> Visit this group at 
>>>>> http://groups.google.com/**group**/webpy<http://groups.google.com/group/webpy>
>>>>> .
>>>>> For more options, visit 
>>>>> https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
>>>>> .
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Vasiliy Boulytchev
>>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "web.py" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to webpy+un...@**googlegroups.com.
>>> To post to this group, send email to [email protected].
>>> Visit this group at 
>>> http://groups.google.com/**group/webpy<http://groups.google.com/group/webpy>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>
>>
>>
>> --
>> Vasiliy Boulytchev
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/webpy.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Vasiliy Boulytchev

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to