summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordm03514 <dm03514@dm03514-Inspiron-1545>2011-11-15 16:29:59 -0500
committerdm03514 <dm03514@dm03514-Inspiron-1545>2011-11-15 16:29:59 -0500
commit1da3603b8317c675edcb438a4ba3f0953ee14f90 (patch)
tree6102292432759d2059db2790e107e54a21897033
parent6f868b450fc77f2322db3aa7c57422ff9bdcc9fa (diff)
downloadaskbot-1da3603b8317c675edcb438a4ba3f0953ee14f90.tar.gz
askbot-1da3603b8317c675edcb438a4ba3f0953ee14f90.tar.bz2
askbot-1da3603b8317c675edcb438a4ba3f0953ee14f90.zip
Very Simple Embeddable widget to display questions corresponding to tags.
-rw-r--r--askbot/skins/default/templates/question_widget.html39
-rw-r--r--askbot/tests/page_load_tests.py5
-rw-r--r--askbot/urls.py5
-rw-r--r--askbot/views/readers.py21
4 files changed, 70 insertions, 0 deletions
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 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+<head>
+ <style type="text/css">
+ #container {
+ width: 200px;
+ height: 350px;
+ }
+ ul {
+ list-style: none;
+ padding: 5px;
+ margin: 5px;
+ }
+ li {
+ border-bottom: #CCC 1px solid;
+ padding-bottom: 5px;
+ padding-top: 5px;
+ }
+ a {
+ text-decoration: none;
+ color: #464646;
+ font-family: 'Yanone Kaffeesatz', sans-serif;
+ font-size: 15px;
+ }
+ </style>
+</head>
+<body>
+ <div id="container">
+ <ul>
+ {% for question in questions %}
+ <li><a href="{{ question.url }}">
+ {{ question.title }}</a></li>
+ {% endfor %}
+ </ul>
+ </div>
+ <link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:300,400,700' rel='stylesheet' type='text/css'>
+</body>
+</html>
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)
+