summaryrefslogtreecommitdiffstats
path: root/hyperkitty/lib/__init__.py
blob: 887cfd52f8156c51811e15104c814e87f5f38cfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#-*- coding: utf-8 -*-

import urllib
from hashlib import md5
import threading

from django.conf import settings

from hyperkitty.utils import log

import kittystore


class ThreadSafeStorePool(object):
    """
    http://unpythonic.blogspot.fr/2007/11/using-storm-and-sqlite-in-multithreaded.html
    """

    def __init__(self):
        self._local = threading.local()

    def get(self):
        try:
            return self._local.store
        except AttributeError:
            self._local.store = kittystore.get_store(settings.KITTYSTORE_URL, debug=False)
            return self._local.store


def gravatar_url(email):
    '''Return a gravatar url for an email address'''
    size = 64
    default = "http://fedoraproject.org/static/images/" + \
            "fedora_infinity_%ix%i.png" % (size, size)
    query_string = urllib.urlencode({'s': size, 'd': default})
    identifier = md5(email).hexdigest()
    return 'http://www.gravatar.com/avatar/%s?%s' % (identifier, query_string)