summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-11-29 15:45:00 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-11-29 15:45:00 -0300
commitbc1369d4c4e8e9d4bbc9cadea16a46509c3cf9b4 (patch)
tree26bdd7ead4b92b35bbc662d3c037c5e0570118ab
parent147eb56d5e1d7eb12d0bac402009e6a72edf0f8b (diff)
parent8bcb9ec5017cafc4bc4af33224c5a596871c5eea (diff)
downloadaskbot-bc1369d4c4e8e9d4bbc9cadea16a46509c3cf9b4.tar.gz
askbot-bc1369d4c4e8e9d4bbc9cadea16a46509c3cf9b4.tar.bz2
askbot-bc1369d4c4e8e9d4bbc9cadea16a46509c3cf9b4.zip
finished the iframe question list widget featuer
-rw-r--r--askbot/conf/__init__.py1
-rw-r--r--askbot/conf/widgets.py99
-rw-r--r--askbot/management/commands/merge_users.py54
-rw-r--r--askbot/setup_templates/settings.py2
-rw-r--r--askbot/setup_templates/settings.py.mustache2
-rw-r--r--askbot/skins/default/media/style/style.less4
-rw-r--r--askbot/skins/default/templates/question/sidebar.html2
-rw-r--r--askbot/skins/default/templates/question_widget.html21
-rw-r--r--askbot/tests/page_load_tests.py10
-rw-r--r--askbot/urls.py5
-rw-r--r--askbot/views/readers.py18
11 files changed, 197 insertions, 21 deletions
diff --git a/askbot/conf/__init__.py b/askbot/conf/__init__.py
index 4f228ea7..026a6185 100644
--- a/askbot/conf/__init__.py
+++ b/askbot/conf/__init__.py
@@ -21,6 +21,7 @@ import askbot.conf.badges
import askbot.conf.login_providers
import askbot.conf.access_control
import askbot.conf.site_modes
+import askbot.conf.widgets
#import main settings object
from askbot.conf.settings_wrapper import settings
diff --git a/askbot/conf/widgets.py b/askbot/conf/widgets.py
new file mode 100644
index 00000000..d704ea12
--- /dev/null
+++ b/askbot/conf/widgets.py
@@ -0,0 +1,99 @@
+"""
+Settings for embeddable widgets
+"""
+from django.utils.translation import ugettext as _
+from django.utils.html import escape
+from askbot.conf.settings_wrapper import settings
+from askbot.deps.livesettings import ConfigurationGroup
+from askbot.deps.livesettings import values
+from askbot.conf.super_groups import CONTENT_AND_UI
+
+EMBEDDABLE_WIDGETS = ConfigurationGroup(
+ 'EMBEDDABLE_WIDGETS',
+ _('Embeddable widgets'),
+ super_group = CONTENT_AND_UI
+)
+
+#we need better capabilities for the settings here
+#
+
+settings.register(
+ values.IntegerValue(
+ EMBEDDABLE_WIDGETS,
+ 'QUESTIONS_WIDGET_MAX_QUESTIONS',
+ default = 7,
+ description = _('Number of questions to show'),
+ help_text = escape(
+ _(
+ 'To embed the widget, add the following code '
+ 'to your site (and fill in correct base url, preferred tags, width and height):'
+ '<iframe '
+ 'src="{{base_url}}/widgets/questions?tags={{comma-separated-tags}}" '
+ 'width="100%" '
+ 'height="300"'
+ 'scrolling="no">'
+ '<p>Your browser does not support iframes.</p>'
+ '</iframe>'
+ )
+ )
+ )
+)
+settings.register(
+ values.LongStringValue(
+ EMBEDDABLE_WIDGETS,
+ 'QUESTIONS_WIDGET_CSS',
+ default = """
+body {
+ overflow: hidden;
+}
+#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;
+}
+li:last-child {
+ border: none;
+}
+a {
+ text-decoration: none;
+ color: #464646;
+ font-family: 'Yanone Kaffeesatz', sans-serif;
+ font-size: 15px;
+}
+""",
+ descripton = _('CSS for the questions widget')
+ )
+)
+
+settings.register(
+ values.LongStringValue(
+ EMBEDDABLE_WIDGETS,
+ 'QUESTIONS_WIDGET_HEADER',
+ description = _('Header for the questions widget'),
+ default = ''
+ )
+)
+
+settings.register(
+ values.LongStringValue(
+ EMBEDDABLE_WIDGETS,
+ 'QUESTIONS_WIDGET_FOOTER',
+ description = _('Footer for the questions widget'),
+ default = """
+<link
+ href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:300,400,700'
+ rel='stylesheet'
+ type='text/css'
+>
+"""
+ )
+)
diff --git a/askbot/management/commands/merge_users.py b/askbot/management/commands/merge_users.py
index 4691c4b3..3c7069e5 100644
--- a/askbot/management/commands/merge_users.py
+++ b/askbot/management/commands/merge_users.py
@@ -1,18 +1,12 @@
from django.core.management.base import CommandError, BaseCommand
from askbot.models import User
-
-class Command(BaseCommand):
+class MergeUsersBaseCommand(BaseCommand):
args = '<from_user_id> <to_user_id>'
help = 'Merge an account and all information from a <user_id> to a <user_id>, deleting the <from_user>'
- def parse_arguments(self, *arguments):
- if len(arguments) != 2:
- raise CommandError('Arguments are <from_user_id> to <to_user_id>')
- self.from_user = User.objects.get(id = arguments[0])
- self.to_user = User.objects.get(id = arguments[1])
-
def handle(self, *arguments, **options):
+
self.parse_arguments(*arguments)
for rel in User._meta.get_all_related_objects():
@@ -26,21 +20,23 @@ class Command(BaseCommand):
self.process_m2m_field(rel.model, rel.field.name)
except Exception, error:
self.stdout.write(u'Warning: %s\n' % error)
-
- self.to_user.reputation += self.from_user.reputation - 1
- self.to_user.gold += self.from_user.gold
- self.to_user.silver += self.from_user.silver
- self.to_user.bronze += self.from_user.bronze
- if self.from_user.last_seen > self.to_user.last_seen:
- self.to_user.last_seen = self.from_user.last_seen
+ self.process_custom_user_fields()
- if self.from_user.date_joined < self.to_user.date_joined:
- self.to_user.date_joined = self.from_user.date_joined
+ self.cleanup()
- self.to_user.save()
+ def cleanup(self):
+ raise Exception, 'Not implemented'
+
+ def process_custom_user_fields(self):
+ """Put app specific logic here."""
+ raise Exception, 'Not implemented'
- self.from_user.delete()
+ def parse_arguments(self, *arguments):
+ if len(arguments) != 2:
+ raise CommandError('Arguments are <from_user_id> to <to_user_id>')
+ self.from_user = User.objects.get(id = arguments[0])
+ self.to_user = User.objects.get(id = arguments[1])
def process_field(self, model, field_name):
"""reassigns the related object to the new user"""
@@ -58,3 +54,23 @@ class Command(BaseCommand):
m2m_field = getattr(obj, field_name)
m2m_field.remove(self.from_user)
m2m_field.add(self.to_user)
+
+
+class Command(MergeUsersBaseCommand):
+
+ def process_custom_user_fields(self):
+ self.to_user.reputation += self.from_user.reputation - 1
+ self.to_user.gold += self.from_user.gold
+ self.to_user.silver += self.from_user.silver
+ self.to_user.bronze += self.from_user.bronze
+
+ if self.from_user.last_seen > self.to_user.last_seen:
+ self.to_user.last_seen = self.from_user.last_seen
+
+ if self.from_user.date_joined < self.to_user.date_joined:
+ self.to_user.date_joined = self.from_user.date_joined
+
+ def cleanup(self):
+ self.to_user.save()
+ self.from_user.delete()
+
diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py
index a6d257ae..9e847eba 100644
--- a/askbot/setup_templates/settings.py
+++ b/askbot/setup_templates/settings.py
@@ -168,6 +168,8 @@ INSTALLED_APPS = (
'followit',
#'avatar',#experimental use git clone git://github.com/ericflo/django-avatar.git$
#requires setting of MEDIA_ROOT and MEDIA_URL
+ #values of which can be the same as ASKBOT_FILE_UPLOAD_DIR and ASKBOT_UPLOADED_FILES_URL,
+ #respectively
)
diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache
index e177c649..79b98814 100644
--- a/askbot/setup_templates/settings.py.mustache
+++ b/askbot/setup_templates/settings.py.mustache
@@ -167,6 +167,8 @@ INSTALLED_APPS = (
'followit',
#'avatar',#experimental use git clone git://github.com/ericflo/django-avatar.git$
#requires setting of MEDIA_ROOT and MEDIA_URL
+ #values of which can be the same as ASKBOT_FILE_UPLOAD_DIR and ASKBOT_UPLOADED_FILES_URL,
+ #respectively
)
diff --git a/askbot/skins/default/media/style/style.less b/askbot/skins/default/media/style/style.less
index 3e913bbf..f5639328 100644
--- a/askbot/skins/default/media/style/style.less
+++ b/askbot/skins/default/media/style/style.less
@@ -39,6 +39,10 @@ input, select {
margin-left:0px;
}
+iframe {
+ border: none;
+}
+
p {
font-size: 14px;
line-height: 140%;
diff --git a/askbot/skins/default/templates/question/sidebar.html b/askbot/skins/default/templates/question/sidebar.html
index d011d562..918c7662 100644
--- a/askbot/skins/default/templates/question/sidebar.html
+++ b/askbot/skins/default/templates/question/sidebar.html
@@ -33,7 +33,7 @@
<a
href="{{settings.APP_URL}}/feeds/question/{{ question.id }}"
title="{% trans %}subscribe to this question rss feed{% endtrans %}"
- >{% trans %}subsribe to rss feed{% endtrans %}</a>
+ >{% trans %}subscribe to rss feed{% endtrans %}</a>
</p>
</div>
</div>
diff --git a/askbot/skins/default/templates/question_widget.html b/askbot/skins/default/templates/question_widget.html
new file mode 100644
index 00000000..bb883c71
--- /dev/null
+++ b/askbot/skins/default/templates/question_widget.html
@@ -0,0 +1,21 @@
+<!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">
+ {{settings.QUESTIONS_WIDGET_CSS|safe}}
+ </style>
+</head>
+<body>
+ {{settings.QUESTIONS_WIDGET_HEADER|safe}}
+ <div id="container">
+ <ul>
+ {% for question in questions %}
+ <li><a href="{{settings.APP_URL}}{{ question.get_absolute_url() }}">
+ {{ question.title }}</a></li>
+ {% endfor %}
+ </ul>
+ </div>
+ {{settings.QUESTIONS_WIDGET_FOOTER|safe}}
+</body>
+</html>
diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py
index e0bcce86..0c8fbe9f 100644
--- a/askbot/tests/page_load_tests.py
+++ b/askbot/tests/page_load_tests.py
@@ -272,7 +272,15 @@ class PageLoadTestCase(AskbotTestCase):
)
self.try_url('users',
status_code=status_code,
- template='users.html')
+ template='users.html'
+ )
+ import pdb; pdb.set_trace()
+ self.try_url(
+ 'widget_questions',
+ status_code = status_code,
+ data={'tags': 'test'},
+ template='question_widget.html',
+ )
#todo: really odd naming conventions for sort methods
self.try_url(
'users',
diff --git a/askbot/urls.py b/askbot/urls.py
index be21217b..2c3d143d 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -119,6 +119,11 @@ urlpatterns = patterns('',
kwargs = {'object_name': 'Question'},
name='question_revisions'
),
+ url(
+ r'^%s%s$' % (_('widgets/'), _('questions/')),
+ 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 53ef519e..2c637f36 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
@@ -626,3 +627,20 @@ 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':
+ raise Http404
+ questions = models.Question.objects.all()
+ tags_input = request.GET.get('tags','').strip()
+ if len(tags_input) > 0:
+ tags = [tag.strip() for tag in tags_input.split(',')]
+ questions = questions.filter(tags__name__in = tags)
+ data = {
+ 'questions': questions[:askbot_settings.QUESTIONS_WIDGET_MAX_QUESTIONS]
+ }
+ return render_into_skin('question_widget.html', data, request)
+