Login

copyright_since

Author:
xplozive
Posted:
March 12, 2009
Language:
Python
Version:
1.0
Tags:
datetime date template-tag formatting copyright copyright-formatting copyright-year
Score:
1 (after 7 ratings)

Example usage: {% copyright_since 2008 %}, {% copyright_since 2009 %}

Output: © 2008—2009, © 2009

Use this templatetag in your footer to achieve proper formatting of copyright notice.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django import template
import datetime

register = template.Library ()

@register.simple_tag
def copyright_since(since):
    now = datetime.datetime.now().year
    if since != now:
        return u'© %d—%d' % (int(since), now)
    return u'© %d' % now

More like this

  1. Send templated email with text | html | optional files by grillermo 3 years, 6 months ago
  2. server with debugging backdoor by teepark 6 years, 7 months ago
  3. ScriptPrefixMiddleware by shellsage 5 years, 7 months ago
  4. CustomChoiceField, Selectable label field version of ModelChoiceField by mauro 7 years, 1 month ago
  5. Currency Object by Rupe 5 years, 10 months ago

Comments

bartTC (on March 12, 2009):

I don't see any need for this. I just use: © 2008—{% now "Y" %}

#

David (on March 12, 2009):

You could probably simplify this even further by using a simple_tag. Something like:

@register.simple_tag
def copyright_since(since):
    now = datetime.datetime.now().year
    if since != now:
        return (u'© %d—%d' % (int(since), now)
    else:
        return (u'© %d' % now)

#

david_bgk (on March 12, 2009):

@David: a filter looks even more simple to me.

#

xplozive (on March 12, 2009):

david_bgk, bartTC: lol, 2009-2009?

#

xplozive (on March 12, 2009):

David: thanks, didn't know about simple_tag

#

xplozive (on March 12, 2009):

David: I've replaced my original snippet code with yours one, works fine

#

adamlofts (on March 12, 2009):

Don't you actually have to make changes to the site to (legally) update the copyright label?

#

xplozive (on March 12, 2009):

adamlofts: I think it's just the notice so it doesn't have any legal power

#

Killarny (on March 13, 2009):

This is handy, thanks :)

Improved formatting slightly and fixed some problems with HTML output:

@register.simple_tag
def copyright_since(since):
    now = datetime.datetime.now().year
    if since != now:
        return u'© %d—%d' % (int(since), now)
    return u'© %d' % now

#

Please login first before commenting.