sort by name in tags not work

2 views
Skip to first unread message

Ali Kusnadi

unread,
Aug 23, 2009, 10:43:13 AM8/23/09
to cnp...@googlegroups.com
hi..

i'm find a problem in cnprog, short tags by name not work

I am using Django 1.0.2 final. and cnprog english


^^bad english sorry

best regards
ali kusnadi

Mike Chen

unread,
Aug 23, 2009, 10:59:01 AM8/23/09
to cnp...@googlegroups.com
Can you give an example of your short tags?
Do you have any special character in tag name?

Regards,
-Mike

Ali Kusnadi

unread,
Aug 23, 2009, 11:40:26 AM8/23/09
to cnp...@googlegroups.com
On 8/23/09, Mike Chen <cha...@gmail.com> wrote:
> Can you give an example of your short tags?Do you have any special character
> in tag name?
>

hi .. mike

see http://cnprog.com/tags/?sort=used or http://cnprog.com/tags/?sort=name

no different ... ?

best regards
ali kusnadi


> >
>

Ali Kusnadi

unread,
Aug 23, 2009, 11:45:19 AM8/23/09
to cnp...@googlegroups.com

solved...

i change tags in view like this

def tags(request):
is_paginated = True

sortby = request.GET.get('sort', 'used')

stag = request.REQUEST.get('q', "")

try:

page = int(request.GET.get('page', '1'))

except ValueError:

page = 1

if stag == "":

if sortby == "name":

objects_list =
Paginator(Tag.objects.filter(deleted=False).exclude(used_count=0).extra(where=['name
like %s'], params=['%' + stag + '%']), DEFAULT_PAGE_SIZE)

else:

objects_list =
Paginator(Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("-used_count"),
DEFAULT_PAGE_SIZE)

# default

else:

objects_list =
Paginator(Tag.objects.filter(deleted=False).exclude(used_count=0).extra(where=['name
like %s'], params=['%' + stag + '%']), DEFAULT_PAGE_SIZE)


try:

tags = objects_list.page(page)

except (EmptyPage, InvalidPage):

tags = objects_list.page(objects_list.num_pages)

return render_to_response('tags.html', {

"tags" : tags,

"stag" : stag,

"tab_id" : sortby,

"keywords" : stag,

"context" : {

'is_paginated' : is_paginated,

'pages': objects_list.num_pages,

'page': page,

'has_previous': tags.has_previous(),

'has_next': tags.has_next(),

'previous': tags.previous_page_number(),

'next': tags.next_page_number(),

'base_url' : '/tags/?sort=%s&' % sortby

}

}, context_instance=RequestContext(request))


but i dont think its good code :D, please correct me

best regards

hsk

unread,
Aug 23, 2009, 12:16:58 PM8/23/09
to CNProg open discussion
Hi, thank you for letting us realize that there was a problem with tag
ordering!

I read through that piece of code and realized that under

forum/views.py: def tags(request):
...
stag = request.GET.get("q", "").strip()
if stag is not None: << this line was the culprit.

quick fix was to change the line to
if stag != "":

you can probably check in python command line
>>"" is not None
returns True! Which is not the author's intention I believe.

I guess python can be pretty deceptive... :|

cheers,

HS
On Aug 23, 11:45 am, Ali Kusnadi <kugutsu.hir...@gmail.com> wrote:

Mike Chen

unread,
Aug 23, 2009, 12:17:40 PM8/23/09
to cnp...@googlegroups.com
Fixed and updated, thanks for reporting this.

Regards,
-Mike

Mike Chen

unread,
Aug 23, 2009, 12:25:53 PM8/23/09
to cnp...@googlegroups.com
Agree on that..

After I have programmed on Ruby and ROR for a while, I feel Python is over explicit sometimes.
 
Code like -
"if sortby == "used":
                sortby = "-used_count"
            else:
                sortby = "name""
is too ugly for me now, and I need to keep in mind that we should support python 2.4 and stay away from "a = b if b == c else d".. painful..

Regards,
-Mike

Ali Kusnadi

unread,
Aug 23, 2009, 1:37:55 PM8/23/09
to cnp...@googlegroups.com
On 8/23/09, hsk <contac...@gmail.com> wrote:
>
> Hi, thank you for letting us realize that there was a problem with tag
> ordering!
>
> I read through that piece of code and realized that under
>
> forum/views.py: def tags(request):
> ...
> stag = request.GET.get("q", "").strip()
> if stag is not None: << this line was the culprit.
>
> quick fix was to change the line to
> if stag != "":
>
> you can probably check in python command line
>>>"" is not None
> returns True! Which is not the author's intention I believe.
>
> I guess python can be pretty deceptive... :|
>
> cheers,
>

thanks

regards
ali kusnadi

> >
>
Reply all
Reply to author
Forward
0 new messages