[Python-modules-commits] [python-django-gravatar2] 01/10: Import python-django-gravatar2_1.4.0.orig.tar.gz

Pierre-Elliott Bécue peb-guest at moszumanska.debian.org
Mon Jul 31 11:03:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

peb-guest pushed a commit to branch master
in repository python-django-gravatar2.

commit 4e6c0b28fbc6bc9891f891b697fc4a3bbd9a5082
Author: Pierre-Elliott Bécue <becue at crans.org>
Date:   Thu Mar 24 19:45:58 2016 +0100

    Import python-django-gravatar2_1.4.0.orig.tar.gz
---
 LICENSE                                  |  19 ++++
 MANIFEST.in                              |   3 +
 PKG-INFO                                 | 145 ++++++++++++++++++++++++++
 README                                   |   1 +
 README.rst                               | 103 +++++++++++++++++++
 django_gravatar/__init__.py              |   0
 django_gravatar/compat.py                |  24 +++++
 django_gravatar/helpers.py               | 108 +++++++++++++++++++
 django_gravatar/models.py                |   1 +
 django_gravatar/templatetags/__init__.py |   0
 django_gravatar/templatetags/gravatar.py |  57 +++++++++++
 django_gravatar/tests.py                 | 171 +++++++++++++++++++++++++++++++
 django_gravatar/views.py                 |   1 +
 setup.cfg                                |   8 ++
 setup.py                                 |  32 ++++++
 15 files changed, 673 insertions(+)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..915e524
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2013 Tristan Waddington <tristan.waddington at gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..9839ade
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,3 @@
+include README
+include README.rst
+include LICENSE
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..88d386f
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,145 @@
+Metadata-Version: 1.1
+Name: django-gravatar2
+Version: 1.4.0
+Summary: Essential Gravatar support for Django. Features helper methods, templatetags and a full test suite!
+Home-page: https://github.com/twaddington/django-gravatar
+Author: Tristan Waddington
+Author-email: tristan.waddington at gmail.com
+License: Copyright (c) 2013 Tristan Waddington <tristan.waddington at gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+Description: django-gravatar
+        ================
+        
+        .. image:: https://secure.travis-ci.org/twaddington/django-gravatar.png
+            :target: https://travis-ci.org/twaddington/django-gravatar
+        
+        .. image:: https://img.shields.io/pypi/dm/django-gravatar2.svg
+            :target: https://pypi.python.org/pypi/django-gravatar2
+        
+        A lightweight django-gravatar app. Includes helper methods for interacting with gravatars outside of template code.
+        
+        If you like this library and it's saved you some time, please consider
+        supporting further development with a `Gittip donation`_!
+        
+        Features
+        --------
+        
+        - Helper methods for constructing a gravatar url and checking an email for an existing gravatar
+        - Templatetags for generating a gravatar url or gravatar <img> tag.
+        - Full test suite!
+        
+        Installing
+        ----------
+        Install from PyPi:
+        
+        You can pip install the app directly from GitHub:
+        
+        ::
+        
+            $ pip install git+git://github.com/twaddington/django-gravatar.git#egg=DjangoGravatar
+        
+        Alternatively, you can now install directly from PyPi!
+        
+        ::
+        
+            $ pip install django-gravatar2
+        
+        Make sure you install `django-gravatar2 <http://pypi.python.org/pypi/django-gravatar2>`_ as
+        there are several other incompatible django-gravatar libraries available.
+        
+        Add django_gravatar to your INSTALLED_APPS in settings.py:
+        
+        ::
+        
+            INSTALLED_APPS = (
+                # ...
+                'django_gravatar',
+            )
+        
+        Basic Usage
+        -----------
+        Use in code:
+        
+        ::
+        
+            from django_gravatar.helpers import get_gravatar_url, has_gravatar, get_gravatar_profile_url, calculate_gravatar_hash
+        
+            url = get_gravatar_url('alice at example.com', size=150)
+            gravatar_exists = has_gravatar('bob at example.com')
+            profile_url = get_gravatar_profile_url('alice at example.com')
+            email_hash = calculate_gravatar_hash('alice at example.com')
+        
+        Use in templates:
+        
+        ::
+        
+            {% load gravatar %}
+        
+            {% gravatar_url user.email 150 %}
+            # https://secure.gravatar.com/avatar/hash.jpg?size=150
+        
+            {% gravatar user.email 150 %}
+            # <img class="gravatar" src="https://secure.gravatar.com/avatar/hash.jpg?size=150" width="150" height="150" alt="" />
+        
+            {% gravatar user.email 150 "user at example.com" %}
+            # <img class="gravatar" src="https://secure.gravatar.com/avatar/hash.jpg?size=150" width="150" height="150" alt="user at example.com" />
+        
+            {% gravatar_profile_url user.email %}
+            # https://secure.gravatar.com/hash
+        
+        Configuring
+        -----------
+        The following options can be configured in your settings.py:
+        
+        GRAVATAR_URL            # Gravatar base url. Defaults to 'http://www.gravatar.com/'
+        
+        GRAVATAR_SECURE_URL     # Gravatar base secure https url. Defaults to 'https://secure.gravatar.com/'
+        
+        GRAVATAR_DEFAULT_SIZE   # Gravatar size in pixels. Defaults to '80'
+        
+        GRAVATAR_DEFAULT_IMAGE  # An image url or one of the following: 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'. Defaults to 'mm'
+        
+        GRAVATAR_DEFAULT_RATING # One of the following: 'g', 'pg', 'r', 'x'. Defaults to 'g'
+        
+        GRAVATAR_DEFAULT_SECURE # True to use https by default, False for plain http. Defaults to True
+        
+        Contributing
+        ------------
+        Feel free to `fork django-gravatar <https://github.com/twaddington/django-gravatar>`_
+        on GitHub! We'd love to see your pull requests. Please make sure you run
+        tests before submitting a patch.
+        
+        .. _Gittip donation: https://www.gittip.com/twaddington/ 
+        
+Keywords: django gravatar avatar
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Environment :: Web Environment
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Framework :: Django
diff --git a/README b/README
new file mode 100644
index 0000000..66cd09b
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+Please see README.rst.
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..c8739dc
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,103 @@
+django-gravatar
+================
+
+.. image:: https://secure.travis-ci.org/twaddington/django-gravatar.png
+    :target: https://travis-ci.org/twaddington/django-gravatar
+
+.. image:: https://img.shields.io/pypi/dm/django-gravatar2.svg
+    :target: https://pypi.python.org/pypi/django-gravatar2
+
+A lightweight django-gravatar app. Includes helper methods for interacting with gravatars outside of template code.
+
+If you like this library and it's saved you some time, please consider
+supporting further development with a `Gittip donation`_!
+
+Features
+--------
+
+- Helper methods for constructing a gravatar url and checking an email for an existing gravatar
+- Templatetags for generating a gravatar url or gravatar <img> tag.
+- Full test suite!
+
+Installing
+----------
+Install from PyPi:
+
+You can pip install the app directly from GitHub:
+
+::
+
+    $ pip install git+git://github.com/twaddington/django-gravatar.git#egg=DjangoGravatar
+
+Alternatively, you can now install directly from PyPi!
+
+::
+
+    $ pip install django-gravatar2
+
+Make sure you install `django-gravatar2 <http://pypi.python.org/pypi/django-gravatar2>`_ as
+there are several other incompatible django-gravatar libraries available.
+
+Add django_gravatar to your INSTALLED_APPS in settings.py:
+
+::
+
+    INSTALLED_APPS = (
+        # ...
+        'django_gravatar',
+    )
+
+Basic Usage
+-----------
+Use in code:
+
+::
+
+    from django_gravatar.helpers import get_gravatar_url, has_gravatar, get_gravatar_profile_url, calculate_gravatar_hash
+
+    url = get_gravatar_url('alice at example.com', size=150)
+    gravatar_exists = has_gravatar('bob at example.com')
+    profile_url = get_gravatar_profile_url('alice at example.com')
+    email_hash = calculate_gravatar_hash('alice at example.com')
+
+Use in templates:
+
+::
+
+    {% load gravatar %}
+
+    {% gravatar_url user.email 150 %}
+    # https://secure.gravatar.com/avatar/hash.jpg?size=150
+
+    {% gravatar user.email 150 %}
+    # <img class="gravatar" src="https://secure.gravatar.com/avatar/hash.jpg?size=150" width="150" height="150" alt="" />
+
+    {% gravatar user.email 150 "user at example.com" %}
+    # <img class="gravatar" src="https://secure.gravatar.com/avatar/hash.jpg?size=150" width="150" height="150" alt="user at example.com" />
+
+    {% gravatar_profile_url user.email %}
+    # https://secure.gravatar.com/hash
+
+Configuring
+-----------
+The following options can be configured in your settings.py:
+
+GRAVATAR_URL            # Gravatar base url. Defaults to 'http://www.gravatar.com/'
+
+GRAVATAR_SECURE_URL     # Gravatar base secure https url. Defaults to 'https://secure.gravatar.com/'
+
+GRAVATAR_DEFAULT_SIZE   # Gravatar size in pixels. Defaults to '80'
+
+GRAVATAR_DEFAULT_IMAGE  # An image url or one of the following: 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'. Defaults to 'mm'
+
+GRAVATAR_DEFAULT_RATING # One of the following: 'g', 'pg', 'r', 'x'. Defaults to 'g'
+
+GRAVATAR_DEFAULT_SECURE # True to use https by default, False for plain http. Defaults to True
+
+Contributing
+------------
+Feel free to `fork django-gravatar <https://github.com/twaddington/django-gravatar>`_
+on GitHub! We'd love to see your pull requests. Please make sure you run
+tests before submitting a patch.
+
+.. _Gittip donation: https://www.gittip.com/twaddington/ 
diff --git a/django_gravatar/__init__.py b/django_gravatar/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/django_gravatar/compat.py b/django_gravatar/compat.py
new file mode 100644
index 0000000..3bac7e3
--- /dev/null
+++ b/django_gravatar/compat.py
@@ -0,0 +1,24 @@
+"""
+This module provides compatibility with older versions of Django and Python
+"""
+
+try:
+    from urllib.parse import urlparse, parse_qs, quote_plus, urlencode
+except ImportError:     # Python 2
+    from urlparse import urlparse, parse_qs
+    from urllib import quote_plus, urlencode
+
+try:
+    from urllib.request import Request, urlopen
+except ImportError:     # Python 2
+    from urllib2 import Request, urlopen
+
+try:
+    from urllib.error import HTTPError
+except ImportError:     # Python 2
+    from urllib2 import HTTPError
+
+try:
+    from urllib.error import URLError
+except ImportError:     # Python 2
+    from urllib2 import URLError
diff --git a/django_gravatar/helpers.py b/django_gravatar/helpers.py
new file mode 100644
index 0000000..3abeaa4
--- /dev/null
+++ b/django_gravatar/helpers.py
@@ -0,0 +1,108 @@
+import hashlib
+
+from django.conf import settings
+
+from .compat import urlencode, urlopen, Request, HTTPError, URLError
+
+# These options can be used to change the default image if no gravatar is found
+GRAVATAR_DEFAULT_IMAGE_404 = '404'
+GRAVATAR_DEFAULT_IMAGE_MYSTERY_MAN = 'mm'
+GRAVATAR_DEFAULT_IMAGE_IDENTICON = 'identicon'
+GRAVATAR_DEFAULT_IMAGE_MONSTER = 'monsterid'
+GRAVATAR_DEFAULT_IMAGE_WAVATAR = 'wavatar'
+GRAVATAR_DEFAULT_IMAGE_RETRO = 'retro'
+
+# These options can be used to restrict gravatar content
+GRAVATAR_RATING_G = 'g'
+GRAVATAR_RATING_PG = 'pg'
+GRAVATAR_RATING_R = 'r'
+GRAVATAR_RATING_X = 'x'
+
+# Get Gravatar base url from settings.py
+GRAVATAR_URL = getattr(settings, 'GRAVATAR_URL', 'http://www.gravatar.com/')
+GRAVATAR_SECURE_URL = getattr(settings, 'GRAVATAR_SECURE_URL', 'https://secure.gravatar.com/')
+
+# Get user defaults from settings.py
+GRAVATAR_DEFAULT_SIZE = getattr(settings, 'GRAVATAR_DEFAULT_SIZE', 80)
+GRAVATAR_DEFAULT_IMAGE = getattr(settings, 'GRAVATAR_DEFAULT_IMAGE',
+        GRAVATAR_DEFAULT_IMAGE_MYSTERY_MAN)
+GRAVATAR_DEFAULT_RATING = getattr(settings, 'GRAVATAR_DEFAULT_RATING',
+        GRAVATAR_RATING_G)
+GRAVATAR_DEFAULT_SECURE = getattr(settings, 'GRAVATAR_DEFAULT_SECURE', True)
+
+
+def calculate_gravatar_hash(email):
+    # Calculate the email hash
+    enc_email = email.strip().lower().encode("utf-8")
+    email_hash = hashlib.md5(enc_email).hexdigest()
+    return email_hash
+
+
+def get_gravatar_url(email, size=GRAVATAR_DEFAULT_SIZE, default=GRAVATAR_DEFAULT_IMAGE,
+        rating=GRAVATAR_DEFAULT_RATING, secure=GRAVATAR_DEFAULT_SECURE):
+    """
+    Builds a url to a gravatar from an email address.
+
+    :param email: The email to fetch the gravatar for
+    :param size: The size (in pixels) of the gravatar to fetch
+    :param default: What type of default image to use if the gravatar does not exist
+    :param rating: Used to filter the allowed gravatar ratings
+    :param secure: If True use https, otherwise plain http
+    """
+    if secure:
+        url_base = GRAVATAR_SECURE_URL
+    else:
+        url_base = GRAVATAR_URL
+
+    # Calculate the email hash
+    email_hash = calculate_gravatar_hash(email)
+
+    # Build querystring
+    query_string = urlencode({
+        's': str(size),
+        'd': default,
+        'r': rating,
+    })
+
+    # Build url
+    url = '{base}avatar/{hash}.jpg?{qs}'.format(base=url_base,
+            hash=email_hash, qs=query_string)
+
+    return url
+
+
+def has_gravatar(email):
+    """
+    Returns True if the user has a gravatar, False if otherwise
+    """
+    # Request a 404 response if the gravatar does not exist
+    url = get_gravatar_url(email, default=GRAVATAR_DEFAULT_IMAGE_404)
+
+    # Verify an OK response was received
+    try:
+        request = Request(url)
+        request.get_method = lambda: 'HEAD'
+        return 200 == urlopen(request).code
+    except (HTTPError, URLError):
+        return False
+
+
+def get_gravatar_profile_url(email, secure=GRAVATAR_DEFAULT_SECURE):
+    """
+    Builds a url to a gravatar profile from an email address.
+
+    :param email: The email to fetch the gravatar for
+    :param secure: If True use https, otherwise plain http
+    """
+    if secure:
+        url_base = GRAVATAR_SECURE_URL
+    else:
+        url_base = GRAVATAR_URL
+
+    # Calculate the email hash
+    email_hash = calculate_gravatar_hash(email)
+
+    # Build url
+    url = '{base}{hash}'.format(base=url_base, hash=email_hash)
+
+    return url
diff --git a/django_gravatar/models.py b/django_gravatar/models.py
new file mode 100644
index 0000000..6c4454a
--- /dev/null
+++ b/django_gravatar/models.py
@@ -0,0 +1 @@
+"""Stub models.py"""
diff --git a/django_gravatar/templatetags/__init__.py b/django_gravatar/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/django_gravatar/templatetags/gravatar.py b/django_gravatar/templatetags/gravatar.py
new file mode 100644
index 0000000..bd41d14
--- /dev/null
+++ b/django_gravatar/templatetags/gravatar.py
@@ -0,0 +1,57 @@
+from django import template
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
+
+from ..helpers import GRAVATAR_DEFAULT_SIZE, get_gravatar_profile_url, get_gravatar_url
+
+# Get template.Library instance
+register = template.Library()
+
+
+def gravatar_url(user_or_email, size=GRAVATAR_DEFAULT_SIZE):
+    """ Builds a gravatar url from an user or email """
+    if hasattr(user_or_email, 'email'):
+        email = user_or_email.email
+    else:
+        email = user_or_email
+
+    try:
+        return escape(get_gravatar_url(email=email, size=size))
+    except:
+        return ''
+
+
+def gravatar(user_or_email, size=GRAVATAR_DEFAULT_SIZE, alt_text='', css_class='gravatar'):
+    """ Builds an gravatar <img> tag from an user or email """
+    if hasattr(user_or_email, 'email'):
+        email = user_or_email.email
+    else:
+        email = user_or_email
+
+    try:
+        url = escape(get_gravatar_url(email=email, size=size))
+    except:
+        return ''
+
+    return mark_safe(
+        '<img class="{css_class}" src="{src}" width="{width}"'
+        ' height="{height}" alt="{alt}" />'.format(
+            css_class=css_class, src=url, width=size, height=size, alt=alt_text
+        )
+    )
+
+
+def gravatar_profile_url(user_or_email):
+    if hasattr(user_or_email, 'email'):
+        email = user_or_email.email
+    else:
+        email = user_or_email
+
+    try:
+        return get_gravatar_profile_url(email)
+    except:
+        return ''
+
+register.simple_tag(gravatar_url)
+register.simple_tag(gravatar)
+register.simple_tag(gravatar_profile_url)
diff --git a/django_gravatar/tests.py b/django_gravatar/tests.py
new file mode 100644
index 0000000..9912104
--- /dev/null
+++ b/django_gravatar/tests.py
@@ -0,0 +1,171 @@
+from django.template import Context, Template
+from django.test import TestCase
+from django.utils.html import escape
+
+from .compat import parse_qs, quote_plus, urlparse
+from .helpers import *
+
+
+class TestGravatarHelperMethods(TestCase):
+
+    def test_gravatar_hash_generation(self):
+        """
+        Verify the generation of hash from email string.
+        """
+        email = "MyEmailAddress at example.com"
+        email_hash = "0bc83cb571cd1c50ba6f3e8a78ef1346"
+
+        self.assertEqual(calculate_gravatar_hash(email), email_hash)
+        self.assertEqual(calculate_gravatar_hash(email), calculate_gravatar_hash(email.lower()))
+
+    def test_gravatar_url(self):
+        """
+        Verify that the gravatar_url method returns the expected output.
+        """
+        email = "joe at example.com"
+        email_upper = "JOE at example.com"
+        email_strip = "   JOE at example.com "
+
+        # Construct the url
+        url = get_gravatar_url(email)
+
+        # Verify email is properly sanitized
+        self.assertEqual(url, get_gravatar_url(email_upper))
+        self.assertEqual(url, get_gravatar_url(email_strip))
+
+        # Parse query string from url
+        urlp = urlparse(url)
+        qs = parse_qs(urlp.query)
+
+        # Verify the correct query arguments are included with the proper defaults
+        self.assertTrue('s' in qs)
+        self.assertTrue('d' in qs)
+        self.assertTrue('r' in qs)
+
+        self.assertEqual(qs.get('s').pop(), str(GRAVATAR_DEFAULT_SIZE))
+        self.assertEqual(qs.get('d').pop(), GRAVATAR_DEFAULT_IMAGE)
+        self.assertEqual(qs.get('r').pop(), GRAVATAR_DEFAULT_RATING)
+
+        # Verify the correct protocol is used
+        if GRAVATAR_DEFAULT_SECURE:
+            self.assertTrue(GRAVATAR_SECURE_URL in url)
+        else:
+            self.assertTrue(GRAVATAR_URL in url)
+
+        # Verify that a url value for default is urlencoded
+        default_url = 'https://www.example.com/default.jpg'
+        url = get_gravatar_url(email, default=default_url)
+
+        # Verify urlencoding
+        self.assertTrue(quote_plus(default_url) in url)
+
+    def test_has_gravatar(self):
+        """
+        Verify that the has_gravatar helper method correctly
+        determines if a user has a gravatar or not.
+        """
+        bad_email = 'eve at example.com'
+        good_email = 'matt at automattic.com'
+
+        self.assertFalse(has_gravatar(bad_email))
+        self.assertTrue(has_gravatar(good_email))
+
+    def test_gravatar_profile_url(self):
+        """
+        Verify that the get_gravatar_profile_url helper method correctly
+        generates a profile url for gravatar user.
+        """
+        email = 'joe at example.com'
+        profile_url = get_gravatar_profile_url(email)
+        email_hash = calculate_gravatar_hash(email)
+
+        self.assertTrue(profile_url.endswith(email_hash))
+
+
+class TestGravatarTemplateTags(TestCase):
+    def test_gravatar_url(self):
+        email = 'matt at automattic.com'
+        context = Context({'email': email})
+
+        t = Template("{% load gravatar %}{% gravatar_url email %}")
+        rendered = t.render(context)
+
+        self.assertEqual(rendered, escape(get_gravatar_url(email)))
+
+    def test_gravatar_img(self):
+        # Some defaults for testing
+        email = 'matt at automattic.com'
+        alt_text = 'some alt text'
+        css_class = 'gravatar-thumb'
+        size = 250
+
+        # Build context
+        context = Context({
+            'email': email,
+            'size': size,
+            'alt_text': alt_text,
+            'css_class': css_class,
+        })
+
+        # Default behavior
+        t = Template("{% load gravatar %}{% gravatar email %}")
+        rendered = t.render(context)
+
+        self.assertTrue(escape(get_gravatar_url(email)) in rendered)
+        self.assertTrue('class="gravatar"' in rendered)
+        self.assertTrue('alt=""' in rendered)
+
+        t = Template("{% load gravatar %}{% gravatar email size alt_text css_class %}")
+        rendered = t.render(context)
+
+        self.assertTrue('width="%s"' % (size,) in rendered)
+        self.assertTrue('height="%s"' % (size,) in rendered)
+        self.assertTrue('alt="%s"' % (alt_text,) in rendered)
+        self.assertTrue('class="%s"' % (css_class,) in rendered)
+
+    def test_gravatar_user_url(self):
+        # class with email attribute
+        class user:
+            email = 'bouke at webatoom.nl'
+
+        context = Context({'user': user})
+
+        t = Template("{% load gravatar %}{% gravatar_url user %}")
+        rendered = t.render(context)
+
+        self.assertEqual(rendered, escape(get_gravatar_url(user.email)))
+
+    def test_gravatar_user_img(self):
+        # class with email attribute
+        class user:
+            email = 'bouke at webatoom.nl'
+
+        context = Context({'user': user})
+
+        t = Template("{% load gravatar %}{% gravatar user %}")
+        rendered = t.render(context)
+
+        self.assertTrue(escape(get_gravatar_url(user.email)) in rendered)
+
+    def test_invalid_input(self):
+        context = Context({'email': None})
+
+        t = Template("{% load gravatar %}{% gravatar email %}")
+        rendered = t.render(context)
+
+        self.assertEqual("", rendered, "Invalid input should return empty result")
+
+    def test_gravatar_profile_url(self):
+        """
+        Verify the profile url generated from template gravatar_profile_url tag.
+        """
+        # class with email attribute
+        class user:
+            email = 'bouke at webatoom.nl'
+
+        context = Context({'user': user})
+
+        t = Template("{% load gravatar %}{% gravatar_profile_url user %}")
+        rendered = t.render(context)
+
+        self.assertEqual(rendered, escape(get_gravatar_profile_url(user.email)))
diff --git a/django_gravatar/views.py b/django_gravatar/views.py
new file mode 100644
index 0000000..6381ad9
--- /dev/null
+++ b/django_gravatar/views.py
@@ -0,0 +1 @@
+"""Stub views.py"""
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..6c71b61
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,8 @@
+[wheel]
+universal = 1
+
+[egg_info]
+tag_build = 
+tag_date = 0
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..66c3950
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,32 @@
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
+
+setup(
+    name='django-gravatar2',
+    version='1.4.0',
+    description='Essential Gravatar support for Django. Features helper'
+                ' methods, templatetags and a full test suite!',
+    long_description=open('README.rst').read(),
+    keywords='django gravatar avatar',
+    license=open('LICENSE').read(),
+    author='Tristan Waddington',
+    author_email='tristan.waddington at gmail.com',
+    url='https://github.com/twaddington/django-gravatar',
+    packages=['django_gravatar', 'django_gravatar.templatetags'],
+    classifiers=[
+        'Development Status :: 5 - Production/Stable', # 4 Beta, 5 Production/Stable
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3.2',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
+        'Framework :: Django',
+    ]
+)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-django-gravatar2.git



More information about the Python-modules-commits mailing list