Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET parameters not retrievable in action view #164

Open
Tamupiwa opened this issue Nov 9, 2023 · 1 comment
Open

GET parameters not retrievable in action view #164

Tamupiwa opened this issue Nov 9, 2023 · 1 comment

Comments

@Tamupiwa
Copy link

Tamupiwa commented Nov 9, 2023

GET parameters seem to always return empty when attempting to retrieve them from the action view. For example when I add the parameter 'form1' to the url that maps to my action http://localhost:8000/admin/form_builder/formdefinition/actions/export_form?form_name=form1 the parameter is removed when I access the request.GET object in the action view. Is it possible to access GET parameters somehow?

@admin.register(FormDefinition)
class FormDefinitionAdmin(DjangoObjectActions, BaseAdmin):
    changelist_actions = ('export_forms')
    
    def export_forms(self, request, queryset):
        # always returns None here
        form_name = request.GET.get('form_name')
        exporter = FormExporter()
        file_path = exporter.export_form(form_name)
        with open(file_path, 'r') as file:
            response = HttpResponse(file, content_type='application/pdf')
            response["Content-Disposition"] = "attachment; filename=forms.json"
            return response
@crccheck
Copy link
Owner

I did an experiment by altering some tests and I saw my GET param go through

diff --git a/django_object_actions/tests/test_admin.py b/django_object_actions/tests/test_admin.py
index db6e7da..f358414 100644
--- a/django_object_actions/tests/test_admin.py
+++ b/django_object_actions/tests/test_admin.py
@@ -18,7 +18,9 @@ class CommentTests(LoggedInTestCase):
     def test_action_on_a_model_with_uuid_pk_works(self):
         comment = CommentFactory()
         comment_url = reverse("admin:polls_comment_change", args=(comment.pk,))
-        action_url = "/admin/polls/comment/{0}/actions/hodor/".format(comment.pk)
+        action_url = "/admin/polls/comment/{0}/actions/hodor/?hello=foo".format(
+            comment.pk
+        )
         # sanity check that url has a uuid
         self.assertIn("-", action_url)
         response = self.client.get(action_url)
@@ -75,7 +77,7 @@ class ChangeTests(LoggedInTestCase):
         self.assertIn("foo", response.context_data)

     def test_changelist_action_view(self):
-        url = "/admin/polls/choice/actions/delete_all/"
+        url = "/admin/polls/choice/actions/delete_all/?nuke=1"
         response = self.client.get(url)
         self.assertRedirects(response, "/admin/polls/choice/")

diff --git a/example_project/polls/admin.py b/example_project/polls/admin.py
index 8d784a8..7ff1903 100644
--- a/example_project/polls/admin.py
+++ b/example_project/polls/admin.py
@@ -43,6 +43,7 @@ class ChoiceAdmin(DjangoObjectActions, admin.ModelAdmin):
         obj.save()

     def delete_all(self, request, queryset):
+        print(request.GET)
         self.message_user(request, "just kidding!")

     @action(description="0")
@@ -145,6 +146,7 @@ class CommentAdmin(DjangoObjectActions, admin.ModelAdmin):
     ################

     def hodor(self, request, obj):
+        print(request.GET)
         if not obj.comment:
             # bail because we need a comment
             return
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..<QueryDict: {'nuke': ['1']}>
......<QueryDict: {'hello': ['foo']}>
.......................
----------------------------------------------------------------------
Ran 31 tests in 1.951s

So I'll need to find another way to replicate this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants