Rajeesh Nair avatar Rajeesh Nair committed 0b27473

Django-monitor: Fixed #4

* The issue #4 was about changelist filter always pointing to the `All`
option irrespective of the choice selected by user. The reason was that
filter rendering happens after calls to ``model_admin.queryset`` which in
turn removes the ``status`` parameter from GET dict. So being unable to
retrieve the selected ``status``, the filter always sets the lookup_val as
None. None corresponds to the choice, ``All``. Fixed the issue by extracting
the ``status`` parameter from the request path.

Comments (0)

Files changed (2)


         status = request.GET.get('status', None)
         # status is not among list_filter entries. So its presence will raise
         # IncorrectLookupParameters when django tries to build-up changelist.
-        # We no longer need that param after leaving here. So let's remove it.
+        # So let's remove it from GET dict (Still available in the url.)
         if status:
             get_dict = request.GET.copy()
             del get_dict['status']


             self, f, request, params, model, model_admin, field_path
         self.lookup_kwarg = 'status'
-        self.lookup_val = request.GET.get(self.lookup_kwarg)
+        # usually, lookup_vals are extracted from request.GET. But we have
+        # intentionally removed ``status`` from GET before.
+        # (Have a look at ``django_monitor.admin.MonitorAdmin.queryset`` to
+        # know why). So we'll apply regex over the url:
+        import re
+        status_matches = re.findall(
+            r'status=(?P<status>%s)' % '|'.join(STATUS_DICT.keys()),
+            request.get_full_path()
+        )
+        self.lookup_val = status_matches[0] if status_matches else None
         self.lookup_choices = STATUS_DICT.keys()
     def choices(self, cl):
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 ProjectModifiedEvent.java.
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.