Exemple #1
0
 def field_to_native(self, obj, field_name):
     try:
         a_path = get_primary_avatar(obj, 50)
         if a_path:
             return self.to_native(a_path.avatar_url(50, 50))
         else:
             return self.to_native(get_default_avatar_url())
     except Avatar.DoesNotExist:
         return self.to_native(get_default_avatar_url())
Exemple #2
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            #return "http://www.gravatar.com/avatar/%s/?%s" % (
            #    md5_constructor(user.email).hexdigest(),
            #    urllib.urlencode(params))
            return get_default_avatar_url(user)
        else:
            return get_default_avatar_url(user)
Exemple #3
0
def render_primary_id(request, extra_context={}, user_id=None, size=AVATAR_DEFAULT_SIZE, *args, **kwargs):
    size = int(size)

    try:
        # Order by -primary first; this means if a primary=True avatar exists
        # it will be first, and then ordered by date uploaded, otherwise a
        # primary=False avatar will be first.  Exactly the fallback behavior we
        # want.
        avatar = Avatar.objects.filter(user__id=user_id).order_by("-primary", "-date_uploaded")[0]
    except IndexError:
        avatar = None
    if avatar:
        if not avatar.thumbnail_exists(size):
            avatar.create_thumbnail(size)

    if avatar:
        # FIXME: later, add an option to render the resized avatar dynamically
        # instead of redirecting to an already created static file. This could
        # be useful in certain situations, particulary if there is a CDN and
        # we want to minimize the storage usage on our static server, letting
        # the CDN store those files instead
        return HttpResponseRedirect(avatar.avatar_url(size))
    else:
        url = get_default_avatar_url()
        return HttpResponseRedirect(url)
Exemple #4
0
def get_user_avatar_url(user):
    the_avatar = get_primary_avatar(user, 80)
    if the_avatar :
        the_avatar = the_avatar.avatar_url(80)
    else:
        the_avatar = get_default_avatar_url()
    return the_avatar
Exemple #5
0
def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZE, *args, **kwargs):
    size = int(size)
    if not isinstance(user, User):
        try:
            user = get_user(user)
        except User.DoesNotExist:
            return None
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        # FIXME: later, add an option to render the resized avatar dynamically
        # instead of redirecting to an already created static file. This could
        # be useful in certain situations, particulary if there is a CDN and
        # we want to minimize the storage usage on our static server, letting
        # the CDN store those files instead
        return HttpResponseRedirect(avatar.avatar_url(size))
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            path = "%s/?%s" % (hashlib.md5(user.email).hexdigest(),
                               urllib.urlencode(params))
            url = urlparse.urljoin(AVATAR_GRAVATAR_BASE_URL, path)
        else:
            url = get_default_avatar_url()
        return HttpResponseRedirect(url)
def render_primary(request, user=None, size=settings.AVATAR_DEFAULT_SIZE):
    size = int(size)
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        # FIXME: later, add an option to render the resized avatar dynamically
        # instead of redirecting to an already created static file. This could
        # be useful in certain situations, particulary if there is a CDN and
        # we want to minimize the storage usage on our static server, letting
        # the CDN store those files instead
        url = avatar.avatar_url(size)
    else:
        if user:
            url = get_default_avatar_url(user.in_staff_index)
        else:
            url = get_default_avatar_url()

    return redirect(url)
Exemple #7
0
def _get_render_primary_response(avatar=None):
    if avatar:
        # FIXME: later, add an option to render the resized avatar dynamically
        # instead of redirecting to an already created static file. This could
        # be useful in certain situations, particulary if there is a CDN and
        # we want to minimize the storage usage on our static server, letting
        # the CDN store those files instead
        return HttpResponseRedirect(avatar.avatar_url(size))
    else:
        url = get_default_avatar_url()
        return HttpResponseRedirect(url)
Exemple #8
0
def avatar(target, size=AVATAR_DEFAULT_SIZE):
    handler = get_target_handler()
    obj = handler.get_target_object(target)

    if not obj:
        url = get_default_avatar_url(target, size)
        alt = _("Default Avatar")
    else:
        url = avatar_url(obj, size)
        alt = handler.get_alt_text(obj)
    return """<img src="%s" alt="%s" width="%s" height="%s" />""" % (url, alt,
                                                                     size, size)
Exemple #9
0
 def render_primary(self):
     size = self.kwargs.get('size', AVATAR_DEFAULT_SIZE)
     if self.avatar:
         # FIXME: later, add an option to render the resized avatar dynamically
         # instead of redirecting to an already created static file. This could
         # be useful in certain situations, particularly if there is a CDN and
         # we want to minimize the storage usage on our static server, letting
         # the CDN store those files instead
         return HttpResponseRedirect(self.avatar.avatar_url(size))
     else:
         url = get_default_avatar_url(self.target, size)
         return HttpResponseRedirect(url)
