Code

#20563 closed New feature (wontfix)

Add validation in QueryDict.get()

Reported by: Cloudream Owned by: nobody
Component: HTTP handling Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Hi,

I'd like to suggest a new parameter in QueryDict.get() named pattern.

p = request.GET.get(key='q', default='10', pattern=r'^\d+$')

As it is submitted by user, the value of parameter q could be any characters. But I only need a non-negative number, so I add a new pattern parameter for QueryDict.get(), if the value does not match the pattern, then get() will return default value, as '10' in example, but not the value submitted by user.

If you love this tiny feature I could prepare a patch. (I think it only requires less than 10 lines of codes and dozens of lines of test codes?)

Attachments (0)

Change History (1)

comment:1 Changed 11 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

Thank-you for the suggestion, however, I don't think this type of logic/validation should be part of QueryDict (it seems like something you may want to use the forms abstraction for).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.