def get(self, request, *args, **kwargs):
"""See if we have a direct match. If so redirect, if not, search.
Try fetching a remote profile if the search term is a handle.
"""
try:
q = safe_text(request.GET.get("q"))
if q:
q = q.strip()
validate_email(q)
except ValidationError:
pass
else:
profile = None
try:
profile = Profile.objects.visible_for_user(request.user).get(handle=q)
except Profile.DoesNotExist:
# Try a remote search
remote_profile = retrieve_remote_profile(q)
if remote_profile:
profile = Profile.from_remote_profile(remote_profile)
if profile:
return redirect(reverse("users:profile-detail", kwargs={"guid": profile.guid}))
return super().get(request, *args, **kwargs)
评论列表
文章目录