Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DESCRIPTION.rst 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. ============
  2. Instructions
  3. ============
  4. This is a reusable django app which adds some templatetags to django-taggit_.
  5. This is a fork the application "django-taggit-templatetags".
  6. django-taggit-templatetags2 requires Django 1.6 or greater.
  7. The application works well under python 2.7 and 3.x
  8. Installation
  9. ============
  10. Just install ``django-taggit-templatetags2`` via ``pip``::
  11. $ pip install django-taggit-templatetags2
  12. After installing and configuring django-taggit_, just add ``taggit_templatetags2`` to your ``INSTALLED_APPS`` in your ``settings.py``::
  13. INSTALLED_APPS = (
  14. ...
  15. 'taggit_templatetags2',
  16. ...
  17. )
  18. Usage
  19. =====
  20. Now there are some templatetags enabled, at the moment only to create lists of
  21. tags and tag-clouds.
  22. In your templates, you need to load ``taggit_templatetags2_tags``::
  23. ...
  24. {% load taggit_templatetags2_tags %}
  25. ...
  26. ---------
  27. Tagdetail
  28. ---------
  29. List of tags for the selected object::
  30. {% get_tags_for_object <some_model_object> as "tags" %}
  31. --------
  32. Taglists
  33. --------
  34. After loading ``taggit_templatetags2_tags`` you can create a list of tags for the
  35. whole project (in the sense of djangoproject), for an app (in the sense of djangoapp),
  36. for a model-class (to get a list for an instance of a model, just use its tag-field).
  37. For the tags of a project, just do::
  38. {% get_taglist as tags %}
  39. For the tags of an app, just do::
  40. {% get_taglist as tags for 'yourapp' %}
  41. For the tags of a model, just do::
  42. {% get_taglist as tags for 'yourapp.yourmodel' %}
  43. You can also customize the name of the tags manager in your model (the default is *tags*)::
  44. {% get_taglist as tags for 'yourapp.yourmodel:yourtags' %}
  45. No matter what you do, you have a list of tags in the ``tags`` template variable.
  46. You can now iterate over it::
  47. <ul>
  48. {% for tag in tags %}
  49. <li>{{tag}} ({{tag.num_times}})</li>
  50. {% endfor %}
  51. </ul>
  52. As you can see, each tag has an attribute ``num_times`` which declares how many
  53. times it was used. The list of tags is sorted descending by ``num_times``.
  54. Inclusion-Tag
  55. -------------
  56. For convenience, there's an inclusion-tag. It's used analogue. For example,
  57. for a taglist of a model, just do::
  58. {% include_taglist 'yourapp.yourmodel' %}
  59. ---------
  60. Tagclouds
  61. ---------
  62. A very popular way to navigate through tags is a tagcloud_. This app provides
  63. some tags for that::
  64. {% get_tagcloud as tags %}
  65. or::
  66. {% get_tagcloud as tags for 'yourapp' %}
  67. or::
  68. {% get_tagcloud as tags for 'yourapp.yourmodel' %}
  69. respectivly. The resulting list of tags is ordered by their ``name`` attribute.
  70. Besides the ``num_items`` attribute, there's a ``weight`` attribute. Its maximum
  71. and minimum may be specified as the settings_ section reads.
  72. Inclusion-Tag: tag cloud
  73. ------------------------
  74. Even for the tagcloud there's an inclusion-tag. For example, for a tagcloud
  75. of a model, just do::
  76. {% include_tagcloud 'yourapp.yourmodel' %}
  77. Inclusion-Tag: tag canvas
  78. -------------------------
  79. TagCanvas_ is a Javascript class which will draw and animate a HTML5 canvas
  80. based tag cloud. You can use this library in your application as follows::
  81. <!-- Somewhere before the tag include_tagcanvas. For example, in the "head". -->
  82. {% include "taggit_templatetags2/tagcanvas_include_js_static.html" %}
  83. {% include_tagcanvas 'element_id' 'width px' 'height px' 'some-url-name' 'yourapp.yourmodel' %}
  84. - element_id - name to create identifiers for html tags
  85. - some-url-name - url to view a list of objects for the selected tag. Default: *tagcanvas-list*.
  86. For example, some-url-name='myurlname', then it must be an entry in urls.py
  87. file like this::
  88. from taggit_templatetags2.views import TagCanvasListView
  89. urlpatterns = patterns(
  90. ...
  91. url(r'^tag-list/(?P<tag_id>.*)/(?P<tag_slug>.*)/',
  92. TagCanvasListView.as_view(), name='myurlname'),
  93. )
  94. Or you can use the default view, and then you have to add the following things:
  95. - in urls.py::
  96. from taggit_templatetags2 import urls as taggit_templatetags2_urls
  97. urlpatterns = patterns(
  98. ...
  99. url(r'^tags/', include('taggit_templatetags2.urls')),
  100. )
  101. - override template "taggit_templatetags2/tagcanvas_base.html" and
  102. - override template "taggit_templatetags2/tagcanvas_list_item.html" to customize the look
  103. To use this inclusion-tag, make sure that 'django.core.context_processors.static'
  104. appears somewhere in your TEMPLATE_CONTEXT_PROCESSORS setting.
  105. .. _settings:
  106. Settings
  107. ========
  108. There are a few settings to be set:
  109. TAGGIT_TAGCLOUD_MIN (default: 1.0)
  110. This specifies the minimum of the weight attribute of a tagcloud's tags.
  111. TAGGIT_TAGCLOUD_MAX (default: 6.0)
  112. This specifies the maximum of the weight attribute of a tagcloud's tags.
  113. If you want to use the weight as font-sizes, just do as follows::
  114. <font size={{tag.weight|floatformat:0}}>{{tag}}</font>
  115. So the weights are converted to integer values.
  116. If you're using your own Tag and/or TaggedItem models rather than the default
  117. ones (`Custom Tagging`_), you can specify a tuple for each model (app,model_name)
  118. TAGGIT_TAG_MODEL = ('myapp','MyTag')
  119. default: ('taggit', 'Tag')
  120. TAGGIT_TAGGED_ITEM_MODEL = ('myapp','MyTaggedItem')
  121. default: ('taggit', 'TaggedItem')
  122. TAGGIT_LIMIT = 234
  123. Number items for tag cloud.
  124. default: 10
  125. TAGGIT_TAG_LIST_ORDER_BY = 'name'
  126. Order for the queryset used to generate the list.
  127. default: -num_times
  128. TAGGIT_TAG_CLOUD_ORDER_BY = '-num_times'
  129. Order for the queryset used to generate the list.
  130. default: name
  131. Testing
  132. =======
  133. Clone code repository::
  134. $ git clone https://github.com/fizista/django-taggit-templatetags.git
  135. Installation dependencies needed to test the application::
  136. $ pip install -e <path to the application>[tests]
  137. Starting tests::
  138. $ python ./develop.py test
  139. Starting test coverage::
  140. $ python ./develop.py manage test
  141. Starting tox tests::
  142. $ tox
  143. Thanks
  144. ======
  145. Thanks to the python- and django-community, in particular to `Alex Gaynor`_,
  146. the inventor of django-taggit_ and a wonderful guy to argue with.
  147. Thanks to `Mathijs de Bruin`_ as well for his helpful pull requests.
  148. .. _django-taggit: http://pypi.python.org/pypi/django-taggit
  149. .. _tagcloud: http://www.wikipedia.org/wiki/Tagcloud
  150. .. _Alex Gaynor: http://alexgaynor.net/
  151. .. _Mathijs de Bruin: http://github.com/dokterbob
  152. .. _Custom Tagging: http://django-taggit.readthedocs.org/en/latest/custom_tagging.html
  153. .. _TagCanvas: http://www.goat1000.com/tagcanvas.php