Commit 05e64bb7 by Őry Máté

dashboard: extract search_user

parent 70fcc92b
...@@ -44,6 +44,15 @@ from dashboard.models import Favourite, Profile ...@@ -44,6 +44,15 @@ from dashboard.models import Favourite, Profile
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def search_user(keyword):
try:
return User.objects.get(username=keyword)
except User.DoesNotExist:
return User.objects.get(email=keyword)
except User.DoesNotExist:
return User.objects.get(profile__org_id=keyword)
# github.com/django/django/blob/stable/1.6.x/django/contrib/messages/views.py # github.com/django/django/blob/stable/1.6.x/django/contrib/messages/views.py
class SuccessMessageMixin(object): class SuccessMessageMixin(object):
""" """
...@@ -1490,11 +1499,7 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView): ...@@ -1490,11 +1499,7 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
try: try:
new_owner = User.objects.get(username=request.POST['name']) new_owner = search_user(request.POST['name'])
except User.DoesNotExist:
new_owner = User.objects.get(email=request.POST['name'])
except User.DoesNotExist:
new_owner = User.objects.get(profile__org_id=request.POST['name'])
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, _('Can not find specified user.')) messages.error(request, _('Can not find specified user.'))
return self.get(request, *args, **kwargs) return self.get(request, *args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment