[web2py] Re: NameError: name 'category' is not defined (reddit clone application)

2016-08-22 Thread pbreit
The paging includes references to "category" except when viewing posts by 
author, there is no category.

A quick fix would be to skip the paging when listing by author:

{{if request.function!='list_posts_by_author':}}
{{if page>0:}}
{{=A('previous', _class='btn', _href=URL(args=(category.name, page-1)))}}
{{pass}}


{{if len(rows)>=10:}}
{{=A('next', _class='btn', _href=URL(args=(category.name, page+1)))}}
{{pass}}
{{pass}}

-- 
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: NameError: name 'category' is not defined (reddit clone application)

2016-08-22 Thread Dave S


On Monday, August 22, 2016 at 6:58:08 AM UTC-7, Annexx Xaar wrote:
>
> Hello sir i have tried all i could, still having errors in the reddit 
> clone application.
> everything works fine except when i 
> implemented  {{=author(user_id)}} under list_posts_by_votes.html
> the errors blows when i click on the author of a comment. it does not 
> dislay the author's name as it showed in the toturial video.
>  
>
>
>
>  here's it
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
>
> Traceback (most recent call last):
>   File "C:\Users\nsikan\Desktop\web2py\gluon\restricted.py", line 227, in 
> restricted
> exec ccode in environment
>   File 
> "C:\Users\nsikan\Desktop\web2py\applications\mydream\views\default/list_posts_by_votes.html",
>  line 117, in 
> NameError: name 'category' is not defined
>
>
Does the ticket show what it thinks is line 117?  list_posts_by_votes() has 
2 mentions of category, and it isn't obvious to me why either would result 
in this error, but focusing on the exact line may help.

/dps


-- 
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: NameError: name 'category' is not defined (reddit clone application)

2016-08-22 Thread Marlysson Silva
It's possible show the result of get_category function ? Or show errors in 
these point ?

Em segunda-feira, 22 de agosto de 2016 11:12:44 UTC-3, Annexx Xaar escreveu:
>
> Pls I am waiting for reply. pls anyone help?
>
>
>
>
>
>
>
> On Monday, August 22, 2016 at 2:58:08 PM UTC+1, Annexx Xaar wrote:
>>
>> Hello sir i have tried all i could, still having errors in the reddit 
>> clone application.
>> everything works fine except when i 
>> implemented  {{=author(user_id)}} under list_posts_by_votes.html
>> the errors blows when i click on the author of a comment. it does not 
>> dislay the author's name as it showed in the toturial video.
>>  
>>
>>
>>
>>  here's it
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>>
>> Traceback (most recent call last):
>>   File "C:\Users\nsikan\Desktop\web2py\gluon\restricted.py", line 227, in 
>> restricted
>> exec ccode in environment
>>   File 
>> "C:\Users\nsikan\Desktop\web2py\applications\mydream\views\default/list_posts_by_votes.html",
>>  line 117, in 
>> NameError: name 'category' is not defined
>>
>> here's deault.py
>> POSTS_PER_PAGE = 10
>> def get_category():
>> category_name = request.args(0)
>> category = db.category(name = category_name)
>> if not category:
>> session.flash = 'page has not been created'
>> redirect(URL('index'))
>> return category
>>
>> def index():
>> rows = db(db.category).select()
>> return locals()
>>
>> def create_post():
>> category = get_category()
>> db.post.category.default = category.id
>> form = SQLFORM(db.post).process(next='view_post/[id]')
>> return locals()
>>
>> def edit_post():
>> id = request.args(0, cast=int)
>> form = SQLFORM(db.post, id).process(next='view_post/[id]')
>> return locals()
>>
>> def list_posts_by_datetime():
>> response.view='default/list_posts_by_votes.html'
>> category = get_category()
>> page = request.args(1, cast=int, default=0)
>> start = page * POSTS_PER_PAGE
>> stop = start + POSTS_PER_PAGE
>> rows = 
>> db(db.post.category==category.id).select(orderby=~db.post.created_on, 
>> limitby=(start, stop))
>> return locals()
>> 
>> def list_posts_by_votes():
>> category = get_category()
>> page = request.args(1, cast=int, default=0)
>> start = page * POSTS_PER_PAGE
>> stop = start + POSTS_PER_PAGE
>> rows = db(db.post.category==category.id).select(orderby=~db.post.votes, 
>> limitby=(start, stop))
>> return locals()
>>
>> def list_posts_by_author():
>> response.view='default/list_posts_by_votes.html'
>> user_id = request.args(0, cast=int)
>> page = request.args(1, cast=int, default=0)
>> start = page * POSTS_PER_PAGE
>> stop = start + POSTS_PER_PAGE
>> rows = 
>> db(db.post.created_by==user_id).select(orderby=~db.post.created_on, 
>> limitby=(start, stop))
>> return locals()
>>
>> def view_post():
>> id = request.args(0, cast=int)
>> post = db.post(id) or redirect(URL('index'))
>> comments = db(db.comm.post==post.id
>> ).select(orderby=~db.comm.created_on)
>> ##TODO
>> return locals()
>>
>> def vote_callback():
>> id = request.args(0, cast=int)
>> direction = request.args(1)
>> ##TODO
>> return locals()
>>
>> def comm_vote_callback():
>> id = request.args(0, cast=int)
>> direction = request.args(1)
>> ##TODO
>> return locals()
>>
>>
>> here's lists_posts_by_votes.html
>> {{extend 'layout.html'}}
>>
>> {{if request.function=='list_posts_by_votes':}}
>> {{=category.name.title()}}
>> {{=A('sort by datetime', _class='btn', 
>> _href=URL('list_posts_by_datetime', args=category.name))}}
>> {{=A('post a new link', _class='btn btn-primary', 
>> _href=URL('create_post', args=category.name))}}
>>
>> {{elif request.function=='list_posts_by_datetime':}}
>> {{=category.name.title()}}
>> {{=A('sort by votes', _class='btn', _href=URL('list_posts_by_votes', args=
>> category.name))}}
>> {{=A('post a new link', _class='btn btn-primary', 
>> _href=URL('create_post', args=category.name))}}
>> {{else:}}
>> {{=author(user_id)}}
>> {{pass}}
>> 
>>
>> {{for post in rows:}}
>> 
>> 
>> {{=post.votes}} 
>>  {{ =A(post.title,_href=post.url) if post.url else 
>> post.title}}
>> {{=A('comments', _href=URL('view_post', args=
>> post.id))}}
>> 
>> 
>>
>> {{pass}}
>>
>> {{if page>0:}}
>> {{=A('previous', _class='btn', _href=URL(args=(category.name, page-1)))}}
>> {{pass}}
>>
>> {{if len(rows)>=10:}}
>> {{=A('next', _class='btn', _href=URL(args=(category.name, page+1)))}}
>> {{pass}}
>>
>>
>> here's db1.py
>> # -*- coding: utf-8 -*-
>> # -*- coding: utf-8 -*-
>> db.define_table('category', Field('name', requires=(IS_SLUG(), 
>> IS_LOWER(),IS_NOT_IN_DB(db, 'category.name'
>>
>> db.define_table('post',
>> Field('category', 'reference category', 
>> writable=False, readable=False),
>> Field('title', 'string', requires=IS_NOT_EMPTY()),
>> Field('url', 

[web2py] Re: NameError: name 'category' is not defined (reddit clone application)

2016-08-22 Thread Annexx Xaar
Pls I am waiting for reply. pls anyone help?







On Monday, August 22, 2016 at 2:58:08 PM UTC+1, Annexx Xaar wrote:
>
> Hello sir i have tried all i could, still having errors in the reddit 
> clone application.
> everything works fine except when i 
> implemented  {{=author(user_id)}} under list_posts_by_votes.html
> the errors blows when i click on the author of a comment. it does not 
> dislay the author's name as it showed in the toturial video.
>  
>
>
>
>  here's it
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
>
> Traceback (most recent call last):
>   File "C:\Users\nsikan\Desktop\web2py\gluon\restricted.py", line 227, in 
> restricted
> exec ccode in environment
>   File 
> "C:\Users\nsikan\Desktop\web2py\applications\mydream\views\default/list_posts_by_votes.html",
>  line 117, in 
> NameError: name 'category' is not defined
>
> here's deault.py
> POSTS_PER_PAGE = 10
> def get_category():
> category_name = request.args(0)
> category = db.category(name = category_name)
> if not category:
> session.flash = 'page has not been created'
> redirect(URL('index'))
> return category
>
> def index():
> rows = db(db.category).select()
> return locals()
>
> def create_post():
> category = get_category()
> db.post.category.default = category.id
> form = SQLFORM(db.post).process(next='view_post/[id]')
> return locals()
>
> def edit_post():
> id = request.args(0, cast=int)
> form = SQLFORM(db.post, id).process(next='view_post/[id]')
> return locals()
>
> def list_posts_by_datetime():
> response.view='default/list_posts_by_votes.html'
> category = get_category()
> page = request.args(1, cast=int, default=0)
> start = page * POSTS_PER_PAGE
> stop = start + POSTS_PER_PAGE
> rows = 
> db(db.post.category==category.id).select(orderby=~db.post.created_on, 
> limitby=(start, stop))
> return locals()
> 
> def list_posts_by_votes():
> category = get_category()
> page = request.args(1, cast=int, default=0)
> start = page * POSTS_PER_PAGE
> stop = start + POSTS_PER_PAGE
> rows = db(db.post.category==category.id).select(orderby=~db.post.votes, 
> limitby=(start, stop))
> return locals()
>
> def list_posts_by_author():
> response.view='default/list_posts_by_votes.html'
> user_id = request.args(0, cast=int)
> page = request.args(1, cast=int, default=0)
> start = page * POSTS_PER_PAGE
> stop = start + POSTS_PER_PAGE
> rows = 
> db(db.post.created_by==user_id).select(orderby=~db.post.created_on, 
> limitby=(start, stop))
> return locals()
>
> def view_post():
> id = request.args(0, cast=int)
> post = db.post(id) or redirect(URL('index'))
> comments = db(db.comm.post==post.id
> ).select(orderby=~db.comm.created_on)
> ##TODO
> return locals()
>
> def vote_callback():
> id = request.args(0, cast=int)
> direction = request.args(1)
> ##TODO
> return locals()
>
> def comm_vote_callback():
> id = request.args(0, cast=int)
> direction = request.args(1)
> ##TODO
> return locals()
>
>
> here's lists_posts_by_votes.html
> {{extend 'layout.html'}}
>
> {{if request.function=='list_posts_by_votes':}}
> {{=category.name.title()}}
> {{=A('sort by datetime', _class='btn', _href=URL('list_posts_by_datetime', 
> args=category.name))}}
> {{=A('post a new link', _class='btn btn-primary', _href=URL('create_post', 
> args=category.name))}}
>
> {{elif request.function=='list_posts_by_datetime':}}
> {{=category.name.title()}}
> {{=A('sort by votes', _class='btn', _href=URL('list_posts_by_votes', args=
> category.name))}}
> {{=A('post a new link', _class='btn btn-primary', _href=URL('create_post', 
> args=category.name))}}
> {{else:}}
> {{=author(user_id)}}
> {{pass}}
> 
>
> {{for post in rows:}}
> 
> 
> {{=post.votes}} 
>  {{ =A(post.title,_href=post.url) if post.url else 
> post.title}}
> {{=A('comments', _href=URL('view_post', args=
> post.id))}}
> 
> 
>
> {{pass}}
>
> {{if page>0:}}
> {{=A('previous', _class='btn', _href=URL(args=(category.name, page-1)))}}
> {{pass}}
>
> {{if len(rows)>=10:}}
> {{=A('next', _class='btn', _href=URL(args=(category.name, page+1)))}}
> {{pass}}
>
>
> here's db1.py
> # -*- coding: utf-8 -*-
> # -*- coding: utf-8 -*-
> db.define_table('category', Field('name', requires=(IS_SLUG(), 
> IS_LOWER(),IS_NOT_IN_DB(db, 'category.name'
>
> db.define_table('post',
> Field('category', 'reference category', 
> writable=False, readable=False),
> Field('title', 'string', requires=IS_NOT_EMPTY()),
> Field('url', requires=IS_EMPTY_OR(IS_URL())),
> Field('body', 'text', requires=IS_NOT_EMPTY()),
> Field('votes', 'integer',default=0 , readable=False, 
> writable=False),
> auth.signature)#created_on, created_by, modified_by, 
> modified_on, is_active
>
> db.define_table('vote',
>