From 1da3603b8317c675edcb438a4ba3f0953ee14f90 Mon Sep 17 00:00:00 2001 From: dm03514 Date: Tue, 15 Nov 2011 16:29:59 -0500 Subject: Very Simple Embeddable widget to display questions corresponding to tags. --- .../skins/default/templates/question_widget.html | 39 ++++++++++++++++++++++ askbot/tests/page_load_tests.py | 5 +++ askbot/urls.py | 5 +++ askbot/views/readers.py | 21 ++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 askbot/skins/default/templates/question_widget.html diff --git a/askbot/skins/default/templates/question_widget.html b/askbot/skins/default/templates/question_widget.html new file mode 100644 index 00000000..1d702ae0 --- /dev/null +++ b/askbot/skins/default/templates/question_widget.html @@ -0,0 +1,39 @@ + + + + + + +
+ +
+ + + diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 442b1bd7..349839ad 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -202,6 +202,11 @@ class PageLoadTestCase(AskbotTestCase): kwargs={'id':17}, template='revisions.html' ) + self.try_url( + 'widget_questions', + data={'tags': 'test'}, + template='question_widget.html', + ) self.try_url('users', template='users.html') #todo: really odd naming conventions for sort methods self.try_url( diff --git a/askbot/urls.py b/askbot/urls.py index 8c1e3c3a..4d820305 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -115,6 +115,11 @@ urlpatterns = patterns('', kwargs = {'object_name': 'Question'}, name='question_revisions' ), + url( + r'^%s$' % _('widget/'), + views.readers.widget_questions, + name='widget_questions' + ), url(#ajax only r'^comment/upvote/$', views.commands.upvote_comment, diff --git a/askbot/views/readers.py b/askbot/views/readers.py index 4a12fe2c..0107e76b 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -12,6 +12,7 @@ import urllib import operator from django.shortcuts import get_object_or_404 from django.http import HttpResponseRedirect, HttpResponse, Http404 +from django.conf import settings as django_settings from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.template import Context from django.utils.http import urlencode @@ -593,3 +594,23 @@ def get_question_body(request): return {'questions-titles': questions_dict} return {'questions-titles': questions_dict} + +def widget_questions(request): + """Returns the first x questions based on certain tags. + @returns template with those questions listed.""" + # make sure this is a GET request with the correct parameters. + if request.method != 'GET' or not request.GET.get('tags'): + raise Http404 + tags_list = request.GET['tags'].split(',') + # Get Questions that contain all the matching tags, could be OR instead. + matching_questions = models.Question.objects.filter(tags__name__in=tags_list)[:7] + data = [] + for matching_question in matching_questions: + data.append({ + 'url': '%s%s' % (django_settings.SITE_BASE_URL, + matching_question.get_absolute_url()), + 'title': matching_question.title + }) + #import ipdb; ipdb.set_trace() + return render_into_skin('question_widget.html', {'questions': data}, request) + -- cgit v1.2.3-1-g7c22