I have to admit, the missing ) is a typo. I made up the ice cream
example to try to simplify my problem, and accidentally missed it off.

Perhaps my example is too simple.
> I have a small form on a page that is mostly optional fields with the
> exception of some drop down boxes.

My actual form has 3 optional fields, and this complicated matters
with matching URLs. Fortunately, two of the fields are limits for a
price search, so I've used "-" to identify the re, and the third is a
text description so I'm expecting URLs that look like "/100-200/persian
%20rug/" (Where 100-200 is the price range, and "persian%20rug" is a
quoted text search).

My issue is that any of those 3 fields may not be submitted, but
somehow I need to redirect to the process view.

The <a href="http://jobs.guardian.co.uk/jobs/"; title="Guardian
Jobs">Guardian Jobs</a> site is a nice example of the effect I want to
create as you add filtering paramters on the left, although I'm using
a form to collect user input as opposed to giving them a list of
ranges which is more difficult.

I hope that clears a few things up.

On Nov 4, 5:23 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> redmonkey wrote:
> > Hi,
>
> > I have a small form on a page that is mostly optional fields with the
> > exception of some drop down boxes. I want to take the data submitted
> > through this form and use them to form a URL.
>
> > My problem is with the URL writing. I first wrote some unit tests to
> > find the regular expressions that worked but Django doesn't seem to
> > like the '?' in URL configurations.
>
> > How can I write a workflow that converts optional, POSTed data to a
> > RESTful URL for processing?
>
> > Here's an example:
>
> > class IceCreamForm(forms.form):
> >     description = forms.CharField(required=False)
> >     flavour = forms.ChoiceField(choices=FLAVOUR_CHOICES, initial=0)
> >     FLAVOUR_CHOICES = (
> >            ...
> >     )
>
> > This is my form class. It contains one optional field, and one
> > required field. When rendered on a page, the form POSTs it's data to
> > the the 'process' view:
>
> > def process(request):
> >     # Standard form stuff (is_valid) ...
> >     params = {}
> >     if form.cleaned_data['description']:
> >         params.update(description=form.cleaned_data['description'])
> >    if form.cleaned_data['flavour']:
> >        params.update(flavour=form.cleaned_data['flavour'])
>
> >    return HttpResponseRedirect('proj.app.views.filter', kwags=params)
>
> > def filter(request, description=None, flavour=0):
> >     ... do stuff ...
>
> > Here, I collect the parameters from the form and try to turn them into
> > a pretty URL that redirects to the filter view to do something with
> > the data. It's the URL writing I'm having problems with. I want to
> > write things like:
>
> > urlpatterns += patterns('proj.app.views',
> >     (r'^(?P<flavour>\w+)/((?P<description>\w+)/)?$', 'filter'),
> > )
>
> It might be better to try something that makes the last slash optional
> in a different way. How about
>
>     (r'^(?P<flavour>\w+)(/(?P<description>\w+))/?$', 'filter'),
>
> > The question mark is wrapped around an extra '/' to complete the URL,
> > but it doesn't work. Nor does
>
> > urlpatterns += patterns('proj.app.views',
> >     (r'^(?P<flavour>\w+)/$', 'filter'),
> >     (r'^(?P<flavour>\w+)/(?P<description>\w+/$', 'filter'),
> > )
>
> > I'm surprised with the result of the last one, and so I'm sure I'm
> > missing something. Does anyone have any ideas or simplifications for
> > me?
>
> The last one doesn't even appear to be a syntactically correct re due to
> mismatching parentheses ... did you copy and paste, or mis-transcribe?
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to