Commits

offline committed 67524a0

messages switched to django-notify

  • Participants
  • Parent commits 6bad669

Comments (0)

Files changed (2)

openauth/utils.py

 from django.core.urlresolvers import reverse
 from django.conf import settings
 
+from notify import notify_user
+
 import openauth
 
 
     return cls
 
 
-def message(request, msg, priority, redirect_name, args=[], kwargs={}):
-    """
-    Shortcut that prepare data for message view.
-    """
-    if openauth.settings.MESSAGE_TYPE == 'flash':
-        request.flash[priority] = msg
-        return redirect(redirect_name, *args, **kwargs)
-    return {'TEMPLATE': 'openauth/message.html', 'message': msg}
-
 
 def activation_required(view_func):
     """
     def wrapper(request, *args, **kwargs):
         if request.user.is_authenticated():
             if openauth.settings.ACTIVATION_REQUIRED and not request.user.is_active:
-                return message(request, _('You account is not activated! Check your email please.'), 'notice', '/')
+                return notify_user.notice(request, "/", _('You account is not activated! Check your email please.'))
         else:
             next_data = {'next': request.path}
             next = reverse('openauth-login')

openauth/views.py

 
 from annoying.decorators import render_to
 from confirmation.models import Confirmation
-from notify import Notify
+from notify import notify_user
 
 import openauth
 from openauth.forms import ResetPasswordForm, NewPasswordForm, LoginForm, \
     Registration should be allowed in REGISTRATION_ALLOWED setting
     """
     if request.user.is_authenticated():
-        msg = Notify(openauth.lang.LOGOUT_BEFORE_REGISTRATION)
-        return msg.notice(request, '/')
+        return notify_user.notice(request, '/', openauth.lang.LOGOUT_BEFORE_REGISTRATION)
     if not openauth.settings.REGISTRATION_ALLOWED:
-        msg = Notify(openauth.lang.REGISTRATION_DISABLED)
-        msg.notice(request, '/')
+        return notify_user.notice(request, '/', openauth.lang.REGISTRATION_DISABLED)
     if request.POST:
         form = str_to_class(openauth.settings.REGISTRATION_FORM)(request.POST)
         if form.is_valid():
                 url += '?key=%s&type=%s' % (confirmation.key, confirmation.confirmation_type)
                 params = {'domain': request.get_host(), 'email': user.email, 'url': url}
                 if email_template(user.email, 'openauth/mail/registration.txt', **params):
-                    msg = Notify(openauth.lang.PLEASE_ACTIVATE)
-                    return msg.success(request, "/")
+                    return notify_user.success(request, "/", openauth.lang.PLEASE_ACTIVATE)
                 else:
                     user.delete()
-                    return message(request, openauth.lang.ERROR_SENDING_MAIL, "error", "/")
+                    return notify_user.error(request, "/", openauth.lang.ERROR_SENDING_MAIL)
             else:
-                return message(request, openauth.lang.LOGIN_NOW, "success", "openauth-login")
+                return notify_user.success(request, "openauth-login", openauth.lang.LOGIN_NOW)
 
     else:
         form = str_to_class(openauth.settings.REGISTRATION_FORM)()
             url += '?key=%s&type=%s' % (confirmation.key, openauth.settings.PASSWORD_RESET_CONFIRMATION_TYPE)
             args = {'domain': request.get_host(), 'url': url}
             if email_template(user.email, 'openauth/mail/reset_password.txt', **args):
-                return message(request, _('Check your email please'), 'notice', '/')
+                return notify_user.notice(request, "/",  _('Check your email please'))
             else:
-                return message(request, openauth.lang.ERROR_SENDING_MAIL, 'error', '/')
+                return notify_user.notice(request, "/", openauth.lang.ERROR_SENDING_MAIL)
     else:
         form = ResetPasswordForm()
     return {'form': form}
 @render_to('openauth/login.html')
 def login(request):
     if request.user.is_authenticated():
-        return message(request, _('You are already authenticated'), 'notice', '/')
+        return notify_user.notice(request, "/", _('You are already authenticated'))
     if request.POST:
         form = LoginForm(request, request.POST)
         request.session['login_redirect_url'] = request.GET.get('next')
         if form.is_valid():
             redirect_url = build_redirect_url(request, openauth.settings.LOGIN_REDIRECT_URL)
-            return message(request, _('You have successfully logged-in'), 'success', redirect_url)
+            return notify_user.success(request, redirect_url, _('You have successfully logged-in'))
     else:
         form = LoginForm(request=request)
     return {'form': form}
 
     if form.is_valid():
         form.save(request.user)
-        return message(request, _('Password was changed'), 'success', 'openauth-show-user', [request.user.id])
+        url = reverse('openauth-show-user', args=[request.user.id])
+        return notify_user.success(request, url, _('Password was changed'))
     return {'form': form}
 
 
 @render_to()
 def logout(request):
     auth.logout(request)
-    return message(request, _('You have been logged out'), 'notice', '/')
+    return notify_user.success(request, "/", _('You have been logged out'))
 
 
 
         form = str_to_class(openauth.settings.EDIT_USER_FORM)(user, request.POST, request.FILES)
         if form.is_valid():
             form.save()
-            return message(request, _('User details successfully changed'), 'success', 'openauth-show-user', args=[user.id])
+            url = reverse('openauth-show-user', args=[request.user.id])
+            return notify_user.success(request, url, _('User details successfully changed'))
     else:
         form = str_to_class(openauth.settings.EDIT_USER_FORM)(user)