Commits

Bela Hausmann committed 4668e84

Updated template tags and added new tag: license_short_link

  • Participants
  • Parent commits 5ff88c6

Comments (0)

Files changed (4)

licenses/models.py

     def __unicode__(self):
         return self.name
 
-    #@property
     def url(self):
         return self.website
     url = property(url)
         ordering = ('name', )
         verbose_name = _('license')
         verbose_name_plural = _('licenses')
+
+    def shortest(self):
+        return self.abbreviation or self.name
+    shortest = property(shortest)

licenses/templates/licenses/logo.html

-<a href="{{ url }}" rel="license"><img src="{{ img }}" title="{{ name }}" alt="{{ name }}" /></a>
+<a href="{{ url }}" rel="license"><img src="{{ img }}" alt="{{ abbr }}" title="{{ name }}" /></a>

licenses/templates/licenses/short_link.html

+<a href="{{ url }}" rel="license">{{ abbr }}</a>

licenses/templatetags/licensing.py

 
 def get_license_by_abbr(parser, token):
     '''
+        Get a license via it's abbreviation and save it to ´varname´.
+
         Usage: {% get_license_by_abbr "short_name" as varname %}
+        Quotation marks are optional.
     '''
     return GetLicenseNode.handle_token(parser, token, field='abbreviation')
-get_license_by_abbr = register.tag(get_license_by_abbr)
+register.tag('get_license_by_abbr', get_license_by_abbr)
+register.tag('get_license_by_abbreviation', get_license_by_abbr)
 
 
 def get_license_by_slug(parser, token):
     '''
+        Get a license via it's slug and save it to ´varname´.
+
         Usage: {% get_license_by_slug "slug" as varname %}
+        Quotation marks are optional.
     '''
     return GetLicenseNode.handle_token(parser, token, field='slug')
-get_license_by_slug = register.tag(get_license_by_slug)
+register.tag('get_license_by_slug', get_license_by_slug)
 
 
 def license_link(license):
     '''
+        Displays the license as a hyperlink.
+
         Usage {{ license|license_link }}
     '''
     return render_to_string('licenses/link.html', {
         'name': conditional_escape(license.name),
         'url': conditional_escape(license.url),
     })
-register.filter(license_link)
+register.filter('license_link', license_link)
+
+
+def license_short_link(license):
+    '''
+        Displays the license as a hyperlink and uses the abbreviation as
+        innerHtml if available.
+
+        Usage {{ license|license_short_link }}
+    '''
+    return render_to_string('licenses/short_link.html', {
+        'abbr': conditional_escape(license.shortest),
+        'url': conditional_escape(license.url),
+    })
+register.filter('license_short_link', license_short_link)
+register.filter('license_abbr_link', license_short_link)
 
 
 def license_logo(license):
     '''
+        Displays the license as a hyperlink with an images as innerHtml.
+
         Usage {{ license|license_logo }}
     '''
     return render_to_string('licenses/logo.html', {
         'name': conditional_escape(license.name),
         'url': conditional_escape(license.url),
+        'abbr': conditional_escape(license.shortest),
         'img': conditional_escape(license.logo),
     })
-register.filter(license_logo)
+register.filter('license_logo', license_logo)