Exemple #10
0
def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZE, *args, **kwargs):
    size = int(size)
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        # FIXME: later, add an option to render the resized avatar dynamically
        # instead of redirecting to an already created static file. This could
        # be useful in certain situations, particulary if there is a CDN and
        # we want to minimize the storage usage on our static server, letting
        # the CDN store those files instead
        return redirect(avatar.avatar_url(size))
    else:
        return redirect(get_default_avatar_url())
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if AVATAR_GRAVATAR_BACKUP:
        params = {"s": str(size)}
        if AVATAR_GRAVATAR_DEFAULT:
            params["d"] = AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(user.email)).hexdigest(), urlencode(params))
        return urljoin(AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Exemple #12
0
def avatar(user, size=AVATAR_DEFAULT_SIZE):
    if not isinstance(user, User):
        try:
            user = User.objects.get(username=user)
            alt = unicode(user)
            url = avatar_url(user, size)
        except User.DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = unicode(user)
        url = avatar_url(user, size)
    return """<img src="%s" alt="%s" width="%s" height="%s" />""" % (url, alt, size, size)
def avatar_url(user, size=80):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            return "http://www.gravatar.com/avatar/%s/?%s" % (
                md5_constructor(user.email).hexdigest(),
                urllib.urlencode(params).replace('&', '&amp;'))
        else:
            return get_default_avatar_url()
Exemple #14
0
def avatar_url(user, size=settings.AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if settings.AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if settings.AVATAR_GRAVATAR_DEFAULT:
            params['d'] = settings.AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(getattr(user,
            settings.AVATAR_GRAVATAR_FIELD))).hexdigest(), urlencode(params))
        return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            return "/avatar/%s/?%s" % (
                md5(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)

    if AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if AVATAR_GRAVATAR_DEFAULT:
            params['d'] = AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (md5(user.email).hexdigest(),
                           urllib.urlencode(params))
        return urlparse.urljoin(AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
def avatar(user, size=AVATAR_DEFAULT_SIZE, **kwargs):
    if not isinstance(user, get_user_model()):
        try:
            user = get_user(user)
            alt = six.text_type(user)
            url = avatar_url(user, size)
        except get_user_model().DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = six.text_type(user)
        url = avatar_url(user, size)
    context = dict(kwargs, **{"user": user, "url": url, "alt": alt, "size": size})
    return render_to_string("avatar/avatar_tag.html", context)
Exemple #18
0
def avatar(user, size=AVATAR_DEFAULT_SIZE, **kwargs):
    if not isinstance(user, User):
        try:
            user = User.objects.get(username=user)
            alt = unicode(user)
            url = avatar_url(user, size)
        except User.DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = unicode(user)
        url = avatar_url(user, size)
    context = dict(kwargs, **{"user": user, "url": url, "alt": alt, "size": size})
    return render_to_string("avatar/avatar_tag.html", context)
def avatar_url(user, width=settings.AVATAR_DEFAULT_SIZE, height=False):
    if not height:
        height = width
    avatar = get_primary_avatar(user, width=width, height=height)
    if avatar:
        return avatar.avatar_url(width, height)

    if settings.AVATAR_GRAVATAR_BACKUP:
        params = {"s": str(width)}
        if settings.AVATAR_GRAVATAR_DEFAULT:
            params["d"] = settings.AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(force_bytes(user.email)).hexdigest(), urlencode(params))
        return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
def avatar_url(user, width=AVATAR_DEFAULT_SIZE, height=False):
    if height == False: height = width
    avatar = get_primary_avatar(user, width=width, height=height)
    if avatar:
        return avatar.avatar_url(width,height)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(width)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            return "http://www.gravatar.com/avatar/%s/?%s" % (
                md5_constructor(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Exemple #21
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):

    if not user.is_authenticated():
        return get_default_avatar_url()

    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {"s": str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params["d"] = AVATAR_GRAVATAR_DEFAULT
            if AVATAR_GRAVATAR_SECURE:
                gravatar_base = "https://secure.gravatar.com"
            else:
                gravatar_base = "http://www.gravatar.com"
            return "%s/avatar/%s/?%s" % (
                gravatar_base,
                md5_constructor(user.email).hexdigest(),
                urllib.urlencode(params),
            )
        else:
            return get_default_avatar_url()
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        use_gravatar = user.profile.use_gravatar if (hasattr(user, 'profile') and hasattr(user.profile, 'use_gravatar')) else True
        if AVATAR_GRAVATAR_BACKUP and use_gravatar:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            return "http://www.gravatar.com/avatar/%s/?%s" % (
                md5_constructor(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Exemple #23
0
def avatar_url(target, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(target)
    if avatar:
        if not avatar.thumbnail_exists(size):
            avatar.create_thumbnail(size)
        return avatar.avatar_url(size)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            return "http://www.gravatar.com/avatar/%s/?%s" % (
                md5_constructor(get_target_gravatar_url(target)).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url(target, size)
def avatar(user, size=AVATAR_DEFAULT_SIZE):
    if not isinstance(user, get_user_model()):
        try:
            user = get_user_model().objects.get(username=user)
            alt = unicode(user)
            url = avatar_url(user, size)
        except get_user_model().DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = unicode(user)
        url = avatar_url(user, size)

    # print user.org_acronym, url    
    return """<img src="%s" alt="%s" />""" % (url, alt,
        )
def avatar(user, width=settings.AVATAR_DEFAULT_SIZE, height=False, **kwargs):
    if not height:
        height = width
    if not isinstance(user, get_user_model()):
        try:
            user = get_user(user)
            alt = six.text_type(user)
            url = avatar_url(user, width, height)
        except get_user_model().DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = six.text_type(user)
        url = avatar_url(user, width, height)
    context = dict(kwargs, **{"user": user, "url": url, "alt": alt, "width": width, "height": height})
    return render_to_string("avatar/avatar_tag.html", context)
Exemple #26
0
def render_primary(request, user=None, width=settings.AVATAR_DEFAULT_SIZE, height = None):
    if height == None: height = width
    width = int(width)
    height = int(height)
    avatar = get_primary_avatar(user, width=width, height=height)
    if avatar:
        # FIXME: later, add an option to render the resized avatar dynamically
        # instead of redirecting to an already created static file. This could
        # be useful in certain situations, particulary if there is a CDN and
        # we want to minimize the storage usage on our static server, letting
        # the CDN store those files instead
        url = avatar.avatar_url(width, height)
    else:
        url = get_default_avatar_url()

    return redirect(url)
Exemple #27
0
def get_accessrights(ars):
    ret = []
    for ar in ars :
        the_avatar = get_primary_avatar(ar.user, 80)
        if the_avatar :
            the_avatar = the_avatar.avatar_url(80)
        else:
            the_avatar = get_default_avatar_url()
        ret.append({
            'book_id': ar.book.id,
            'user_id': ar.user.id,
            'user_name': ar.user.readable_name,
            'rights': ar.rights,
            'avatar': the_avatar
        })
    return ret
Exemple #28
0
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    else:
        if AVATAR_GRAVATAR_BACKUP:
            params = {'s': str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params['d'] = AVATAR_GRAVATAR_DEFAULT
            proto = "http"
            if AVATAR_GRAVATAR_SSL:
                proto = "https"
            return "%s://www.gravatar.com/avatar/%s/?%s" % (
                proto, hashlib.md5(user.email).hexdigest(),
                urllib.urlencode(params))
        else:
            return get_default_avatar_url()
Exemple #29
0
def render_primary(request,
                   extra_context={},
                   user=None,
                   size=AVATAR_DEFAULT_SIZE,
                   *args,
                   **kwargs):
    size = int(size)
    avatar = get_primary_avatar(user, size=size)
    if avatar:
        # FIXME: later, add an option to render the resized avatar dynamically
        # instead of redirecting to an already created static file. This could
        # be useful in certain situations, particulary if there is a CDN and
        # we want to minimize the storage usage on our static server, letting
        # the CDN store those files instead
        return redirect(avatar.avatar_url(size))
    else:
        return redirect(get_default_avatar_url())
Exemple #30
0
def avatar_url_from_email(email, size=AVATAR_DEFAULT_SIZE):
    try:
        user = User.objects.get(email=email)
        return avatar_url(user, size)
    except User.DoesNotExist:

        if AVATAR_GRAVATAR_BACKUP:
            params = {"s": str(size)}
            if AVATAR_GRAVATAR_DEFAULT:
                params["d"] = AVATAR_GRAVATAR_DEFAULT
            if AVATAR_GRAVATAR_SECURE:
                gravatar_base = "https://secure.gravatar.com"
            else:
                gravatar_base = "http://www.gravatar.com"
            return "%s/avatar/%s/?%s" % (gravatar_base, md5_constructor(email).hexdigest(), urllib.urlencode(params))
        else:
            return get_default_avatar_url()
def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(user, size=size)
    tt = Orglogo.objects.filter(orgacronym=user.org_acronym)
    # if avatar:
    #     return avatar.avatar_url(size)
    # else:
    #     if tt.count()>0:
    #         return tt[0].logo_url(200)
    #     else:
    #         return get_default_avatar_url()

    if tt.count()>0:
        return tt[0].logo_url(size)
    elif avatar:
        return avatar.avatar_url(size)
    else:
        return get_default_avatar_url()
Exemple #32
0
def avatar_url(contact, size=settings.AVATAR_DEFAULT_SIZE):
    avatar = get_primary_avatar(contact, size=size)

    if avatar:
        return avatar.avatar_url(size)

    if settings.AVATAR_GRAVATAR_BACKUP:
        params = {'s': str(size)}
        if settings.AVATAR_GRAVATAR_DEFAULT:
            params['d'] = settings.AVATAR_GRAVATAR_DEFAULT
        path = "%s/?%s" % (hashlib.md5(
            force_bytes(getattr(contact,
                                settings.AVATAR_GRAVATAR_FIELD))).hexdigest(),
                           urlencode(params))
        return urljoin(settings.AVATAR_GRAVATAR_BASE_URL, path)

    return get_default_avatar_url()
Exemple #33
0
def avatar(user, size=AVATAR_DEFAULT_SIZE):
    if not isinstance(user, get_user_model()):
        try:
            user = get_user_model().objects.get(username=user)
            alt = unicode(user)
            url = avatar_url(user, size)
        except get_user_model().DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = unicode(user)
        url = avatar_url(user, size)

    # print user.org_acronym, url
    return """<img src="%s" alt="%s" />""" % (
        url,
        alt,
    )
def avatar(user, size=AVATAR_DEFAULT_SIZE, **kwargs):
    if not isinstance(user, User):
        try:
            user = User.objects.get(username=user)
            alt = unicode(user)
            url = avatar_url(user, size)
        except User.DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = unicode(user)
        url = avatar_url(user, size)
    context = dict(kwargs, **{
        'user': user,
        'url': url,
        'alt': alt,
        'size': size,
    })
    return render_to_string('avatar/avatar_tag.html', context)
Exemple #35
0
def avatar(user, size=AVATAR_DEFAULT_SIZE, **kwargs):
    if not isinstance(user, get_user_model()):
        try:
            user = get_user(user)
            alt = six.text_type(user)
            url = avatar_url(user, size)
        except get_user_model().DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = six.text_type(user)
        url = avatar_url(user, size)
    context = dict(kwargs, **{
        'user': user,
        'url': url,
        'alt': alt,
        'size': size,
    })
    return render_to_string('avatar/avatar_tag.html', context)
Exemple #36
0
def avatar(contact, size=settings.AVATAR_DEFAULT_SIZE, **kwargs):

    if not isinstance(contact, Contact):
        try:
            contact = get_contact(contact)
            alt = six.text_type(contact)
            url = avatar_url(contact, size)
        except Contact.DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = six.text_type(contact)
        url = avatar_url(contact, size)
    context = dict(
        kwargs, **{
            'contact': contact,
            'url': url,
            'alt': alt,
            'size': size,
        })
    return render_to_string('avatar/avatar_tag.html', context)
Exemple #37
0
def avatar(user, size=AVATAR_DEFAULT_SIZE, template=None, **kwargs):
    if not isinstance(user, User):
        try:
            user = get_user(user)
            alt = unicode(user)
            url = avatar_url(user, size)
        except User.DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = unicode(user)
        url = avatar_url(user, size)
    context = dict(kwargs, **{
        'user': user,
        'url': url,
        'alt': alt,
        'size': size,
    })
    if template == 'img':
        return """<img src="%s" alt="%s" width="%s" height="%s" />""" % (
            url, alt, size, size)
    if not template:
        template = 'avatar/avatar_tag.html'
    return render_to_string(template, context)
Exemple #38
0
def avatar_url(user, size=Settings.AVATAR_DEFAULT_SIZE):
    avatar = get_user_avatar(user, size=size)
    if avatar:
        return avatar.avatar_url(size)
    return get_default_avatar_url()
Exemple #39
0
 def get_avatar_url(self, obj):
     avatar = get_primary_avatar(obj, size=66)
     if avatar:
         return avatar.avatar_url(66)
     return get_default_avatar_url()
Exemple #40
0
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.template import defaultfilters

from geonode.maps.models import Layer
from geonode.maps.models import Map
from geonode.documents.models import Document
from geonode.search import extension

from agon_ratings.categories import RATING_CATEGORY_LOOKUP
from agon_ratings.models import OverallRating

from avatar.util import get_default_avatar_url

_default_avatar_url = get_default_avatar_url()


def _bbox(obj):
    idx = None
    # the one-to-one reverse relationship requires special handling if null :(
    # maybe one day: https://code.djangoproject.com/ticket/10227
    try:
        idx = obj.spatial_temporal_index
    except ObjectDoesNotExist:
        pass
    except AttributeError:
        pass
    # unknown extent, just give something that works
    extent = idx.extent.extent if idx else map(str, (obj.bbox_x0, obj.bbox_y0,
                                                     obj.bbox_x1, obj.bbox_y1))