Permalink
Browse files

Moved over gravatar code and fleshed out the important bits.

git-svn-id: http://django-gravatar.googlecode.com/svn/trunk@2 6ccaa926-6f50-0410-9a0f-7d6703ace4a5
  • Loading branch information...
1 parent 06e14de commit b89feba468c6ad1ddab95aff35724357c426a88b mtrier committed Jun 24, 2008
View
No changes.
View
@@ -0,0 +1,39 @@
+Thanks for downloading django-gravatar!
+
+To install it, first use subversion to check out the source code:
+
+ svn checkout http://django-gravatar.googlecode.com/svn/trunk/ django-gravatar
+
+Now, link the included ``gravatar`` directory to your pythonpath. On Debian
+variants, it would look something like this.
+
+ sudo ln -s `pwd`/django-gravatar/gravatar /usr/lib/python2.5/site-packages/
+
+To use it with a Django installation, first place 'gravatar' in the INSTALLED_APPS
+tuple of your settings.py file like so:
+
+ INSTALLED_APPS = (
+ # ...
+ 'gravatar',
+ )
+
+Here is sample usage in a template.
+
+ {% load gravatar %}
+ {% gravatar blogs.author 40 %}
+
+In the previous example, a gravatar will be displayed for the specified author
+at a size of 40px square. The second argument is optional and if not supplied
+the gravatar image will be 80px square, the default gravatar image size.
+
+In addition to supplying a user object, you can also provide a username as a
+string. For instance:
+
+ {% gravatar 'jtauber' %}
+
+If supplied in this fashion then the user object is loaded based on the
+username information.
+
+Note that this application requires Python 2.3 or later, and Django later than
+0.96. You can obtain Python from http://www.python.org/ and Django from
+http://www.djangoproject.com/.
View
@@ -0,0 +1,29 @@
+Copyright (c) 2008, James Tauber
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of the author nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
View
@@ -0,0 +1,10 @@
+=======================
+django-gravatar
+=======================
+
+django-gravatar makes it easy to add gravatar support to your Django
+application through the addition of a template tag.
+
+For installation instructions, read INSTALL.txt.
+
+Visit the google code page at http://django-gravatar.googlecode.com/
View
No changes.
View
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
No changes.
@@ -0,0 +1,26 @@
+from django import template
+from django.utils.html import escape
+from django.contrib.auth.models import User
+
+import urllib, hashlib
+
+register = template.Library()
+
+def gravatar(user, size=80):
+ if not isinstance(user, User):
+ try:
+ user = User.objects.get(username=user)
+ email = user.email
+ username = user.username
+ except User.DoesNotExist:
+ email = "?"
+ username = user
+ else:
+ email = user.email
+ username = user.username
+
+ gravatar_url = "http://www.gravatar.com/avatar.php?"
+ gravatar_url += urllib.urlencode({'gravatar_id':hashlib.md5(email).hexdigest(), 'size':str(size)})
+ return """<img src="%s" alt="gravatar for %s" />""" % (escape(gravatar_url), username)
+
+register.simple_tag(gravatar)
View
@@ -0,0 +1 @@
+# Create your views here.

0 comments on commit b89feba

Please sign in to comment.