Commit 05e64bb7 by Őry Máté

dashboard: extract search_user

parent 70fcc92b
......@@ -44,6 +44,15 @@ from dashboard.models import Favourite, Profile
logger = logging.getLogger(__name__)
def search_user(keyword):
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)
class SuccessMessageMixin(object):
......@@ -1490,11 +1499,7 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
def post(self, request, *args, **kwargs):
new_owner = User.objects.get(username=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'])
new_owner = search_user(request.POST['name'])
except User.DoesNotExist:
messages.error(request, _('Can not find specified user.'))
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