diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2013-04-07 05:37:16 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2013-04-07 05:37:16 -0400 |
commit | 67c5a4bb63a08c3620e6667f4b0c3a3c61cc61ce (patch) | |
tree | 4fe5381c2b2a16f994a8bfa6092db70e77e7a52f /askbot/views | |
parent | b03f881b11204b7e0fe323dd9148085ef0dfa35d (diff) | |
parent | 60bc578f579d8b5a40e4c040a0bbd6a60e30e950 (diff) | |
download | askbot-67c5a4bb63a08c3620e6667f4b0c3a3c61cc61ce.tar.gz askbot-67c5a4bb63a08c3620e6667f4b0c3a3c61cc61ce.tar.bz2 askbot-67c5a4bb63a08c3620e6667f4b0c3a3c61cc61ce.zip |
merged with the master branch
Diffstat (limited to 'askbot/views')
-rw-r--r-- | askbot/views/context.py | 8 | ||||
-rw-r--r-- | askbot/views/readers.py | 130 |
2 files changed, 67 insertions, 71 deletions
diff --git a/askbot/views/context.py b/askbot/views/context.py index eeaf6002..2b9ef5ea 100644 --- a/askbot/views/context.py +++ b/askbot/views/context.py @@ -1,11 +1,13 @@ """functions, preparing parts of context for the templates in the various views""" +from django.conf import settings as django_settings from django.utils import simplejson from django.utils.translation import ugettext as _ from askbot.conf import settings as askbot_settings from askbot import const from askbot.const import message_keys as msg from askbot.models import GroupMembership +from askbot.utils.loading import load_module def get_for_tag_editor(): #data for the tag editor @@ -50,3 +52,9 @@ def get_for_inbox(user): 'group_join_requests_count': group_join_requests_count } +def get_extra(context_module_setting, request, data): + extra_context = getattr(django_settings, context_module_setting, None) + if extra_context: + extra_context_getter = load_module(extra_context) + return extra_context_getter(request, data) + return {} diff --git a/askbot/views/readers.py b/askbot/views/readers.py index fa39426c..962e1dbb 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -40,7 +40,6 @@ from askbot import const from askbot.utils import functions from askbot.utils.html import sanitize_html from askbot.utils.decorators import anonymous_forbidden, ajax_only, get_only -from askbot.utils.loading import load_module from askbot.search.state_manager import SearchState, DummySearchState from askbot.templatetags import extra_tags from askbot.conf import settings as askbot_settings @@ -239,47 +238,64 @@ def questions(request, **kwargs): 'feed_url': context_feed_url, } + extra_context = context.get_extra( + 'ASKBOT_QUESTIONS_PAGE_EXTRA_CONTEXT', + request, + template_data + ) + template_data.update(extra_context) + return render(request, 'main_page.html', template_data) def tags(request):#view showing a listing of available tags - plain list + #1) Get parameters. This normally belongs to form cleaning. + post_data = request.GET + sortby = post_data.get('sort', 'used') + try: + page = int(post_data.get('page', '1')) + except ValueError: + page = 1 + + if sortby == 'name': + order_by = 'name' + else: + order_by = '-used_count' + + query = post_data.get('query', '').strip() tag_list_type = askbot_settings.TAG_LIST_FORMAT - if tag_list_type == 'list': + #2) Get query set for the tags. + query_params = {'deleted': False} + if query != '': + query_params['name__icontains'] = query - stag = "" - is_paginated = True - sortby = request.GET.get('sort', 'used') - try: - page = int(request.GET.get('page', '1')) - except ValueError: - page = 1 - - stag = request.GET.get("query", "").strip() - if stag != '': - objects_list = Paginator( - models.Tag.objects.filter( - deleted=False, - name__icontains=stag - ).exclude( - used_count=0 - ), - DEFAULT_PAGE_SIZE - ) - else: - if sortby == "name": - objects_list = Paginator(models.Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("name"), DEFAULT_PAGE_SIZE) - else: - objects_list = Paginator(models.Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("-used_count"), DEFAULT_PAGE_SIZE) + tags_qs = Tag.objects.filter(**query_params).exclude(used_count=0) + + tags_qs = tags_qs.order_by(order_by) + + #3) Start populating the template context. + data = { + 'active_tab': 'tags', + 'page_class': 'tags-page', + 'tag_list_type' : tag_list_type, + 'stag' : query, + 'tab_id' : sortby, + 'keywords' : query, + 'search_state': SearchState(*[None for x in range(7)]) + } + if tag_list_type == 'list': + #plain listing is paginated + objects_list = Paginator(tags_qs, DEFAULT_PAGE_SIZE) try: tags = objects_list.page(page) except (EmptyPage, InvalidPage): tags = objects_list.page(objects_list.num_pages) paginator_data = { - 'is_paginated' : is_paginated, + 'is_paginated' : (objects_list.num_pages > 1), 'pages': objects_list.num_pages, 'page': page, 'has_previous': tags.has_previous(), @@ -289,47 +305,24 @@ def tags(request):#view showing a listing of available tags - plain list 'base_url' : reverse('tags') + '?sort=%s&' % sortby } paginator_context = functions.setup_paginator(paginator_data) - data = { - 'active_tab': 'tags', - 'page_class': 'tags-page', - 'tags' : tags, - 'tag_list_type' : tag_list_type, - 'stag' : stag, - 'tab_id' : sortby, - 'keywords' : stag, - 'paginator_context' : paginator_context, - } - + data['paginator_context'] = paginator_context else: - - stag = "" - sortby = request.GET.get('sort', 'name') - - if request.method == "GET": - stag = request.GET.get("query", "").strip() - if stag != '': - tags = models.Tag.objects.filter(deleted=False, name__icontains=stag).exclude(used_count=0) - else: - if sortby == "name": - tags = models.Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("name") - else: - tags = models.Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("-used_count") - + #tags for the tag cloud are given without pagination + tags = tags_qs font_size = extra_tags.get_tag_font_size(tags) + data['font_size'] = font_size - data = { - 'active_tab': 'tags', - 'page_class': 'tags-page', - 'tags' : tags, - 'tag_list_type' : tag_list_type, - 'font_size' : font_size, - 'stag' : stag, - 'tab_id' : sortby, - 'keywords' : stag, - 'search_state': SearchState(*[None for x in range(7)]) - } + data['tags'] = tags + data.update(context.get_extra('ASKBOT_TAGS_PAGE_EXTRA_CONTEXT', request, data)) - return render(request, 'tags.html', data) + if request.is_ajax(): + template = get_template('tags/content.html') + template_context = RequestContext(request, data) + json_data = {'success': True, 'html': template.render(template_context)} + json_string = simplejson.dumps(json_data) + return HttpResponse(json_string, mimetype='application/json') + else: + return render(request, 'tags.html', data) @csrf.csrf_protect def question(request, id):#refactor - long subroutine. display question body, answers and comments @@ -615,13 +608,8 @@ def question(request, id):#refactor - long subroutine. display question body, an data.update(context.get_for_tag_editor()) - extra_context = getattr( - django_settings, 'ASKBOT_QUESTION_PAGE_EXTRA_CONTEXT', None - ) - if extra_context: - extra_context_getter = load_module(extra_context) - extra_data = extra_context_getter(request, data) - data.update(extra_data) + extra = context.get_extra('ASKBOT_QUESTION_PAGE_EXTRA_CONTEXT', request, data) + data.update(extra) return render(request, 'question.html', data) |