Permalink
Browse files

Merge remote-tracking branch 'ericflo/master'

Conflicts:
	avatar/management/__init__.py
	avatar/views.py
	setup.py
  • Loading branch information...
jezdez committed Apr 25, 2012
2 parents 66ab586 + bc0a346 commit 4a81a2a3885838967e8edd7c56afbb9bb409e01e
Showing with 28 additions and 43 deletions.
  1. +0 −14 avatar/management/__init__.py
  2. +4 −0 avatar/signals.py
  3. +23 −28 avatar/views.py
  4. +1 −1 setup.py
@@ -1,14 +0,0 @@
-from django.conf import settings
-from django.db.models import signals
-from django.utils.translation import ugettext_noop as _
-
-if "notification" in settings.INSTALLED_APPS:
- from notification import models as notification
-
- def create_notice_types(app, created_models, verbosity, **kwargs):
- #notification.create_notice_type("avatar_updated", _("Avatar Updated"), _("your avatar has been updated"))
- #notification.create_notice_type("avatar_friend_updated", _("Friend Updated Avatar"), _("a friend has updated their avatar"))
- pass
- signals.post_syncdb.connect(create_notice_types, sender=notification)
-else:
- print "Skipping creation of NoticeTypes as notification app not found"
View
@@ -0,0 +1,4 @@
+import django.dispatch
+
+
+avatar_updated = django.dispatch.Signal(providing_args=["user", "avatar"])
View
@@ -1,23 +1,20 @@
+from django.core.files.base import ContentFile
from django.http import HttpResponseRedirect, HttpResponse, Http404
-from django.shortcuts import render_to_response
+from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext as _
-from django.conf import settings
-from django.views.decorators.csrf import csrf_exempt, csrf_view_exempt
+from django.views.decorators.csrf import csrf_exempt
+
from django.contrib.auth.decorators import login_required
-from django.shortcuts import get_object_or_404
+from django.contrib.auth.models import User
+from django.contrib import messages
+
from avatar.forms import PrimaryAvatarForm, DeleteAvatarForm, UploadAvatarForm
from avatar.models import Avatar
from avatar.settings import AVATAR_MAX_AVATARS_PER_USER, AVATAR_DEFAULT_SIZE
+from avatar.signals import avatar_updated
from avatar.util import get_primary_avatar, get_default_avatar_url
-from django.contrib.auth.models import User
-from django.core.files.base import ContentFile
-from django.contrib import messages
-friends = False
-if 'friends' in settings.INSTALLED_APPS:
- friends = True
- from friends.models import Friendship
def _get_next(request):
"""
@@ -38,7 +35,8 @@ def _get_next(request):
if not next:
next = request.path
return next
-
+
+
def _get_avatars(user):
# Default set. Needs to be sliced, but that's it. Keep the natural order.
avatars = user.avatar_set.all()
@@ -55,20 +53,18 @@ def _get_avatars(user):
else:
# Slice the default set now that we used the queryset for the primary avatar
avatars = avatars[:AVATAR_MAX_AVATARS_PER_USER]
- return (avatar, avatars)
+ return (avatar, avatars)
@csrf_exempt
def webcam_upload(request, id):
# TODO: add proper security by attaching session to flash request
user = get_object_or_404(User, pk=id)
if request.method == "POST":
- avatar = Avatar(
- user = user,
- primary = True,
- )
- avatar.avatar.save("%s_webcam_%s.jpg"%(user.pk, Avatar.objects.filter(user=user).count()),
- ContentFile(request.raw_post_data))
+ avatar = Avatar(user=user, primary=True)
+ avatar.avatar.save("%s_webcam_%s.jpg" %
+ (user.pk, Avatar.objects.filter(user=user).count()),
+ ContentFile(request.raw_post_data))
avatar.save()
messages.success(request, _("Successfully uploaded a new avatar."))
return HttpResponse(status=200, content="ok")
@@ -84,14 +80,12 @@ def add(request, extra_context=None, next_override=None,
request.FILES or None, user=request.user)
if request.method == "POST" and 'avatar' in request.FILES:
if upload_avatar_form.is_valid():
- avatar = Avatar(
- user = request.user,
- primary = True,
- )
+ avatar = Avatar(user=request.user, primary=True)
image_file = request.FILES['avatar']
avatar.avatar.save(image_file.name, image_file)
avatar.save()
messages.success(request, _("Successfully uploaded a new avatar."))
+ avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
return HttpResponseRedirect(next_override or _get_next(request))
return render_to_response(
'avatar/add.html',
@@ -122,12 +116,14 @@ def change(request, extra_context=None, next_override=None,
if request.method == "POST":
updated = False
if 'choice' in request.POST and primary_avatar_form.is_valid():
- avatar = Avatar.objects.get(id=
- primary_avatar_form.cleaned_data['choice'])
+ avatar = Avatar.objects.get(
+ id=primary_avatar_form.cleaned_data['choice'])
avatar.primary = True
avatar.save()
updated = True
messages.success(request, _("Successfully updated your avatar."))
+ if updated:
+ avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
return HttpResponseRedirect(next_override or _get_next(request))
return render_to_response(
'avatar/change.html',
@@ -158,6 +154,7 @@ def delete(request, extra_context=None, next_override=None, *args, **kwargs):
if unicode(a.id) not in ids:
a.primary = True
a.save()
+ avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
break
Avatar.objects.filter(id__in=ids).delete()
messages.success(request, _("Successfully deleted the requested avatars."))
@@ -225,7 +222,7 @@ def avatar(request, username, id, template_name="avatar/avatar.html"):
"count": count,
}, context_instance=RequestContext(request))
-
+
def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZE, *args, **kwargs):
size = int(size)
avatar = get_primary_avatar(user, size=size)
@@ -239,5 +236,3 @@ def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZ
else:
url = get_default_avatar_url()
return HttpResponseRedirect(url)
-
-
View
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages
-version = '1.3'
+version = '2.0a1'
LONG_DESCRIPTION = """
Using django-avatar

0 comments on commit 4a81a2a

Please sign in to comment.