Jens Diemer committed c920b77

Allow all users to search other user post. TODO: Add a link on user list page.

Comments (0)

Files changed (1)


 from django.contrib.auth.models import User
 from django.contrib.sites.models import Site
 from django.core.cache import cache
+from django.core.exceptions import SuspiciousOperation
 from django.core.urlresolvers import reverse
 from django.db import transaction
 from django.db.models import Q, F
         if not user.is_authenticated():
             raise Http404("Search 'show_user' not available for anonymous user.")
-        if user.is_staff:
-            user_id = request.GET.get("user_id",
+        user_id = request.GET.get("user_id",
+        try:
             user_id = int(user_id)
-            if user_id !=
+        except ValueError:
+            raise SuspiciousOperation()
  1. intgr

    I would prefer to provide more info with exceptions...

    except ValueError as err:
       raise SuspiciousOperation(str(err))
+        if user_id !=
+            try:
                 search_user = User.objects.get(id=user_id)
-      , "Filter by user '%s'." % search_user.username)
-        else:
-            user_id =
+            except User.DoesNotExist:
+                messages.error(request, _("Error: User unknown!"))
+                return HttpResponseRedirect(request.path)
+  , "Filter by user '%s'." % search_user.username)
         if show_as_posts:
             posts = posts.filter(user__id=user_id)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.