Re: Url tag issues

2008-06-19 Thread phillc

use of named urls will probably make that a ton easier

On Jun 19, 11:45 am, "Emily Rodgers" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have been hitting a brick wall so many times now on this that it is
> starting to hurt!! Please help if you can...
>
> I have an index page, and I want my function for it (in views.py) to take a
> number of parameters to decide what to display, but I can't figure out how
> to do it.
>
> The kinds of options I want to give it are things like, pkid of the thing I
> want to select (for more details), a filter to apply to the list of things
> shown on the index page, the name of the attribute I want to sort the index
> table by.
>
> The problems I am hitting are mainly to do with the {% url
> app.views.function keyword=optval %} tags to generate urls for my link bar.
>
> The combinations or parameters I want to use are:
>
> id
> id + filter
> filter
> and sort_by (alone, or with any of the above combinations)
>
> I have managed to write a regex to understand these options and my views
> function does what I want, but with that regex, the {% url blah thing %}
> just doesn't work at all. Do I need to just write loads of separate regexes
> (for different combinations!)?
>
> The regex that works (reading urls), but doesn't generate urls is something
> along the lines of:
>
> r'^co(|(?P\d*)/)(|/filter/(?P\w*)/)(|sort/(?P\w*)/)$
> '
>
> The kinds of url tag things I have been using are:
>
> {% url myapp.views.index id=3 %}
> {% url myapp.views.index filter_by="comp" %}
> {% url myapp.views.index filter_by="comp",sort_by="date" %}
>
> But they just evaluate to an empty string :(
>
> The problem is the option thing. Am I just being lazy / stupid?
>
> Em
>
> Information Security Analyst, ARM Ltd,
> 110 Fulbourn Road, Cambridge CB1 9NJ, UK
> Tel: +44 (0) 1223 406 365
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



RE: Url tag issues

2008-06-20 Thread Emily Rodgers

Cheers, I have been thinking of that, but also using includes. Still haven't
managed to make it work the way I want :(

> -Original Message-
> From: django-users@googlegroups.com 
> [mailto:[EMAIL PROTECTED] On Behalf Of phillc
> Sent: 19 June 2008 20:31
> To: Django users
> Subject: Re: Url tag issues
> 
> 
> use of named urls will probably make that a ton easier
> 
> On Jun 19, 11:45 am, "Emily Rodgers" <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I have been hitting a brick wall so many times now on this 
> that it is 
> > starting to hurt!! Please help if you can...
> >
> > I have an index page, and I want my function for it (in 
> views.py) to 
> > take a number of parameters to decide what to display, but I can't 
> > figure out how to do it.
> >
> > The kinds of options I want to give it are things like, pkid of the 
> > thing I want to select (for more details), a filter to apply to the 
> > list of things shown on the index page, the name of the attribute I 
> > want to sort the index table by.
> >
> > The problems I am hitting are mainly to do with the {% url 
> > app.views.function keyword=optval %} tags to generate urls 
> for my link bar.
> >
> > The combinations or parameters I want to use are:
> >
> > id
> > id + filter
> > filter
> > and sort_by (alone, or with any of the above combinations)
> >
> > I have managed to write a regex to understand these options and my 
> > views function does what I want, but with that regex, the 
> {% url blah 
> > thing %} just doesn't work at all. Do I need to just write loads of 
> > separate regexes (for different combinations!)?
> >
> > The regex that works (reading urls), but doesn't generate urls is 
> > something along the lines of:
> >
> > 
> r'^co(|(?P\d*)/)(|/filter/(?P\w*)/)(|sort/(?P\
> > w*)/)$
> > '
> >
> > The kinds of url tag things I have been using are:
> >
> > {% url myapp.views.index id=3 %}
> > {% url myapp.views.index filter_by="comp" %} {% url 
> myapp.views.index 
> > filter_by="comp",sort_by="date" %}
> >
> > But they just evaluate to an empty string :(
> >
> > The problem is the option thing. Am I just being lazy / stupid?
> >
> > Em
> >
> > Information Security Analyst, ARM Ltd, 110 Fulbourn Road, Cambridge 
> > CB1 9NJ, UK
> > Tel: +44 (0) 1223 406 365
> > 
> 



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Url tag issues

2008-06-20 Thread Rajesh Dhawan

Hi Emily,



> > >
> > > The problems I am hitting are mainly to do with the {% url
> > > app.views.function keyword=optval %} tags to generate urls
> > for my link bar.


Firstly, as phillc suggests, it's a good idea to first name your index
page so it's easier to reference it in your url tags.

> > >
> > > The combinations or parameters I want to use are:
> > >
> > > id
> > > id + filter
> > > filter
> > > and sort_by (alone, or with any of the above combinations)

Since you need that kind of flexibility in which parameters and
combinations you can have, consider using query string parameters
instead of url path parameters.


> > >
> > > The kinds of url tag things I have been using are:
> > >
> > > {% url myapp.views.index id=3 %}
> > > {% url myapp.views.index filter_by="comp" %} {% url
> > myapp.views.index
> > > filter_by="comp",sort_by="date" %}

If you use query strings that would become:

{% url myindex %}?id=3
{% url myindex %}?filter_by=comp
{% url myindex %}?filter_by=comp&sort_by=date

Where myindex is the name of your URL pattern whose regex itself will
also be much simplified now that the parameters are part of the query
string.

In your view, you would obtain the parameters with:

filter_by = request.GET.get('filter_by', None)
sort_by = request.GET.get('sort_by', None)
id = request.GET.get('id', None)

Now, whichever parameters above are not None would be used in your
view logic to build your queries and template context.

-Rajesh D

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



RE: Url tag issues

2008-06-23 Thread Emily Rodgers

 

> -Original Message-
> From: django-users@googlegroups.com 
> [mailto:[EMAIL PROTECTED] On Behalf Of Rajesh Dhawan
> Sent: 20 June 2008 19:06
> To: Django users
> Subject: Re: Url tag issues
> 
> 
> Hi Emily,
> 
> 
> 
> > > >
> > > > The problems I am hitting are mainly to do with the {% url 
> > > > app.views.function keyword=optval %} tags to generate urls
> > > for my link bar.
> 
> 
> Firstly, as phillc suggests, it's a good idea to first name 
> your index page so it's easier to reference it in your url tags.
> 
> > > >
> > > > The combinations or parameters I want to use are:
> > > >
> > > > id
> > > > id + filter
> > > > filter
> > > > and sort_by (alone, or with any of the above combinations)
> 
> Since you need that kind of flexibility in which parameters 
> and combinations you can have, consider using query string 
> parameters instead of url path parameters.

This is what I would normally have done, but I got the impression that
this kinda went again what django is about, so I was trying to do it in
a more djangoesque way!! Perhaps I will just do it how I would have
before!!

Thanks for pointing out the obvious (that I had been stupidly
disregarding) to me :)

Em

-- 
IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium.  Thank you.



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Url tag issues

2008-06-23 Thread Rajesh Dhawan

Hi Emily,

>
> > Since you need that kind of flexibility in which parameters
> > and combinations you can have, consider using query string
> > parameters instead of url path parameters.
>
> This is what I would normally have done, but I got the impression that
> this kinda went again what django is about, so I was trying to do it in
> a more djangoesque way!!

Actually, both ways are djangoesque enough.

Normally, you would use the "path style" when your URL's path
components are well-defined(/articles/detail/123/, /news/sports/
soccer/, etc.) On the other hand, when you have to drive the main view
with a flexible number of parameters some of which may not always be
present *and* you need them to appear in many different combinations,
the querystring-based pattern fits in better.

> Perhaps I will just do it how I would have
> before!!
>
> Thanks for pointing out the obvious (that I had been stupidly
> disregarding) to me :)

Yeah, sometimes the most obvious solution is also the right one ;)

-RD
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---