summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoahY <yuttadhammo@yahoo.com>2011-07-27 00:09:56 +0530
committerNoahY <yuttadhammo@yahoo.com>2011-07-27 00:09:56 +0530
commit54fd0a6738aed5d6446fba869992c5965db5d52c (patch)
tree4447cd12aa3625502f8d7316c59c7b238aca7e22
parentf20910217d645bc922cbdfce774c84ce5a7dc130 (diff)
downloadaskbot-54fd0a6738aed5d6446fba869992c5965db5d52c.tar.gz
askbot-54fd0a6738aed5d6446fba869992c5965db5d52c.tar.bz2
askbot-54fd0a6738aed5d6446fba869992c5965db5d52c.zip
added tag cloud to sidebar
-rwxr-xr-xaskbot/skins/default/media/style/style.css25
-rw-r--r--askbot/skins/default/templates/main_page/sidebar.html17
-rw-r--r--askbot/skins/default/templates/tags.html14
-rw-r--r--askbot/views/readers.py75
4 files changed, 80 insertions, 51 deletions
diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css
index a0589d71..cfcc394e 100755
--- a/askbot/skins/default/media/style/style.css
+++ b/askbot/skins/default/media/style/style.css
@@ -374,6 +374,31 @@ blockquote {
because it must be the same in the emails
askbot/models/__init__.py:format_instant_notification_email()
*/
+
+/* tag cloud */
+
+.tag-size-1 {
+ font-size:12;
+}
+.tag-size-2 {
+ font-size:13;
+}
+.tag-size-3 {
+ font-size:14;
+}
+.tag-size-4 {
+ font-size:15;
+}
+.tag-size-5 {
+ font-size:16;
+}
+.tag-size-6 {
+ font-size:17;
+}
+.tag-size-7 {
+ font-size:18;
+}
+
ul.tags,
.boxC ul.tags,
ul.tags.marked-tags,
diff --git a/askbot/skins/default/templates/main_page/sidebar.html b/askbot/skins/default/templates/main_page/sidebar.html
index 52d107af..c71b8c20 100644
--- a/askbot/skins/default/templates/main_page/sidebar.html
+++ b/askbot/skins/default/templates/main_page/sidebar.html
@@ -20,18 +20,11 @@
{% cache 0 "tags" tags search_tags scope sort query context.page context.page_size language_code %}
<div class="boxC">
<h2>{% trans %}Related tags{% endtrans %}</h2>
- <ul id="related-tags" class="tags">
- {% for tag in tags %}
- <li>
- {{ macros.tag_widget(
- tag.name,
- html_tag = 'div',
- extra_content = '<span class="tag-number">&#215; ' ~
- tag.local_used_count|intcomma ~ '</span>'
- )}}
- </li>
- {% endfor %}
- </ul>
+ {% for tag in tags %}
+ <span class="tag-size-{{ font_size[tag.name] }}">
+ <a class="link-typeA" title="Number of entries: {{ tag.used_count }}" href="/blog/tags/all/{{ tag.name }}">{{ tag.name }}</a>
+ </span>
+ {% endfor %}
</div>
{% endcache %}
{% endif %}
diff --git a/askbot/skins/default/templates/tags.html b/askbot/skins/default/templates/tags.html
index cec5639d..976d8f1d 100644
--- a/askbot/skins/default/templates/tags.html
+++ b/askbot/skins/default/templates/tags.html
@@ -21,23 +21,21 @@
><span>{% trans %}by popularity{% endtrans %}</span></a>
</div>
</div>
-<p>
+<p>
{% if stag %}
{% trans %}All tags matching '<span class="darkred"><strong>{{ stag }}</strong></span>'{% endtrans %}:
{% endif %}
- {% if not tags.object_list %}
+ {% if not tags %}
<span>{% trans %}Nothing found{% endtrans %}</span>
{% endif %}
</p>
-{% if tags.object_list %}
- {% for tag in tags.object_list %}
- <span style="font-size: {{ tag_font_size[tag] }}px;">
+{% if tags %}
+ {% for tag in tags %}
+ <span class="tag-size-{{ font_size[tag.name] }}">
<a class="link-typeA" title="Number of entries: {{ tag.used_count }}" href="/blog/tags/all/{{ tag.name }}">{{ tag.name }}</a>
</span>
+ {% endfor %}
{% endif %}
-<div class="pager">
- {{macros.paginator(paginator_context)}}
-</div>
{% endblock %}
{% block endjs %}
<script type="text/javascript">
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index b5676a9a..9f7b9ceb 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -6,6 +6,7 @@ By main textual content is meant - text of Questions, Answers and Comments.
The "read-only" requirement here is not 100% strict, as for example "question" view does
allow adding new comments via Ajax form post.
"""
+import math
import datetime
import logging
import urllib
@@ -90,7 +91,9 @@ def questions(request):
request_user = request.user,
search_state = search_state,
)
-
+
+ font_size = get_tag_font_size(tags)
+
paginator = Paginator(qs, search_state.page_size)
if paginator.num_pages < search_state.page:
@@ -215,6 +218,7 @@ def questions(request):
'summary': question.summary,
'id': question.id,
'tags': question.get_tag_names(),
+ 'font_size': font_size,
'votes': extra_filters.humanize_counter(question.score),
'votes_class': votes_class,
'votes_word': ungettext('vote', 'votes', question.score),
@@ -289,6 +293,7 @@ def questions(request):
'sort': search_state.sort,
'tab_id' : search_state.sort,
'tags' : related_tags,
+ 'font_size' : font_size,
'tag_filter_strategy_choices': const.TAG_FILTER_STRATEGY_CHOICES,
}
@@ -328,48 +333,56 @@ def tags(request):#view showing a listing of available tags - plain list
else:
objects_list = Paginator(models.Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("-used_count"), DEFAULT_PAGE_SIZE)
- try:
- tags = objects_list.page(page)
- except (EmptyPage, InvalidPage):
- tags = objects_list.page(objects_list.num_pages)
-
- #tag cloud params
- max_tag = 0
- for tag in tags.objects_list:
- if tag.used_count > max_tag:
- max_tag = tag.used_count
+ tags = models.Tag.objects.all().filter(deleted=False).exclude(used_count=0).order_by("name")
- min_tag = max_tag
- for tag in tags.objects_list:
- if tag.used_count < min_tag:
- min_tag = tag.used_count
+ font_size = get_tag_font_size(tags)
- for tag in tags.objects_list:
- font_size[tag] = tag_font_size(max_tag,min_tag,tag.used_count)
-
- paginator_data = {
- 'is_paginated' : is_paginated,
- 'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': tags.has_previous(),
- 'has_next': tags.has_next(),
- 'previous': tags.previous_page_number(),
- 'next': tags.next_page_number(),
- 'base_url' : reverse('tags') + '?sort=%s&amp;' % sortby
- }
- paginator_context = extra_tags.cnprog_paginator(paginator_data)
data = {
'active_tab': 'tags',
'page_class': 'tags-page',
'tags' : tags,
- 'tag_font_size' : tag_font_size,
+ 'max' : max_tag,
+ 'min' : min_tag,
+ 'font_size' : font_size,
'stag' : stag,
'tab_id' : sortby,
'keywords' : stag,
- 'paginator_context' : paginator_context
}
+
return render_into_skin('tags.html', data, request)
+def get_tag_font_size(tags):
+ max_tag = 0
+ for tag in tags:
+ if tag.used_count > max_tag:
+ max_tag = tag.used_count
+
+ min_tag = max_tag
+ for tag in tags:
+ if tag.used_count < min_tag:
+ min_tag = tag.used_count
+
+ font_size = {}
+ for tag in tags:
+ font_size[tag.name] = tag_font_size(max_tag,min_tag,tag.used_count)
+
+ return font_size
+
+def tag_font_size(max_size, min_size, current_size):
+ """
+ do a logarithmic mapping calcuation for a proper size for tagging cloud
+ Algorithm from http://blogs.dekoh.com/dev/2007/10/29/choosing-a-good-
+ font-size-variation-algorithm-for-your-tag-cloud/
+ """
+ MAX_FONTSIZE = 7
+ MIN_FONTSIZE = 1
+
+ #avoid invalid calculation
+ if current_size == 0:
+ current_size = 1
+ weight = (math.log10(current_size) - math.log10(min_size)) / (math.log10(max_size) - math.log10(min_size))
+ return MIN_FONTSIZE + round((MAX_FONTSIZE - MIN_FONTSIZE) * weight)
+
@csrf.csrf_protect
def question(request, id):#refactor - long subroutine. display question body, answers and comments
"""view that displays body of the question and