]> git.openstreetmap.org Git - osqa.git/commitdiff
OSQA-586, be able to display recent tags in a cloud. Using logarithmic mapping to...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 5 Jul 2011 19:45:38 +0000 (19:45 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 5 Jul 2011 19:45:38 +0000 (19:45 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1103 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/settings/view.py
forum/skins/default/templates/sidebar/recent_tags.html
forum/templatetags/extra_tags.py

index 14b3aad131898dfcf7b4ba7b9285264d85fdbbdc..9b7cf4ea00619f03aa26ae10aaf9a0a83ed0abca 100644 (file)
@@ -13,10 +13,32 @@ SUMMARY_LENGTH = Setting('SUMMARY_LENGTH', 300, VIEW_SET, dict(
 label = _("Summary Length"),
 help_text = _("The number of characters that are going to be displayed in order to get the content summary.")))
 
+# Tag settings
 RECENT_TAGS_SIZE = Setting('RECENT_TAGS_SIZE', 25, VIEW_SET, dict(
 label = _("Recent tags block size"),
 help_text = _("The number of tags to display in the recent tags block in the front page.")))
 
+SHOW_TAGS_IN_A_CLOUD = Setting('SHOW_TAGS_IN_A_CLOUD', True, VIEW_SET, dict(
+label = _("Show tags in a cloud"),
+help_text = _("If selected the tags in the recent tags widget will be displayed in a cloud."),
+required=False))
+
+TAGS_CLOUD_MIN_OCCURS = Setting('TAGS_CLOUD_MIN_OCCURS', 1, VIEW_SET, dict(
+label = _("Tags cloud min occurs"),
+help_text = _("Used to calculate the font size of the tags in the cloud widget.")))
+
+TAGS_CLOUD_MAX_OCCURS = Setting('TAGS_CLOUD_MAX_OCCURS', 35, VIEW_SET, dict(
+label = _("Tags cloud max occurs"),
+help_text = _("Used to calculate the font size of the tags in the cloud widget.")))
+
+TAGS_CLOUD_MIN_FONT_SIZE = Setting('TAGS_CLOUD_MIN_FONT_SIZE', 10, VIEW_SET, dict(
+label = _("Tags cloud min font size"),
+help_text = _("Used to calculate the font size of the tags in the cloud widget.")))
+
+TAGS_CLOUD_MAX_FONT_SIZE = Setting('TAGS_CLOUD_MAX_FONT_SIZE', 25, VIEW_SET, dict(
+label = _("Tags cloud max font size"),
+help_text = _("Used to calculate the font size of the tags in the cloud widget.")))
+
 RECENT_AWARD_SIZE = Setting('RECENT_AWARD_SIZE', 15, VIEW_SET, dict(
 label = _("Recent awards block size"),
 help_text = _("The number of awards to display in the recent awards block in the front page.")))
@@ -28,3 +50,4 @@ help_text = _("If you check this the latest activity will be updated when editin
 LIMIT_RELATED_TAGS = Setting('LIMIT_RELATED_TAGS', 0, VIEW_SET, dict(
 label = _("Limit related tags block"),
 help_text = _("Limit related tags block size in questions list pages. Set to 0 to display all all tags.")))
+
index 6ec6fc870d4ffca33bd87cd40b90e7e0af9757db..40209c0dcdbcc06e4745976dd1f6cbac1efb61d4 100644 (file)
@@ -1,11 +1,14 @@
-{% load i18n %}\r
+{% load i18n extra_tags %}\r
+{% declare %}\r
+    show_tags_in_a_cloud = settings.SHOW_TAGS_IN_A_CLOUD\r
+{% enddeclare %}\r
 \r
 <div class="boxC">\r
        <h3>{% trans "Recent tags" %}</h3>\r
        <div class="body">\r
          <div class="tags" id="recent-tags">\r
         {% for tag in tags %}\r
-            <a rel="tag" class="tag-link-{{ tag.name }}" title="{% blocktrans with tag.name as tagname %}see questions tagged '{{tagname}}'{% endblocktrans %}" href="{% url tag_questions tag.name|urlencode %}">{{ tag.name }}</a>\r
+            <a rel="tag"{% if show_tags_in_a_cloud %} style="font-size: {% get_tag_font_size tag %}px;"{% endif %} class="tag-link-{{ tag.name }}" title="{% blocktrans with tag.name as tagname %}see questions tagged '{{tagname}}'{% endblocktrans %}" href="{% url tag_questions tag.name|urlencode %}">{{ tag.name }}</a>\r
         {% endfor %}\r
         </div>\r
         <div class="more"><a href="{% url tags %}">{% trans "popular tags" %} </a> </div>\r
index cf9cee096da01cb96ad306bf377013fdcf74221d..9fa31f8ade7f3fe4533d9eccead813d7e9542908 100644 (file)
@@ -170,6 +170,24 @@ def media(url):
         url = url_prefix + url
         return url
 
+@register.simple_tag
+def get_tag_font_size(tag):
+    occurrences_of_current_tag = tag.used_count
+
+    # Occurrences count settings
+    min_occurs = int(settings.TAGS_CLOUD_MIN_OCCURS)
+    max_occurs = int(settings.TAGS_CLOUD_MAX_OCCURS)
+
+    # Font size settings
+    min_font_size = int(settings.TAGS_CLOUD_MIN_FONT_SIZE)
+    max_font_size = int(settings.TAGS_CLOUD_MAX_FONT_SIZE)
+
+    # Calculate the font size of the tag according to the occurrences count
+    weight = (math.log(occurrences_of_current_tag)-math.log(min_occurs))/(math.log(max_occurs)-math.log(min_occurs))
+    font_size_of_current_tag = min_font_size + int(math.floor((max_font_size-min_font_size)*weight))
+
+    return font_size_of_current_tag
+
 class ItemSeparatorNode(template.Node):
     def __init__(self, separator):
         sep = separator.strip()
@@ -277,6 +295,7 @@ class DeclareNode(template.Node):
                 d['os'] = os
                 d['html'] = html
                 d['reverse'] = reverse
+                d['settings'] = settings
                 d['smart_str'] = smart_str
                 d['smart_unicode'] = smart_unicode
                 d['force_unicode'] = force_unicode