mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
removed all dependence on django-notification and django-friends by changing to emitting signals
This commit is contained in:
parent
9aac349f2d
commit
bc0a34612c
3 changed files with 10 additions and 39 deletions
|
|
@ -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"))
|
||||
|
||||
signals.post_syncdb.connect(create_notice_types, sender=notification)
|
||||
else:
|
||||
print "Skipping creation of NoticeTypes as notification app not found"
|
||||
4
avatar/signals.py
Normal file
4
avatar/signals.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import django.dispatch
|
||||
|
||||
|
||||
avatar_updated = django.dispatch.Signal(providing_args=["user", "avatar"])
|
||||
|
|
@ -9,16 +9,9 @@ from django.contrib.auth.decorators import login_required
|
|||
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
|
||||
|
||||
notification = False
|
||||
if 'notification' in settings.INSTALLED_APPS:
|
||||
from notification import models as notification
|
||||
|
||||
friends = False
|
||||
if 'friends' in settings.INSTALLED_APPS:
|
||||
friends = True
|
||||
from friends.models import Friendship
|
||||
|
||||
def _get_next(request):
|
||||
"""
|
||||
|
|
@ -39,16 +32,6 @@ def _get_next(request):
|
|||
if not next:
|
||||
next = request.path
|
||||
return next
|
||||
|
||||
def _notification_updated(request, avatar):
|
||||
notification.send([request.user], "avatar_updated",
|
||||
{"user": request.user, "avatar": avatar})
|
||||
if friends:
|
||||
notification.send((x['friend'] for x in
|
||||
Friendship.objects.friends_for_user(request.user)),
|
||||
"avatar_friend_updated",
|
||||
{"user": request.user, "avatar": avatar}
|
||||
)
|
||||
|
||||
def _get_avatars(user):
|
||||
# Default set. Needs to be sliced, but that's it. Keep the natural order.
|
||||
|
|
@ -66,7 +49,7 @@ 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)
|
||||
|
||||
@login_required
|
||||
def add(request, extra_context=None, next_override=None,
|
||||
|
|
@ -87,8 +70,7 @@ def add(request, extra_context=None, next_override=None,
|
|||
avatar.save()
|
||||
request.user.message_set.create(
|
||||
message=_("Successfully uploaded a new avatar."))
|
||||
if notification:
|
||||
_notification_updated(request, 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',
|
||||
|
|
@ -126,8 +108,8 @@ def change(request, extra_context=None, next_override=None,
|
|||
updated = True
|
||||
request.user.message_set.create(
|
||||
message=_("Successfully updated your avatar."))
|
||||
if updated and notification:
|
||||
_notification_updated(request, 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,8 +140,7 @@ def delete(request, extra_context=None, next_override=None, *args, **kwargs):
|
|||
if unicode(a.id) not in ids:
|
||||
a.primary = True
|
||||
a.save()
|
||||
if notification:
|
||||
_notification_updated(request, a)
|
||||
avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
|
||||
break
|
||||
Avatar.objects.filter(id__in=ids).delete()
|
||||
request.user.message_set.create(
|
||||
|
|
|
|||
Loading…
Reference in a new issue