tags url; fix bugs

This commit is contained in:
bkfox
2016-06-20 13:38:34 +02:00
parent 23016a594f
commit a3a9beac6d
10 changed files with 108 additions and 25 deletions

View File

@ -135,6 +135,9 @@ class ThreadRoute(Route):
class DateRoute(Route):
"""
Select posts using a date with format yyyy/mm/dd;
"""
name = 'date'
url_args = [
('year', '[0-9]{4}'),
@ -160,6 +163,11 @@ class DateRoute(Route):
class SearchRoute(Route):
"""
Search post using request.GET['q']. It searches in fields designated by
model.search_fields
"""
# TODO: q argument in url_args -> need to allow optional url_args
name = 'search'
@classmethod
@ -183,3 +191,27 @@ class SearchRoute(Route):
}
class TagsRoute(Route):
"""
Select posts that contains the given tags. The tags are separated
by a '+'.
"""
name = 'tags'
url_args = [
('tags', '(\w|-|_|\+)+')
]
@classmethod
def get_queryset(cl, model, request, tags, **kwargs):
tags = tags.split('+')
return model.objects.filter(tags__name__in=tags)
@classmethod
def get_title(cl, model, request, tags, **kwargs):
return _('Tagged %(model)s with %(tags)s') % {
'model': model._meta.verbose_name_plural,
'tags': tags.replace('+', ', ')
}