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

Feature request - ability for 'static' or fixed URL params based on widget kwargs #36

Open
lb- opened this issue Sep 5, 2021 · 1 comment

Comments

@lb-
Copy link
Member

lb- commented Sep 5, 2021

Example Use Case

  • A Document chooser block that will restrict file types based on some generic kwargs passed into the Block declaration
  • e.g. doc_block = RestrictedDocumentChooserBlock(accept="svg,md") OR doc_block = RestrictedDocumentChooserBlock(attrs={"data-url-accept": "svg,md"}).
  • See answer https://stackoverflow.com/a/69060326/8070948

Idea - LinkedField with a static value

  • LinkedField is super close but does not allow for a case where the URL param is fixed/static based on the Panel usage, something like this could be possible but does not really use any linked field at all.
PersonChooser(linked_fields={
    'country': {'static': 'AU'}
})

Idea - Handling arbitrary widget attrs that generate URL params

  • Django has the widget.attrs approach for scenarios like this it seems (where we may not want to define a whole widget but just want to pass some dict down to its declaration/rendering).
  • Handling attrs does not work out of the box (e.g. PersonChooser(attrs={'data-country': 'AU' })) but it can be made to work without too much effort, it would be nice if it did though. From here the Widget class can append this value to the URL generated by get_choose_modal_url.
  • Maybe even going a step further and automatically add any URL params that are passed as attrs and prefixed with data-url- so no get_choose_modal_url modification needed (although, that is a bit magic).
  • Another option is to be more explicit and just allow PersonChooser(url_values={'country': 'AU' }), as long as the same params are also in the preserve_url_parameters on the view set, they could be used by get_unfiltered_object_list
@lb-
Copy link
Member Author

lb- commented Oct 3, 2021

Another similar question, wanting a way to filter documents that are .csv easily with a specific instance of a DocumentChooserBlock
https://stackoverflow.com/questions/69413317/is-there-a-way-to-filter-the-document-chooser-when-its-opened-from-a-particular

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

1 participant