Re: 'ifequal' takes two arguments
On Sep 22, 4:48 pm, Bradley Hintze <bradle...@aggiemail.usu.edu> wrote: > I am getting an ''ifequal' takes two arguments' error for this line: > > {% ifequal {{ param2_trunc_new.3.0 }} {{ param2.4.1 }} %} > > I believer those are indeed two arguments. What going on here? > > -- > Bradley J. Hintze Don't put arguments within variable delimiters: {% ifequal param2_trunc_new.3.0 param2.4.1 %} In any case, in Django 1.2+ you can do this: {% if param2_trunc_new.3.0 != param2.4.1 %} -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 'ifequal' takes two arguments
Oh, and you don't have a space between those two variables, so it could be that they're running together and appear to be a single one. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 'ifequal' takes two arguments
Try writing both values to the screen or standard out. It's always possible that one of them isn't being populated. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
'ifequal' takes two arguments
I am getting an ''ifequal' takes two arguments' error for this line: {% ifequal {{ param2_trunc_new.3.0 }} {{ param2.4.1 }} %} I believer those are indeed two arguments. What going on here? -- Bradley J. Hintze Graduate Student Duke University School of Medicine 801-712-8799 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
Hi Bill, thank you for pointing me to the stringformat template option, I was comparing Long with String. Using now try: berufe_id = int(berufe_id.strip()) except: pass What helped me a lot. On Mar 11, 5:18 pm, Bill Freeman <ke1g...@gmail.com> wrote: > It's time to go back to figuring out just what these things are. > Put back your code that shows you the variable values, except > instead of > > {{ item.id }} > > and > > {{ berufe_id }} > > use > > --{{ item.id|stringformat:"%r" }}-- > > and > > --{{ berufe_id|stringformat:"%r%" }}-- > > The %r version will include quotes if it's a string, and will show > any whitespace. The dashes are just to be sure we know where > the object representation begins and ends. > > May we see the corresponding url pattern? > > I just want to be clear, however, that the best place to fix this is > in a view function. Even if it is mostly a wrapper for a generic view > function (capture all the arguments and then pass them on, after > fixing up the berufe_id argument, and return what the generic view > returns. > > This would also give a place to put a pdb.set_trace() so that you can > really see what's going on without having to invent code to give you > hints. > > In case you're not very pythonic, here's what fix-up code in such a > view function would look like: > > try: > berufe_id = int(berufe_id.strip()) > except: > pass > > Where the "pass" is you could instead return some error, or set > berufe_id to the integer 1. > > Actually, while testing (DEBUG=True in settings.py), leave out the > try, except, pass and just put in the berufe_id= line. Then if it > can't convert it to an integer you will get a 500 with a nice debugging > stacktrace that let's you look at variables in each stack frame, particularly > that of the view function. > > My reasons for saying that this is the right place to fix it is that: > 1. This only > happens once per request, as opposed to once per select item per request; > 2. You have the full power of python to fix whatever needs to be fixed; > 3. I believe that comparing two integers is a bit faster than comparing two > strings (unless both strings are interned, in which case you have the cost > of interning each string generated through stringformat, which is even more > expensive than a string compare; and 4. The template code, which may be > manipulated by non-programmers, becomes clearer to understand. > > Bill > > On Wed, Mar 10, 2010 at 4:17 PM, wolle <wo...@upb.de> wrote: > > Hi Tom, > > > really cool idea, but it does not work... > > > > > -- Bitte Berufsgruppe > > wählen -- > > {% for item in berufe %} > > > ifequal berufe_id item.id| > > stringformat:"s" %}selected{% endifequal %}>{{item.name}} > > {% endfor %} > > > > > does not select any option... > > > Any more hints? > > > On Mar 10, 5:13 pm, Tom Evans <tevans...@googlemail.com> wrote: > >> On Wed, Mar 10, 2010 at 3:37 PM, Bill Freeman <ke1g...@gmail.com> wrote: > >> > That would be my guess. I presume that item.id is an int, so it's > >> > likely that you're passing berufe_id as a string. All the stuff that > >> > comes from the GET or POST attributes or request, and any > >> > arguments garnered by the url pattern are strings. If you're not > >> > converting it yourself, berufe_id will be a string, and: > > >> > >>> 1 == '1' > >> > False > >> > >>> > > >> > Do you have a view function, or are you fitting this into a generic > >> > view somehow? > > >> > Too bad that there doesn't seem to be a filter to invoke the int > >> > constructor, > >> > or a string method that does it. You could add a method to your model > >> > that returns id as a string, then > > >> > ...{% ifequal item.id_as_string berufe_id %}... > > >> {% ifequal item.id|stringformat:"s" berufe_id %} > > >> Cheers > > >> Tom > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
It's time to go back to figuring out just what these things are. Put back your code that shows you the variable values, except instead of {{ item.id }} and {{ berufe_id }} use --{{ item.id|stringformat:"%r" }}-- and --{{ berufe_id|stringformat:"%r%" }}-- The %r version will include quotes if it's a string, and will show any whitespace. The dashes are just to be sure we know where the object representation begins and ends. May we see the corresponding url pattern? I just want to be clear, however, that the best place to fix this is in a view function. Even if it is mostly a wrapper for a generic view function (capture all the arguments and then pass them on, after fixing up the berufe_id argument, and return what the generic view returns. This would also give a place to put a pdb.set_trace() so that you can really see what's going on without having to invent code to give you hints. In case you're not very pythonic, here's what fix-up code in such a view function would look like: try: berufe_id = int(berufe_id.strip()) except: pass Where the "pass" is you could instead return some error, or set berufe_id to the integer 1. Actually, while testing (DEBUG=True in settings.py), leave out the try, except, pass and just put in the berufe_id= line. Then if it can't convert it to an integer you will get a 500 with a nice debugging stacktrace that let's you look at variables in each stack frame, particularly that of the view function. My reasons for saying that this is the right place to fix it is that: 1. This only happens once per request, as opposed to once per select item per request; 2. You have the full power of python to fix whatever needs to be fixed; 3. I believe that comparing two integers is a bit faster than comparing two strings (unless both strings are interned, in which case you have the cost of interning each string generated through stringformat, which is even more expensive than a string compare; and 4. The template code, which may be manipulated by non-programmers, becomes clearer to understand. Bill On Wed, Mar 10, 2010 at 4:17 PM, wolle <wo...@upb.de> wrote: > Hi Tom, > > really cool idea, but it does not work... > > > -- Bitte Berufsgruppe wählen > -- > {% for item in berufe %} > berufe_id item.id| > stringformat:"s" %}selected{% endifequal %}>{{item.name}} > {% endfor %} > > > does not select any option... > > Any more hints? > > On Mar 10, 5:13 pm, Tom Evans <tevans...@googlemail.com> wrote: >> On Wed, Mar 10, 2010 at 3:37 PM, Bill Freeman <ke1g...@gmail.com> wrote: >> > That would be my guess. I presume that item.id is an int, so it's >> > likely that you're passing berufe_id as a string. All the stuff that >> > comes from the GET or POST attributes or request, and any >> > arguments garnered by the url pattern are strings. If you're not >> > converting it yourself, berufe_id will be a string, and: >> >> > >>> 1 == '1' >> > False >> > >>> >> >> > Do you have a view function, or are you fitting this into a generic >> > view somehow? >> >> > Too bad that there doesn't seem to be a filter to invoke the int >> > constructor, >> > or a string method that does it. You could add a method to your model >> > that returns id as a string, then >> >> > ...{% ifequal item.id_as_string berufe_id %}... >> >> {% ifequal item.id|stringformat:"s" berufe_id %} >> >> Cheers >> >> Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
Hi Tom, really cool idea, but it does not work... -- Bitte Berufsgruppe wählen -- {% for item in berufe %} {{item.name}} {% endfor %} does not select any option... Any more hints? On Mar 10, 5:13 pm, Tom Evans <tevans...@googlemail.com> wrote: > On Wed, Mar 10, 2010 at 3:37 PM, Bill Freeman <ke1g...@gmail.com> wrote: > > That would be my guess. I presume that item.id is an int, so it's > > likely that you're passing berufe_id as a string. All the stuff that > > comes from the GET or POST attributes or request, and any > > arguments garnered by the url pattern are strings. If you're not > > converting it yourself, berufe_id will be a string, and: > > > >>> 1 == '1' > > False > > >>> > > > Do you have a view function, or are you fitting this into a generic > > view somehow? > > > Too bad that there doesn't seem to be a filter to invoke the int > > constructor, > > or a string method that does it. You could add a method to your model > > that returns id as a string, then > > > ...{% ifequal item.id_as_string berufe_id %}... > > {% ifequal item.id|stringformat:"s" berufe_id %} > > Cheers > > Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
On Wed, Mar 10, 2010 at 11:13 AM, Tom Evans <tevans...@googlemail.com> wrote: > {% ifequal item.id|stringformat:"s" berufe_id %} Cool. I spend my filter investigation time looking for one that would convert berufe_id to an int (no joy). -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
On Wed, Mar 10, 2010 at 3:37 PM, Bill Freeman <ke1g...@gmail.com> wrote: > That would be my guess. I presume that item.id is an int, so it's > likely that you're passing berufe_id as a string. All the stuff that > comes from the GET or POST attributes or request, and any > arguments garnered by the url pattern are strings. If you're not > converting it yourself, berufe_id will be a string, and: > > >>> 1 == '1' > False > >>> > > Do you have a view function, or are you fitting this into a generic > view somehow? > > Too bad that there doesn't seem to be a filter to invoke the int constructor, > or a string method that does it. You could add a method to your model > that returns id as a string, then > > ...{% ifequal item.id_as_string berufe_id %}... > {% ifequal item.id|stringformat:"s" berufe_id %} Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
That would be my guess. I presume that item.id is an int, so it's likely that you're passing berufe_id as a string. All the stuff that comes from the GET or POST attributes or request, and any arguments garnered by the url pattern are strings. If you're not converting it yourself, berufe_id will be a string, and: >>> 1 == '1' False >>> Do you have a view function, or are you fitting this into a generic view somehow? Too bad that there doesn't seem to be a filter to invoke the int constructor, or a string method that does it. You could add a method to your model that returns id as a string, then ...{% ifequal item.id_as_string berufe_id %}... On Wed, Mar 10, 2010 at 10:23 AM, wolle <wo...@upb.de> wrote: > Already tried this several times. Here is a result of your code > > item.id = 1 with berufe_id = 1 > item.id = 2 with berufe_id = 1 > > Not sure if this a type (int vs. string) error? > > On Mar 10, 4:18 pm, Bill Freeman <ke1g...@gmail.com> wrote: >> Try adding code to render the values that you are trying to compare, >> so that you can see in what way they are not equal. They it will >> probably become obvious in what way the conversion through the >> GET or POST data and view isn't quite what you want. E.g.; before >> the select: >> >> berufe_id: {{ berufe_id }} >> {% for item in berufe %}{{ item.id }}{% endfor %} >> >> On Wed, Mar 10, 2010 at 8:01 AM, wolle <wo...@upb.de> wrote: >> > Hi everybody, >> >> > I have a question on the ifequal template tag. >> >> > I have an HTML select where people can filter the database entries. On >> > change of the selection I reload the page (new URL) and filter the >> > results. I append the selected value from the option to the request >> > (as berufe_id) and want to pre-select the chosen option with the >> > following code: >> >> > >> > -- Please select >> > -- >> > {% for item in berufe %} >> > > > ifequal item.id berufe_id %} >> > selected{% endifequal %}>{{item.name}} >> > {% endfor %} >> > >> >> > Somehow the equal check does not work. item.id is the id of the Object >> > iterator and berufe_id the selected value from the last selection... >> > {% ifequal item.id "2" %}selected{% endifequal %} seems to work >> > though... >> >> > Who can help me with this? >> >> > Thanks >> > Wolle >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "Django users" group. >> > To post to this group, send email to django-us...@googlegroups.com. >> > To unsubscribe from this group, send email to >> > django-users+unsubscr...@googlegroups.com. >> > For more options, visit this group >> > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
Already tried this several times. Here is a result of your code item.id = 1 with berufe_id = 1 item.id = 2 with berufe_id = 1 Not sure if this a type (int vs. string) error? On Mar 10, 4:18 pm, Bill Freeman <ke1g...@gmail.com> wrote: > Try adding code to render the values that you are trying to compare, > so that you can see in what way they are not equal. They it will > probably become obvious in what way the conversion through the > GET or POST data and view isn't quite what you want. E.g.; before > the select: > > berufe_id: {{ berufe_id }} > {% for item in berufe %}{{ item.id }}{% endfor %} > > On Wed, Mar 10, 2010 at 8:01 AM, wolle <wo...@upb.de> wrote: > > Hi everybody, > > > I have a question on the ifequal template tag. > > > I have an HTML select where people can filter the database entries. On > > change of the selection I reload the page (new URL) and filter the > > results. I append the selected value from the option to the request > > (as berufe_id) and want to pre-select the chosen option with the > > following code: > > > > > -- Please select > > -- > > {% for item in berufe %} > > > ifequal item.id berufe_id %} > > selected{% endifequal %}>{{item.name}} > > {% endfor %} > > > > > Somehow the equal check does not work. item.id is the id of the Object > > iterator and berufe_id the selected value from the last selection... > > {% ifequal item.id "2" %}selected{% endifequal %} seems to work > > though... > > > Who can help me with this? > > > Thanks > > Wolle > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ifequal issue
Try adding code to render the values that you are trying to compare, so that you can see in what way they are not equal. They it will probably become obvious in what way the conversion through the GET or POST data and view isn't quite what you want. E.g.; before the select: berufe_id: {{ berufe_id }} {% for item in berufe %}{{ item.id }}{% endfor %} On Wed, Mar 10, 2010 at 8:01 AM, wolle <wo...@upb.de> wrote: > Hi everybody, > > I have a question on the ifequal template tag. > > I have an HTML select where people can filter the database entries. On > change of the selection I reload the page (new URL) and filter the > results. I append the selected value from the option to the request > (as berufe_id) and want to pre-select the chosen option with the > following code: > > > -- Please select -- > {% for item in berufe %} > item.id berufe_id %} > selected{% endifequal %}>{{item.name}} > {% endfor %} > > > Somehow the equal check does not work. item.id is the id of the Object > iterator and berufe_id the selected value from the last selection... > {% ifequal item.id "2" %}selected{% endifequal %} seems to work > though... > > Who can help me with this? > > Thanks > Wolle > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
ifequal issue
Hi everybody, I have a question on the ifequal template tag. I have an HTML select where people can filter the database entries. On change of the selection I reload the page (new URL) and filter the results. I append the selected value from the option to the request (as berufe_id) and want to pre-select the chosen option with the following code: -- Please select -- {% for item in berufe %} {{item.name}} {% endfor %} Somehow the equal check does not work. item.id is the id of the Object iterator and berufe_id the selected value from the last selection... {% ifequal item.id "2" %}selected{% endifequal %} seems to work though... Who can help me with this? Thanks Wolle -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Is valid {% ifequal model.name "Mymodelname" %}??
I'm going to take a flier and guess that you want this to be conditional on the name of the class of an instance passed in the context. That is, you have a model class Foo, maybe another named Bar that you have an instance of the class, e.g.; x = Foo.objects.get(pk=1), and that you're passing it into a template, e.g.; context(..., model=x,...). In this case, try something like: {% ifequal model.__class__.__name__ "Foo" %} ... Remember, you can always temporarily add something like {{ model.name }} to the text to see what you're comparing to that string. Bill On Wed, Sep 2, 2009 at 11:44 AM, Sandra Django <sandradja...@gmail.com>wrote: > Hi friends, Can I do a condition depending on my model name? For example, I > did that: > {% ifequal model.name "Mymodelname" %} > do something > {% endifequal %} > > But don't work. Someone could help me? > > > > --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is valid {% ifequal model.name "Mymodelname" %}??
On Wed, Sep 2, 2009 at 4:44 PM, Sandra Django<sandradja...@gmail.com> wrote: > Hi friends, Can I do a condition depending on my model name? For example, I > did that: > {% ifequal model.name "Mymodelname" %} > do something > {% endifequal %} > > But don't work. Someone could help me? As part of your select could you tag the name as a hard coded column name and then check for it as a regular field? SELECT 'Mymodelname' AS `name`, other, fields, * FROM Mymodelname WHERE ... Not sure how you do it as a QuerySet though. -- Andrew McGregor 07940 22 33 11 --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Is valid {% ifequal model.name "Mymodelname" %}??
Hi friends, Can I do a condition depending on my model name? For example, I did that: {% ifequal model.name "Mymodelname" %} do something {% endifequal %} But don't work. Someone could help me? --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is valid {% ifequal model.name "Mymodelname" %}??
Be more specific, is model in the context ? is name a property of model ? On 2 sep, 17:44, Sandra Django <sandradja...@gmail.com> wrote: > Hi friends, Can I do a condition depending on my model name? For example, I > did that: > {% ifequal model.name "Mymodelname" %} > do something > {% endifequal %} > > But don't work. Someone could help me? --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a way to combine ifequal with ifequal/if?
On Sat, Aug 15, 2009 at 6:53 PM, Daniel Rosemanwrote: > > On Aug 15, 11:21 am, realfun wrote: > > Sigh, seems not better way, sometimes it's ugly also to put them on the > > views.py - A/B/C could be the attribute of an element among a list of > > elements. Say, A is x.A, B is y.B, C is z.C, then you need to create a > tuple > > for them on views side, and thus make a coupling for the order in the > tuple. > > > > Make everything into the views doesn't always work - at least doesn't > always > > work gracefully. > > > I think most people agree with that these days, and think the > restrictions on conditionals within the template language was probably > a bad idea. > > The best solution is to use SmilyChris's smart_if template tag: > http://www.djangosnippets.org/snippets/1350/ > which I think will allow most of the syntax you want. > -- > DR. > Thanks for the hint, I will try smart_if template tag. -- Zhongfang --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a way to combine ifequal with ifequal/if?
On Aug 15, 11:21 am, realfunwrote: > Sigh, seems not better way, sometimes it's ugly also to put them on the > views.py - A/B/C could be the attribute of an element among a list of > elements. Say, A is x.A, B is y.B, C is z.C, then you need to create a tuple > for them on views side, and thus make a coupling for the order in the tuple. > > Make everything into the views doesn't always work - at least doesn't always > work gracefully. > I think most people agree with that these days, and think the restrictions on conditionals within the template language was probably a bad idea. The best solution is to use SmilyChris's smart_if template tag: http://www.djangosnippets.org/snippets/1350/ which I think will allow most of the syntax you want. -- DR. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a way to combine ifequal with ifequal/if?
Sigh, seems not better way, sometimes it's ugly also to put them on the views.py - A/B/C could be the attribute of an element among a list of elements. Say, A is x.A, B is y.B, C is z.C, then you need to create a tuple for them on views side, and thus make a coupling for the order in the tuple. Make everything into the views doesn't always work - at least doesn't always work gracefully. On Sat, Aug 15, 2009 at 12:24 AM, Javier Guerrawrote: > > On Fri, Aug 14, 2009 at 11:18 AM, realfun wrote: > > Hi, > > I have met the situation like "if A==B or A==C: doSomething...", or, "if > > A==B or C: doSomething..." > > I found it's hard to express in Django template, and small though, so no > > meaning to write it as a filter. > > put the logic in the view function (or maybe in the model!) and hand a > simple boolean to the template > > > -- > Javier > > > > -- 代码发芽网: http://fayaa.com/code/ (无需插件支持blog代码高亮,100+种语言,30+种高亮主题) 游戏发芽网: http://fayaa.com/youxi/ (华容道、数独等在线游戏及求解、图解) 我的Blog: 半瓶墨水(http://www.2maomao.com/blog) Follow me @ http://twitter.com/realfun --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a way to combine ifequal with ifequal/if?
On Fri, Aug 14, 2009 at 11:18 AM, realfunwrote: > Hi, > I have met the situation like "if A==B or A==C: doSomething...", or, "if > A==B or C: doSomething..." > I found it's hard to express in Django template, and small though, so no > meaning to write it as a filter. put the logic in the view function (or maybe in the model!) and hand a simple boolean to the template -- Javier --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Is there a way to combine ifequal with ifequal/if?
Hi, I have met the situation like "if A==B or A==C: doSomething...", or, "if A==B or C: doSomething..." I found it's hard to express in Django template, and small though, so no meaning to write it as a filter. Current I did a redundancy way: {%ifequal A B%} blabla {%else%} {%ifequal A C%} blabla {%endifequal%} {%endifequal%} this is fare more complex than it should be, it even dup the code! Is there an easy way or hidden feature that could make a simple solution? --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: IFEQUAL takes two arguments error on Django 0.91
On Wed, Jun 10, 2009 at 5:43 PM, Frank Petersonwrote: > > I'm on Django 0.91 (unfortunately we are stuck with that and cannot > upgrade). > I have a really hard time believe you truly are stuck. Migration may not be the simplest in the short-run, but certainly sensible in the long-term. Who wants to use old, broken, incomplete code anyway? -- 401.837.8417 jasonbeaud...@gmail.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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: IFEQUAL takes two arguments error on Django 0.91
On Wed, Jun 10, 2009 at 5:43 PM, Frank Peterson <fictionalper...@gmail.com>wrote: > > I'm on Django 0.91 (unfortunately we are stuck with that and cannot > upgrade). > > We have a variable - object.caption and lets say that it equals > "Bling: whatever" (without the quotes) > > I am doing a hack in the templates (dont have access to anything else, > and need to output "IT WORKED!" (without the quotes) > > I am using the following code > > {% ifequal object.caption|lower|truncatewords:"1"|cut:": ..." "bling" > %}IT WORKED!{% endifequal %} > > It gives me "bling" when I output this {{ object.caption|lower| > truncatewords:"1"|cut:": ..." }} > however as soon as that code is in the ifequal it errors and says > > IFEQUAL takes two arguments error It has been a long time since Django .91 but if I were to see this error I would think that object.caption|lower|truncatewords:"1"|cut:": ..." is not return anything (is there a object.caption that doesn't have a value?) When you just place {{ object.caption|lower|truncatewords:"1"|cut:": ..." }} what is displayed? You can also put an if tag around to the ifequal tag to see if there is a object.caption|lower|truncatewords:"1"|cut:": ..." I hope that helps, Michael --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
IFEQUAL takes two arguments error on Django 0.91
I'm on Django 0.91 (unfortunately we are stuck with that and cannot upgrade). We have a variable - object.caption and lets say that it equals "Bling: whatever" (without the quotes) I am doing a hack in the templates (dont have access to anything else, and need to output "IT WORKED!" (without the quotes) I am using the following code {% ifequal object.caption|lower|truncatewords:"1"|cut:": ..." "bling" %}IT WORKED!{% endifequal %} It gives me "bling" when I output this {{ object.caption|lower| truncatewords:"1"|cut:": ..." }} however as soon as that code is in the ifequal it errors and says IFEQUAL takes two arguments error --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ifequal with a tuple value?
I can apply a filter to convert the request.GET.subseries value to an integer but is still does not match??? {% ifequal id request.GET.subseries|intvalue %} I have tried the other way round converting the id to an integer and keeping the request.GET.subseries as is and this again does not work. MMMmmm... On May 29, 12:50 pm, Rama Vadakattu <rama.vadaka...@gmail.com> wrote: > i hope you are encountering the problem as request.GET.subseries is > string and id is integer and they are not matching. > > On May 29, 3:52 pm, mbdtsmh <martin.harri...@astrazeneca.com> wrote: > > > I have the problem below when I use a tuple to try and match a request > > item; i.e., it never matches. I can do the same thing with a list > > rather than a tuple value and it works fine? I have tried to convert > > the tuple to a string but no joy - is there something obvious I'm > > missing??? > > > > > {% for id, subseries in SubSeriesChoice %} > > <li{% ifequal id request.GET.subseries %} > > class="selected"{% endifequal %}>{{ subseries }} > > {% endfor %} > > > > > SubSeriesChoice is a list of tuples... > > [(8L, u'Meta'), (9L, u'Para'), (10L, u'Ortho'), (123L, u'amides')] > > > any help would be very much appreciated. > > > Thanks, > > > Martin --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ifequal with a tuple value?
i hope you are encountering the problem as request.GET.subseries is string and id is integer and they are not matching. On May 29, 3:52 pm, mbdtsmh <martin.harri...@astrazeneca.com> wrote: > I have the problem below when I use a tuple to try and match a request > item; i.e., it never matches. I can do the same thing with a list > rather than a tuple value and it works fine? I have tried to convert > the tuple to a string but no joy - is there something obvious I'm > missing??? > > > {% for id, subseries in SubSeriesChoice %} > <li{% ifequal id request.GET.subseries %} > class="selected"{% endifequal %}>{{ subseries }} > {% endfor %} > > > SubSeriesChoice is a list of tuples... > [(8L, u'Meta'), (9L, u'Para'), (10L, u'Ortho'), (123L, u'amides')] > > any help would be very much appreciated. > > Thanks, > > Martin --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ifequal with a tuple value?
I have the problem below when I use a tuple to try and match a request item; i.e., it never matches. I can do the same thing with a list rather than a tuple value and it works fine? I have tried to convert the tuple to a string but no joy - is there something obvious I'm missing??? {% for id, subseries in SubSeriesChoice %} <li{% ifequal id request.GET.subseries %} class="selected"{% endifequal %}>{{ subseries }} {% endfor %} SubSeriesChoice is a list of tuples... [(8L, u'Meta'), (9L, u'Para'), (10L, u'Ortho'), (123L, u'amides')] any help would be very much appreciated. Thanks, Martin --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ifequal tag within nested for: html forms
On May 25, 2:29 pm, Pablo López <plval...@gmail.com> wrote: > {% ifequal str(problemImpact.description) > (impact.0) %} This is not valid Django template syntax - I am surprised it works at all. You can't call functions with parameters within Django templates. -- DR. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ifequal tag within nested for: html forms
Hi everyone, I am having problems with a string comparison in a django template and I'd very much appreciate some help here! This template is rendered from a view and gets to variables: - HTproblemImpact, a dictionary with strings as keys (the "problems") and Impact objects as values. The Impact class has two attributes: description (string) and value (integer). This dictionary contains the default impact for each problem type, which the user could change in the html form that I explain below. - IMPACT_CHOICES, a tuple with the possible impacts, as strings. For instance: IMPACT_CHOICES = ( ("HI", "high"), ("LO", "low"), ... ,) So this is part of my template: {% for problemType, problemImpact in HTproblemImpact.items %} {{ problemType }}: {{ problemImpact.description }} {% for impact in IMPACT_CHOICES %} {% else %} checked="false"> {% endifequal %} {{ impact.1 }} {% endfor %} {% endfor %} The problem here is that the ifequal tag *always* returns true. I could understand that it always returned false if it was a problem with different string codings, but I don't know how it can be always true. This is the HTML output for this part of the template: ProblemX: ME high medium low none ProblemY: ME high medium low none Any idea of how to fix it? Thanks a lot!! Pablo --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django ifequal crush in chinese
thanks Karen: i solved the problem, using u''[constant string like chinese charactor]'. i think using u'' means the string should be processed as unicode charactor, inside python ,change all to unicode to process. thanks again --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django ifequal crush in chinese
On Sat, May 9, 2009 at 6:10 AM, linvar <tanf...@gmail.com> wrote: > > hello everybody: > i cannot use {% ifequal var1 var2 %} to test if equal when > var1,var2 are UTF8 encoding. but if var1,var2 are ansi that is ok. you > know i am in chinese and alway catche such ugly encoding problem. > anyone can help. > thanks advanced! > Are you sure you are comparing two utf-8 encoded bytestrings? (Also, I think you mean ASCII, not ansi.) It sounds like you might have one Unicode object and one utf-8 encoded bytestring; these will not compare as equal with {% ifequal %}. If that is what you are doing your server (if you using the dev server) should also be printing a warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal (I actually find this a little surprising, as usually bytestrings are assumed to be utf-8 encoded within Django, so my initial guess would have been that comparing a unicode string to its utf-8 encoded bytestring value would have resulted in True from {% ifequal %}, but that doesn't seem to be the case.) Karen --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
django ifequal crush in chinese
hello everybody: i cannot use {% ifequal var1 var2 %} to test if equal when var1,var2 are UTF8 encoding. but if var1,var2 are ansi that is ok. you know i am in chinese and alway catche such ugly encoding problem. anyone can help. thanks advanced! --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to compare two different types in templates using ifequal
On Mon, 2009-03-02 at 01:41 -0800, eli wrote: [...] > I have no idea where is the bug... In all cases you are likely making assumptions about what the filters are returning that are likely not correct. One way Insert the values of the filters into your template and have a look at what they are returning. For example: {{ e.date_start|date:"j"|floatformat }} and so on. Bear in mind that this isn't going to be 100% reliable, since it will return the string form of whatever the result is and is the original results aren't strings, they won't necessarily compare as equal, even though their string forms are equal. However, if the string forms are different, that's certainly a big clue as to why they aren't comparing as equal. Regards, Malcolm --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to compare two different types in templates using ifequal
On Mar 2, 11:41 am, Alex Koshelev <daeva...@gmail.com> wrote: > Just now {% ifequal %} doesn't support filter expressions as arguments. So > you must prepare values by {% with %} tag before using them in {% ifequal > %}. Thank You, I will try it later.. ps. I'm sorry for double-post. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to compare two different types in templates using ifequal
Hi, I have a problem (Django 1.1. alpha SVN): Python: week = [1, 2, 3, 4, 5, 6, 7] # There are only two records in objects_list with date_start field = 01.01.2000 and 02.01.2000 objects_list = SomeModel.objects.all() Template: {% for day in week %} {% for e in objects_list %} {# date:"j" - return day of the month without leading zeros. #} {% ifequal e.date_start|date:"j" day %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: none. So, trying to set the same types: {% for day in week %} {% for e in objects_list %} {% ifequal e.date_start|date:"j"|floatformat day|floatformat %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... It should be only two times: I'm in... Another way: {% for day in week %} {% for e in objects_list %} {% ifequal e.date_start|date:"j"|floatformat day %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: none, and the last one {% for day in week %} {% for e in objects_list %} {% ifequal e.date_start|date:"j"|stringformat:"s" day| stringformat:"s" %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... I have no idea where is the bug... Thanks for help. regards. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to compare two different types in templates using ifequal
Just now {% ifequal %} doesn't support filter expressions as arguments. So you must prepare values by {% with %} tag before using them in {% ifequal %}. On Mon, Mar 2, 2009 at 12:22 PM, eli <eliasz.wont...@gmail.com> wrote: > > Hi, > > I have a problem: > > Python: > week = [1, 2, 3, 4, 5, 6, 7] > # There are only two records in objects_list with date_start field = > 01.01.2000 and 02.01.2000 > objects_list = SomeModel.objects.all() > > Template: > > {% for day in week %} > {% for e in objects_list %} >{% ifequal e.date_start|date:"j" day %} > I'm in... >{% endifequal %} > {% endfor %} > {% endfor %} > > Output: none. So, trying to set the same types: > > {% for day in week %} > {% for e in objects_list %} >{% ifequal e.date_start|date:"j"|floatformat day|floatformat %} > I'm in... >{% endifequal %} > {% endfor %} > {% endfor %} > > Output: > I'm in... > I'm in... > I'm in... > I'm in... > I'm in... > I'm in... > I'm in... > > It should be only two times: I'm in... > > Another way: > > {% for day in week %} > {% for e in objects_list %} >{% ifequal e.date_start|date:"j"|floatformat day %} > I'm in... >{% endifequal %} > {% endfor %} > {% endfor %} > > Output: none, and the last one > > {% for day in week %} > {% for e in objects_list %} >{% ifequal e.date_start|date:"j"|stringformat:"s" day| > stringformat:"s" %} > I'm in... >{% endifequal %} > {% endfor %} > {% endfor %} > > Output: > I'm in... > I'm in... > I'm in... > I'm in... > I'm in... > I'm in... > I'm in... > > I have no idea where is the bug... > > Thanks for help. > > regards. > > > > --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to compare two different types in templates using ifequal
Hi, I have a problem: Python: week = [1, 2, 3, 4, 5, 6, 7] # There are only two records in objects_list with date_start field = 01.01.2000 and 02.01.2000 objects_list = SomeModel.objects.all() Template: {% for day in week %} {% for e in objects_list %} {% ifequal e.date_start|date:"j" day %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: none. So, trying to set the same types: {% for day in week %} {% for e in objects_list %} {% ifequal e.date_start|date:"j"|floatformat day|floatformat %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... It should be only two times: I'm in... Another way: {% for day in week %} {% for e in objects_list %} {% ifequal e.date_start|date:"j"|floatformat day %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: none, and the last one {% for day in week %} {% for e in objects_list %} {% ifequal e.date_start|date:"j"|stringformat:"s" day| stringformat:"s" %} I'm in... {% endifequal %} {% endfor %} {% endfor %} Output: I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... I'm in... I have no idea where is the bug... Thanks for help. regards. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: template ifequal substitution of value
I figured out what to do. I created a new instance in the view.py: def search(request): newdate='1999' In the template I used the "Y" for both instances and was able to get the comparison to work: {% ifequal items.startdt|date:"Y" newdate|date:"Y" %} this does the correct comparison {% endifequal %} --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
template ifequal substitution of value
I have two date fields: startdt and enddt. The template code that works is: {% ifequal items.startdt items.enddt %} this says startdt and enddt are the same (as seen in the template) {% endifequal %} In postgres I have a date value in the startdt and enddt fields stored like this: 1999-01-08, which appears as Jan 08, 1999 in the template. I would like the Jan 08, 1999 value to appear as blank or nothing in the template. I tried this: {% ifequal items.startdt "1999-01-08" %} (this space should show nothing) (as not seen in the template) {% endifequal %} I get no error, but I also get no action for this syntax, either. Any help would be appreciated. --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ifequal and DateQuerySet objects
On Feb 3, 10:03 am, brad <bkmontgom...@gmail.com> wrote: > You could use the built-in __str__ method on now.year. > In [11]: now.year.__str__() > Out[11]: '2009' > > In [12]: now.year.__str__() == '2009' > Out[12]: True > > In your template you'd do something like this: > {% ifequal year month.year.__str__ %} Doh! I didn't even think about the built-in methods being available in templates. Thanks! --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ifequal and DateQuerySet objects
On Feb 2, 6:37 pm, Bret W <bretwal...@gmail.com> wrote: > I've run into a problem with ifequal in one of my templates. > > I'm using date-based generic view to display all objects for a given > year. > urls.py: > (r'^taken/(?P\d{4})/$' ... > > Part of the extra_context I pass is a DateQuerySet object: > months = Photo.objects.dates('date_taken', 'month', order='DESC') > > In my template, I have the following: > {% for month in months %} > {% ifequal year month.year %} > ... > > It always evaluates to false. > > I know this is because Python won't handle the casting: > > > > >>> from datetime import datetime > >>> now = datetime.now() > >>> now.year == 2009 > True > >>> now.year == "2009" > False > > So, is it possible to handle this comparison in the template? You could use the built-in __str__ method on now.year. In [11]: now.year.__str__() Out[11]: '2009' In [12]: now.year.__str__() == '2009' Out[12]: True In your template you'd do something like this: {% ifequal year month.year.__str__ %} --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ifequal and DateQuerySet objects
I've run into a problem with ifequal in one of my templates. I'm using date-based generic view to display all objects for a given year. urls.py: (r'^taken/(?P\d{4})/$' ... Part of the extra_context I pass is a DateQuerySet object: months = Photo.objects.dates('date_taken', 'month', order='DESC') In my template, I have the following: {% for month in months %} {% ifequal year month.year %} ... It always evaluates to false. I know this is because Python won't handle the casting: >>> from datetime import datetime >>> now = datetime.now() >>> now.year == 2009 True >>> now.year == "2009" False >>> So, is it possible to handle this comparison in the template? --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with encoding and using ifequal in Django templates
On Tue, 2009-01-27 at 09:25 -0800, Ben Gerdemann wrote: > Hello, > > I'm having problems using {% ifequal s1 "some text" %} to compare > strings with extended characters in Django templates. When string s1 > contains ascii characters >127, I get exceptions in the template > rendering. I know you've solved this yourself, but for future reference: there are no such animals as "ASCII characters > 127". ASCII is a 7-bit encoding. You could be talking about UTF-8 bytes or Unicode characters (codepoints) in that range (or ISO-8859-1 or other encoding of choice), but not ASCII. Using the right terms for future problems will avoid any "wtf?!" moments on the part of the readers. Regards, Malcolm --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with encoding and using ifequal in Django templates
Sometimes there's nothing like describing a problem to someone else to help you solve it. :) I should have marked the Python strings as Unicode like this and everything works now: def test(request): return render_to_response("test.html", { "s1": u"dados", "s2": u"aprovação", } ) --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem with encoding and using ifequal in Django templates
Hello, I'm having problems using {% ifequal s1 "some text" %} to compare strings with extended characters in Django templates. When string s1 contains ascii characters >127, I get exceptions in the template rendering. What am I doing wrong? I'm using UTF-8 coding throughout the rest of application in both the data, templates and Python code without any problems. Any ideas? Cheers, Ben views.py def test(request): return render_to_response("test.html", { "s1": "dados", "s2": "aprovação", } ) test.html s1={{s1}} s2={{s2}} {% ifequal s1 "dados" %} s1="dados" is true {% endifequal %} {% ifequal s1 "aprovação" %} s1="aprovação" is true {% endifequal %} {% comment %} The following two comparions cause the following exception: Caught an exception while rendering: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128) {% ifequal s2 "dados" %} s2="dados" is true {% endifequal %} {% ifequal s2 "aprovação" %} s2="aprovação" is true {% endifequal %} {% endcomment %} {% ifequal s2 u"dados" %} s2="dados" is true {% endifequal %} {% comment %} The following comparison causes the following exception: Caught an exception while rendering: 'ascii' codec can't encode characters in position 8-9: ordinal not in range(128) {% ifequal s2 u"aprovação" %} s2="aprovação" is true {% endifequal %} {% endcomment %} Output s1=dados s2=aprovação s1="dados" is true --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ifequal with floatformat:"0" doesn't work
Just now {% ifequal %} tag doesn't apply filters to its operands. On Tue, Jan 20, 2009 at 2:58 PM, ltcstyle <ltcst...@gmail.com> wrote: > > is this a bug or what? > > {{float_number|floatformat:"0"}} give me correct number 1 > > but > {% ifequal float_number|floatformat:"0" 1 %} > never match > > Any ideas? > > Thanks > > > > > > --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
ifequal with floatformat:"0" doesn't work
is this a bug or what? {{float_number|floatformat:"0"}} give me correct number 1 but {% ifequal float_number|floatformat:"0" 1 %} never match Any ideas? Thanks --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: {% ifequal %} Confusion
On Sun, 2008-11-23 at 21:52 -0800, Andy Young wrote: > Hi all, > > I've attempted a shortcut in an {% ifequal %} tag and ran into some > unexpected consequences. Basically, I have two DateFields in a model > named begin_date and end_date. I am iterating through field names > ({{ f }}) and their corresponding values ({{ item|getattr:f }}) to > populate a webpage. I want to catch these date-related field names to > apply different formatting using the "date" filter. > > What worked: > > {% ifequal f 'begin_date' %} > blah blah blah > {% else %}{% ifequal f 'end_date' %} > blah blah blah > {% endifequal %}{% endifequal %} > > What didn't work: > > {% ifequal f|slice:"-4:" 'date' %} blah blah blah {% endifequal > %} (matches no fields) > nor {% ifequal f|slice:"-4:" u'date' %} blah blah blah {% endifequal > %}(matches all fields) > nor {% ifequal f|slice:"-4:" date %} blah blah blah {% endifequal > %} (matches all fields) > > I would imagine the "slice" filter returns a string, which is why I'm > perplexed the 'date' string didn't match. I'm probably missing some > nuance involving unicode string formatting, etc. Long-term bug in Django that we really will fix before 1.1 (because it's embarrassing and makes us look kind of silly): The ifequal tag (and a few others) don't correctly handle any kind of filtering on their argument. Regards, Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
{% ifequal %} Confusion
Hi all, I've attempted a shortcut in an {% ifequal %} tag and ran into some unexpected consequences. Basically, I have two DateFields in a model named begin_date and end_date. I am iterating through field names ({{ f }}) and their corresponding values ({{ item|getattr:f }}) to populate a webpage. I want to catch these date-related field names to apply different formatting using the "date" filter. What worked: {% ifequal f 'begin_date' %} blah blah blah {% else %}{% ifequal f 'end_date' %} blah blah blah {% endifequal %}{% endifequal %} What didn't work: {% ifequal f|slice:"-4:" 'date' %} blah blah blah {% endifequal %} (matches no fields) nor {% ifequal f|slice:"-4:" u'date' %} blah blah blah {% endifequal %} (matches all fields) nor {% ifequal f|slice:"-4:" date %} blah blah blah {% endifequal %} (matches all fields) I would imagine the "slice" filter returns a string, which is why I'm perplexed the 'date' string didn't match. I'm probably missing some nuance involving unicode string formatting, etc. --~--~-~--~~~---~--~~ 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: ifequal and numbers
On Oct 27, 10:36 pm, "Alfredo Alessandrini" <[EMAIL PROTECTED]> wrote: > There is a method for write this, without write a loop: > > {% ifequal apple.number <20 %} > .. > {% endifequal %} > > Alfredo On Oct 27, 11:52 pm, "R. Gorman" <[EMAIL PROTECTED]> wrote: > You would probably be better off writing a custom template tag (http:// > docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom- > template-tags). > > R. Actually a filter would be easier. A filter can return True or False, so you would just do def islessthan(var1, var2): return var1http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ifequal and numbers
You would probably be better off writing a custom template tag (http:// docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom- template-tags). R. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ifequal and numbers
There is a method for write this, without write a loop: {% ifequal apple.number <20 %} .. {% endifequal %} Alfredo --~--~-~--~~~---~--~~ 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: ifequal doesn't like spaces?
On Wed, 2008-10-15 at 19:39 -0400, Karen Tracey wrote: > On Wed, Oct 15, 2008 at 4:02 PM, Frank Peterson > <[EMAIL PROTECTED]> wrote: > > I have something like the following > > {% ifequal flatpage.title "Special Reports" %} > src="http://example.com/icon_specialreports.png; /> > {% endifequal %} > > I get the error > 'ifequal' takes two arguments > so it doesn't like the fact that "Special Reports" has a space > in it. > > Is there a way around this? > > I'm on Django 0.91 (I cannot upgrade, because it's our > corporate > system and they have to upgrade it). > > This was ticket #1522 fixed in revision 3112. Sorry, no bright ideas > for avoiding the restriction occur to me, though I'll admit my > inclination to do creative thinking to work around things that were > fixed 2+ years ago is not high. Perhaps looking at how it was fixed > will give you some ideas. A not uncommon "workaround" for cases like this is to take Django's existing ifequals tag and put it in your own templatetag library under a different name. Then you would load this library of tags that only exist in the future and call it using the new name (rather than ifequals). So you're using Django's current code with only slight modifications. Regards, Malcolm > --~--~-~--~~~---~--~~ 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: ifequal doesn't like spaces?
On Wed, Oct 15, 2008 at 4:02 PM, Frank Peterson <[EMAIL PROTECTED]>wrote: > > I have something like the following > > {% ifequal flatpage.title "Special Reports" %} >http://example.com/icon_specialreports.png; /> > {% endifequal %} > > I get the error > 'ifequal' takes two arguments > so it doesn't like the fact that "Special Reports" has a space in it. > > Is there a way around this? > > I'm on Django 0.91 (I cannot upgrade, because it's our corporate > system and they have to upgrade it). > This was ticket #1522 fixed in revision 3112. Sorry, no bright ideas for avoiding the restriction occur to me, though I'll admit my inclination to do creative thinking to work around things that were fixed 2+ years ago is not high. Perhaps looking at how it was fixed will give you some ideas. Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ifequal doesn't like spaces?
I have something like the following {% ifequal flatpage.title "Special Reports" %} http://example.com/icon_specialreports.png; /> {% endifequal %} I get the error 'ifequal' takes two arguments so it doesn't like the fact that "Special Reports" has a space in it. Is there a way around this? I'm on Django 0.91 (I cannot upgrade, because it's our corporate system and they have to upgrade it). --~--~-~--~~~---~--~~ 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: AND OR in ifequal
On Aug 22, 8:00 am, Will Rocisky <[EMAIL PROTECTED]> wrote: > how do you put AND, OR in ifequal statement of django? Use nested if statements that use one operator at a time. There's an example towards the end of the IF tag documentation here: http://www.djangoproject.com/documentation/templates/#if -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 -~--~~~~--~~--~--~---
AND OR in ifequal
how do you put AND, OR in ifequal statement of django? --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
2 bruno: > Not my opinion. Custom tags are to Django's templating language what > functions are to Python. I don't think that this is official django developers opinion. --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
> I can't see > how the ifless tag would be useful to the majority of users. Zinovil > really hasn't provided many real life examples either. I can tell you lots of examples. {% ifless accounts.count 50 %} show Paginator {% else %} don't show Paginator {% endifless %} > Oh and as far as I know, you can't combine the hypothetical ifless tag > and the ifequal tag to achieve the effect of the (again hypothetical) > iflessthanorequal tag. Yes, you right, iflessorequal is also should be included. > The same goes for imitating "ifgreater" with > "not iflessthanorequal". Am I correct? "ifgreaterorequal a b" is the same as "ifless b a" and wise versa Zinovii --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
I've always felt that Django provides a lot of stuff out of the box that most other frameworks don't. To name a few: auth, admin, sites, contenttypes, permissions, comments etc. Maybe some have gotten too much of the good thing and are now wanting for more? :) On the other hand, even though I agree that some other things could be built in as well in addition to the ones I listed, such as thumbnail generation, database migration support, and a few more, I can't see how the ifless tag would be useful to the majority of users. Zinovil really hasn't provided many real life examples either. Oh and as far as I know, you can't combine the hypothetical ifless tag and the ifequal tag to achieve the effect of the (again hypothetical) iflessthanorequal tag. The same goes for imitating "ifgreater" with "not iflessthanorequal". Am I correct? Erik On 20.08.2008, at 12:09, woeye wrote: > > I think it's ok that the Django team wants to keep the codebase clean > and maintainable. But from an endusers point of view I understand > Zinovii's position, too. Sometimes I feel that Django's feature set is > very basic and provides only the bare minimum to get started. For real > work you have to write your own extensions, such as template tags, > first. Though this approach frees the Django development team from > maintaining more code, the downside is, that this approach shifts the > burden to the enduser of Django. Now the enduser has to maintain his > own code. And it's not only one enduser, but a lot of endusers, each > one maintaining its own version. > As an enduser, how focuses on getting a site ready-to-work, I'd like > to have a ready-to-use framework which provides all the tools I need > to get my job done. Why to reinvent the wheel everytime? > > Still, I do understand the position of the Django development team. > But maybe there will be some time after 1.0 > to look at the feature set of Django and think about how to enrich the > experience for the enduser :-) > >> Not my opinion. Custom tags are to Django's templating language what >> functions are to Python. Would you advice to avoid writing functions >> "unless you really need some (function) that you can't live without >> and you know what are you doing" ? > > > --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
I think it's ok that the Django team wants to keep the codebase clean and maintainable. But from an endusers point of view I understand Zinovii's position, too. Sometimes I feel that Django's feature set is very basic and provides only the bare minimum to get started. For real work you have to write your own extensions, such as template tags, first. Though this approach frees the Django development team from maintaining more code, the downside is, that this approach shifts the burden to the enduser of Django. Now the enduser has to maintain his own code. And it's not only one enduser, but a lot of endusers, each one maintaining its own version. As an enduser, how focuses on getting a site ready-to-work, I'd like to have a ready-to-use framework which provides all the tools I need to get my job done. Why to reinvent the wheel everytime? Still, I do understand the position of the Django development team. But maybe there will be some time after 1.0 to look at the feature set of Django and think about how to enrich the experience for the enduser :-) > Not my opinion. Custom tags are to Django's templating language what > functions are to Python. Would you advice to avoid writing functions > "unless you really need some (function) that you can't live without > and you know what are you doing" ? --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
On 19 août, 19:44, Zinovii Dmytriv <[EMAIL PROTECTED]> wrote: > You didn't convince me. > > If somebody ask you "When I should write my custom tags?" - the answer > should be - "You shouldn't, unless you really need some tags that you > can't live without and you know what are you doing." Not my opinion. Custom tags are to Django's templating language what functions are to Python. Would you advice to avoid writing functions "unless you really need some (function) that you can't live without and you know what are you doing" ? --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
> But we're not talking about 'extensions of framework code' here. We're > talking about a custom tag, which is using an explicit piece of > functionality already provided by the framework: the ability to write > your own tags. We started this thread from the bug in ifequal. But now we are talking that django missing important tag - ifless. Which should be built-in. > This is no more extending the code than is writing your > own views, and I'm sure you won't claim that Django should provide all > possible views so that you would only have to write your own if it's > really necessary. tags and views are on totally different level. It's like brick and building. Django developers supply bricks and I'm building buildings. It's ok if you have 1 project and you supporting 1 project for 5 years then you can write custom tag. But if you have 20 and you want to update them because django moved from 1.0 to 2.0, and then to 3.0. So functional which was deprecated are not more available. Then you have to patch all 20... Everybody should avoid custom tags unless you can't build application without them. --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
On Aug 19, 7:48 pm, Zinovii Dmytriv <[EMAIL PROTECTED]> wrote: > I'm very happy that django is very flexible - this is great. But Rule > of thumb is to avoid extensions of framework code unless it's really- > really necessary. ifless is not that case. It just should be built-in. But we're not talking about 'extensions of framework code' here. We're talking about a custom tag, which is using an explicit piece of functionality already provided by the framework: the ability to write your own tags. This is no more extending the code than is writing your own views, and I'm sure you won't claim that Django should provide all possible views so that you would only have to write your own if it's really necessary. -- DR. --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
2 Join.Together > That system will not go through any such changes in the foreseeable > future, because that would be a backwards-incompatible change If you are talking about "ifequal doesn't evaluate expressions" - that it was bug. And it was fixed for 1.0 anyway. If you are talking about "ifless" - it's a new feature request. Then I didn't get what backwards-incompatible you are talking? Nothing is going to be changed just new standard tag implemented. Regards, Zinovii --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
I'm very happy that django is very flexible - this is great. But Rule of thumb is to avoid extensions of framework code unless it's really- really necessary. ifless is not that case. It just should be built-in. Like Malcolm said about ifequal: > Equality is a natural operation for all sorts of object types. I agree > "The "less than" comparison only applies to things that have a natural > ordering." Fine, I think ordering is also natural for programing languges. It doesn't always have a lot of sense (like compare objects, or string versus integers) but it's your problems be carefully... If-else is conditional construct by definition of any programming language (template language pretend to be subset of regular programing language). By condition means to check statement is True or False. Lets remove conditional "if" statement from Python 3000 to avoid comparing things that are not in natural order. It would be fun! :) Zinovii --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
If they aren't sufficiently essential for you to use them as custom tags, they surely can't be essential for the core. regards Steve Zinovii Dmytriv wrote: > You didn't convince me. > > If somebody ask you "When I should write my custom tags?" - the answer > should be - "You shouldn't, unless you really need some tags that you > can't live without and you know what are you doing." > > PS: Also in django-template-utils enough to have if_less - > if_greater, if_greater_or_equal, if_less_or_equal are useless. > > Zinovii > > > On Aug 19, 6:59 am, "[EMAIL PROTECTED]" > <[EMAIL PROTECTED]> wrote: >> On Aug 18, 4:05 pm,zdmytriv<[EMAIL PROTECTED]> wrote: >> >>> It's always bad idea to extend somebodies tool because when you wanted >>> to update current version with latest you can be in trouble. Latest >>> doesn't always support previous. >>> i.e. Django 1.0 uses Variable class to process variable from template >>> but 0.96 uses plain function resolve_variable() which is deprecated in >>> 1.0. >>> Zinovii >> That system will not go through any such changes in the foreseeable >> future, because that would be a backwards-incompatible change, which >> the developers have committed to avoiding. There is a whole system >> geared specifically towards custom template tags, so there is no need >> to hack away at it and there is no danger of your code becoming >> useless 2 weeks from now. -- 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 -~--~~~~--~~--~--~---
Re: ifequal doesn't evaluate expressions
You didn't convince me. If somebody ask you "When I should write my custom tags?" - the answer should be - "You shouldn't, unless you really need some tags that you can't live without and you know what are you doing." PS: Also in django-template-utils enough to have if_less - if_greater, if_greater_or_equal, if_less_or_equal are useless. Zinovii On Aug 19, 6:59 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Aug 18, 4:05 pm,zdmytriv<[EMAIL PROTECTED]> wrote: > > > It's always bad idea to extend somebodies tool because when you wanted > > to update current version with latest you can be in trouble. Latest > > doesn't always support previous. > > i.e. Django 1.0 uses Variable class to process variable from template > > but 0.96 uses plain function resolve_variable() which is deprecated in > > 1.0. > > > Zinovii > > That system will not go through any such changes in the foreseeable > future, because that would be a backwards-incompatible change, which > the developers have committed to avoiding. There is a whole system > geared specifically towards custom template tags, so there is no need > to hack away at it and there is no danger of your code becoming > useless 2 weeks from now. --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
> http://code.google.com/p/django-template-utils/ Yeah I saw it and it would be great to have django utils also for current stable version (0.96). Those are for 1.0 and 1.0 is not released yet. Even if release is on 1 September I'm still not going to install it. I'll wait few months for the first patches. Anyway I wrote it for myself. --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
On Aug 18, 4:05 pm, zdmytriv <[EMAIL PROTECTED]> wrote: > It's always bad idea to extend somebodies tool because when you wanted > to update current version with latest you can be in trouble. Latest > doesn't always support previous. > i.e. Django 1.0 uses Variable class to process variable from template > but 0.96 uses plain function resolve_variable() which is deprecated in > 1.0. > > Zinovii That system will not go through any such changes in the foreseeable future, because that would be a backwards-incompatible change, which the developers have committed to avoiding. There is a whole system geared specifically towards custom template tags, so there is no need to hack away at it and there is no danger of your code becoming useless 2 weeks from now. --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
On Mon, Aug 18, 2008 at 11:05 PM, zdmytriv <[EMAIL PROTECTED]> wrote: > >> That's one good reason why it's not needed in core. If you need it and >> you understand the trade-offs and consequences, you can implement it >> immediately with no break in the flow. Django's supported third-party >> template tags since day 1 (and even earlier). :-) > > It's always bad idea to extend somebodies tool because when you wanted > to update current version with latest you can be in trouble. Latest > doesn't always support previous. > i.e. Django 1.0 uses Variable class to process variable from template > but 0.96 uses plain function resolve_variable() which is deprecated in > 1.0. Changes like this one can hardly be the reason for your complaints. If you had written an ifless template tag yourself (which took 3 minutes to write) you'd maybe need 2 minutes more after a year fixing it for current trunk. I'd say compared to other work that is necessary to keep websites up-to-date. This stuff will not go into Django before 1.0, and there were no good points raised in this thread why it should go in after that. You don't need to extend core just to get these template tags -- you don't even need to write them yourself or keep them up-to-date, since somebody else is already doing this: http://code.google.com/p/django-template-utils/ See the comparison templatetag library. --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
> However the implementation of such a > tag would be unlikely to need much patching in the future "... patching in the future" No comments... > so Malcolm's > advice about implementing it yourself would be acceptable, I'd have thought. No comments... Zinovii --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
zdmytriv wrote: > 2 Steve: > > >> That's no way to endear yourself to the Django community. The >> development team has some pretty good brains. >> > > I agree, I was too aggressive, sorry about that. Just can't believe > that bug like this can be on this level. > I'd argue that it isn't a bug, it's a feature there by design. > What about ifless? Is it going to be implemented in 1.0 also? > >> I very much doubt it. >> > > It doesn't look like... I hope... > > No, Django's in feature freeze now. However the implementation of such a tag would be unlikely to need much patching in the future, so Malcolm's advice about implementing it yourself would be acceptable, I'd have thought. regards Steve --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
> That's one good reason why it's not needed in core. If you need it and > you understand the trade-offs and consequences, you can implement it > immediately with no break in the flow. Django's supported third-party > template tags since day 1 (and even earlier). :-) It's always bad idea to extend somebodies tool because when you wanted to update current version with latest you can be in trouble. Latest doesn't always support previous. i.e. Django 1.0 uses Variable class to process variable from template but 0.96 uses plain function resolve_variable() which is deprecated in 1.0. Zinovii --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
2 Steve: > That's no way to endear yourself to the Django community. The > development team has some pretty good brains. I agree, I was too aggressive, sorry about that. Just can't believe that bug like this can be on this level. > > What about ifless? Is it going to be implemented in 1.0 also? > > I very much doubt it. It doesn't look like... I hope... Zinovii --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
On Mon, 2008-08-18 at 13:37 -0700, zdmytriv wrote: > 2 Malcolm: > > > It makes a lot of sense when you think about what they can apply to. > > Equality is a natural operation for all sorts of object types. The > "less > > than" comparison only applies to things that have a natural > ordering. > > The first set is much larger than the second. > > A normal use for "ifequal" is testing string values for equality. > not so > > much for doing mathematical comparisons. [...] > You still can compare them and python is not going to complain and > more you can compare even objectA < 1... I used the word "natural" in my original post for a reason. You can certainly compare these objects, but it's not particularly sensible. We already have enough problems with people comparing visually similar, but actually unlike, objects and having equality fail. Introducing ordering operations would lead to further confusion. > I still can't get why not to implement ifless. It's like 3 min of > coding. That's one good reason why it's not needed in core. If you need it and you understand the trade-offs and consequences, you can implement it immediately with no break in the flow. Django's supported third-party template tags since day 1 (and even earlier). :-) Anyway, it's all a moot point. Feature freeze is in place. Let's move onwards to 1.0. Regards, Malcolm --~--~-~--~~~---~--~~ 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: ifequal doesn't evaluate expressions
2 Malcolm: > It makes a lot of sense when you think about what they can apply to. > Equality is a natural operation for all sorts of object types. The "less > than" comparison only applies to things that have a natural ordering. > The first set is much larger than the second. > A normal use for "ifequal" is testing string values for equality. not so > much for doing mathematical comparisons. I'm disagree. ifequal at the end goes to python level of equality. So 1. a = 1, b = 1.0 2. a = 1, b = "1" ifequal 1 1.0 # True ifequal 1 "1" # False So looks like dynamic typecasting works. For example: class ClassA(object): pass class ClassB(object): pass objectA = ClassA() objectB = ClassB() if objectA < objectB: print "A < B" else: print "A > B" You still can compare them and python is not going to complain and more you can compare even objectA < 1... If you dig deeper into realization level, into django/template/ defaulttags.py: class IfEqualNode(Node): ... def render(self, context): ... if (self.negate and val1 != val2) or (not self.negate and val1 == val2): return self.nodelist_true.render(context) ... So comparison is nothing but python == and !=. I still can't get why not to implement ifless. It's like 3 min of coding. Zinovii --~--~-~--~~~---~--~~ 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: ifequal with url pattern?
what about ifequal flatpage.url[:len('/products/')] '/products/' so you always check the beginning of the url V On Jul 18, 11:38 pm, Eliza <[EMAIL PROTECTED]> wrote: > Hi, > > I'm new to Django and am working on a template, and I have the feeling > I may be approaching something the wrong way. > > I have a navigation bar that is produced in the template, but needs to > look slightly different for each page, because it should have the menu > item for the current page highlighted. > > My current approach is to have a series of {% ifequal ... %} > statements in the template, along these lines: > . > . > . > {% ifequal flatpage.url '/products/' %} > // draw the products menu item highlighted > {% endifequal %} > {% ifequal flatpage.url '/blog/' %} > // draw the blog menu item highlighted > {% endifequal %} > > ...and so on. > > This works fine for now, but will break as soon as there are any sub- > pages under any of these sections. For example, I want to be able to > add a '/products/foo/' page, which contains detailed info about the > Foo product, and I want the "Products" menu bar item to remain > highlighted when this page is displayed. Since '/products/foo/' is not > equal to '/products/', the current code won't work for this. > > One extremely inelegant solution would be to simply extend my list of > {% ifequal ... %}s in the template, to test for each sub-page of / > products/ separately. But the fact that this is even occurring to me > leads me to believe I'm going about this the wrong way. > > Is there a better approach? > > Thanks, > Eliza --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ifequal with url pattern?
Hi, I'm new to Django and am working on a template, and I have the feeling I may be approaching something the wrong way. I have a navigation bar that is produced in the template, but needs to look slightly different for each page, because it should have the menu item for the current page highlighted. My current approach is to have a series of {% ifequal ... %} statements in the template, along these lines: . . . {% ifequal flatpage.url '/products/' %} // draw the products menu item highlighted {% endifequal %} {% ifequal flatpage.url '/blog/' %} // draw the blog menu item highlighted {% endifequal %} ...and so on. This works fine for now, but will break as soon as there are any sub- pages under any of these sections. For example, I want to be able to add a '/products/foo/' page, which contains detailed info about the Foo product, and I want the "Products" menu bar item to remain highlighted when this page is displayed. Since '/products/foo/' is not equal to '/products/', the current code won't work for this. One extremely inelegant solution would be to simply extend my list of {% ifequal ... %}s in the template, to test for each sub-page of / products/ separately. But the fact that this is even occurring to me leads me to believe I'm going about this the wrong way. Is there a better approach? Thanks, Eliza --~--~-~--~~~---~--~~ 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: Trying to get ifequal to evaluate to True
On Jun 30, 9:00 pm, "Paolo Ambrosio" <[EMAIL PROTECTED]> wrote: > I just built a test application and it works for me, if I understood > what is your problem. > [...] > P.S. > I am using the trunk > Many thanks for taking out the time to build a test application. I really appreciate that. Thanks. Trying to follow in with your example, I realised what was going wrong. The login template I am working with extends a base template, and so naturally fills in blocks only from the parent template. The {% ifequal %} expression, for some reason that didn't stand out before, was placed outside of any of the required main blocks. No sooner than I moved the expression inside one of the main blocks that it started to work as expected. Many thanks, again. :) -- Ayaz Ahmed Khan --~--~-~--~~~---~--~~ 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: Trying to get ifequal to evaluate to True
On Mon, Jun 30, 2008 at 5:14 PM, Ayaz Ahmed Khan <[EMAIL PROTECTED]> wrote: > > On Jun 30, 8:05 pm, "Paolo Ambrosio" <[EMAIL PROTECTED]> > wrote: >> On Mon, Jun 30, 2008 at 4:52 PM, Ayaz Ahmed Khan >> >> <[EMAIL PROTECTED]> wrote: >> > [...] The variable "next" >> > does have that particular value (I verified both by printing it out >> > and by making sure {% if next %} evaluates to True). However, the >> > "ifequal" expression just doesn't work. >> >> Are you passing it through the context while invoking the template? > > I, myself, am not passing that particular value. I am calling the > built-in login view provided by Django -- which is ``from > django.contrib.auth.views import login''. That view passes the "next" > as part of the context while rendering the login template. I just built a test application and it works for me, if I understood what is your problem. I created a view protected by the @login_required decorator, mapped to two different urls: 1) /accounts/test1/ 2) /accounts/test2/ The login_required redirects to /accounts/login/?next=... that calls the same view you are using. And this is my template ("registration/login.html"): {{ next }} - {% ifequal next "/accounts/test1/" %}true{% endifequal %} If I go to http://localhost:8000/accounts/test1/, I am redirected to http://localhost:8000/accounts/login/?next=/accounts/test1/ that shows: /accounts/test1/ - true otherwise if I go to http://localhost:8000/accounts/test2/ I see: /accounts/test2/ - Maybe yours is just a typo. Paolo P.S. I am using the trunk --~--~-~--~~~---~--~~ 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: Trying to get ifequal to evaluate to True
On Jun 30, 8:05 pm, "Paolo Ambrosio" <[EMAIL PROTECTED]> wrote: > On Mon, Jun 30, 2008 at 4:52 PM, Ayaz Ahmed Khan > > <[EMAIL PROTECTED]> wrote: > > [...] The variable "next" > > does have that particular value (I verified both by printing it out > > and by making sure {% if next %} evaluates to True). However, the > > "ifequal" expression just doesn't work. > > Are you passing it through the context while invoking the template? I, myself, am not passing that particular value. I am calling the built-in login view provided by Django -- which is ``from django.contrib.auth.views import login''. That view passes the "next" as part of the context while rendering the login template. -- Ayaz Ahmed Khan --~--~-~--~~~---~--~~ 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: Trying to get ifequal to evaluate to True
On Mon, Jun 30, 2008 at 4:52 PM, Ayaz Ahmed Khan <[EMAIL PROTECTED]> wrote: > [...] The variable "next" > does have that particular value (I verified both by printing it out > and by making sure {% if next %} evaluates to True). However, the > "ifequal" expression just doesn't work. Are you passing it through the context while invoking the template? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Trying to get ifequal to evaluate to True
If a view is decorated with the `login_required decorator', an anonymous user accessing that view is directed to the login page with the URL the view exists on preserved in the "next" variable which is passed to the login view and template. In the login template, I am trying to match the value of the "next" variable with a hard-coded string. However, no matter what I do, I cannot seem to be able to get {% ifequal next "value" %} to evaluate to True. The variable "next" does have that particular value (I verified both by printing it out and by making sure {% if next %} evaluates to True). However, the "ifequal" expression just doesn't work. I have no idea why not. Any clues will be much appreciated. Thanks -- Ayaz Ahmed Khan --~--~-~--~~~---~--~~ 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: ifequal tag in template with hard coded string confusion
Thank you very much Karen - You clearly defined that problem for me and that fixed the issue. For others who might run into the same problem, they would do well to remember to add either __str__ or __uinicode__ as the case warrant:s: {% ifequal foo.bar__str__ "foobar" %} or {% ifequal foo.bar__unicode__ "foobar" %} Thanks again Karen -- For anyone else who might be confused by this. On Jun 10, 7:08 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Tue, Jun 10, 2008 at 5:33 PM, John Teague <[EMAIL PROTECTED]> wrote: > > > First the particulars: > > Django svn rev 7610, > > Apache 2.2.8, > > mod_python 3.3.1, > > Python/2.5.2 > > > I have a template that uses django_template_utils (http:// > > code.google.com/p/django-template-utils/) to retrieve objects. The > > following is the relevant markup/code: > > -- > > {% load generic_content %} > > {% get_latest_objects dispatcher.dispatchlog 100 as log_item %} > > {% for log_item in log_item %} > > > > {% ifequal log_item.id 1 %}{{ log_item.id }}{% > > endifequal %} > > {% ifequal log_item.priority_level 'High' %} > class="urg3">{{ log_item.priority_level }}{% endifequal %} > > > > {% endfor %} > > -- > > > As you can see, what I want to do is to set the appropriate extra div > > and class based on the comparison of the hard-coded string. In the > > first use of the ifequal on the 'id' field. I get the expected result. > > The integer 1 matches the returned value and renders the the extra > > div. > > > However, in the second example 'priority_level' field, the returned > > value is 'High' which should match the comparison to the hard-coded > > string 'High'. I have verified that this is a match. However, the > > ifequal fails silently. As near as I can tell, the only difference > > between the two fields is that the priority_value field is a > > foreignkey. Obviously, the value of the foreign key is, in this case, > > a pk integer, but the name is returned in what should be just a string > > __str__. > > > Am I missing something simple here? Any help would be very much > > appreciated. > > (You mean priority_level is a ForeignKey, right, not priority_value?) The > variable resolution done by ifequal isn't automatically going to call str() > on the variable, so if you want to compare what the __str__ method returns > against a string, then you need to include that in the comparison: > > {% ifequal log_item.priority_level.__str__ 'High' %} > > Karen --~--~-~--~~~---~--~~ 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: ifequal tag in template with hard coded string confusion
On Tue, Jun 10, 2008 at 5:33 PM, John Teague <[EMAIL PROTECTED]> wrote: > > First the particulars: > Django svn rev 7610, > Apache 2.2.8, > mod_python 3.3.1, > Python/2.5.2 > > I have a template that uses django_template_utils (http:// > code.google.com/p/django-template-utils/) to retrieve objects. The > following is the relevant markup/code: > -- > {% load generic_content %} > {% get_latest_objects dispatcher.dispatchlog 100 as log_item %} > {% for log_item in log_item %} > > {% ifequal log_item.id 1 %}{{ log_item.id }}{% > endifequal %} > {% ifequal log_item.priority_level 'High' %} class="urg3">{{ log_item.priority_level }}{% endifequal %} > > {% endfor %} > -- > > As you can see, what I want to do is to set the appropriate extra div > and class based on the comparison of the hard-coded string. In the > first use of the ifequal on the 'id' field. I get the expected result. > The integer 1 matches the returned value and renders the the extra > div. > > However, in the second example 'priority_level' field, the returned > value is 'High' which should match the comparison to the hard-coded > string 'High'. I have verified that this is a match. However, the > ifequal fails silently. As near as I can tell, the only difference > between the two fields is that the priority_value field is a > foreignkey. Obviously, the value of the foreign key is, in this case, > a pk integer, but the name is returned in what should be just a string > __str__. > > Am I missing something simple here? Any help would be very much > appreciated. > (You mean priority_level is a ForeignKey, right, not priority_value?) The variable resolution done by ifequal isn't automatically going to call str() on the variable, so if you want to compare what the __str__ method returns against a string, then you need to include that in the comparison: {% ifequal log_item.priority_level.__str__ 'High' %} Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ifequal tag in template with hard coded string confusion
First the particulars: Django svn rev 7610, Apache 2.2.8, mod_python 3.3.1, Python/2.5.2 I have a template that uses django_template_utils (http:// code.google.com/p/django-template-utils/) to retrieve objects. The following is the relevant markup/code: -- {% load generic_content %} {% get_latest_objects dispatcher.dispatchlog 100 as log_item %} {% for log_item in log_item %} {% ifequal log_item.id 1 %}{{ log_item.id }}{% endifequal %} {% ifequal log_item.priority_level 'High' %}{{ log_item.priority_level }}{% endifequal %} {% endfor %} -- As you can see, what I want to do is to set the appropriate extra div and class based on the comparison of the hard-coded string. In the first use of the ifequal on the 'id' field. I get the expected result. The integer 1 matches the returned value and renders the the extra div. However, in the second example 'priority_level' field, the returned value is 'High' which should match the comparison to the hard-coded string 'High'. I have verified that this is a match. However, the ifequal fails silently. As near as I can tell, the only difference between the two fields is that the priority_value field is a foreignkey. Obviously, the value of the foreign key is, in this case, a pk integer, but the name is returned in what should be just a string __str__. Am I missing something simple here? Any help would be very much appreciated. Regards, John --~--~-~--~~~---~--~~ 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: Using {% ifequal %} in my template is not working
Thanks Ivan, I've got it working however I did something different. I just put str() around my query and it works. So instead of request.session['info'].update(shape=ProductShape.objects.get(id=request['shape'])) I used: request.session['info'].update(shape=str(ProductShape.objects.get(id=request['shape']))) On Nov 10, 4:36 am, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > Greg wrote: > > request.session['info'].update(shape=ProductShape.objects.get(id=request['shape'])) > > return render_to_response('search.htm', {'pinfo': > > request.session['info']} > > This might be because of your first line here doesn't work as expected. > Session is not exactly a dict and one of the things where it differs is > that when you put a mutable object (a list, a dict etc.) into it you > can't change it in place. Instead you should reassign the whole object: > > d = request.session['info'] > d.update(shape=...) > request.session['info'] = 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: Using {% ifequal %} in my template is not working
Greg wrote: > request.session['info'].update(shape=ProductShape.objects.get(id=request['shape'])) > return render_to_response('search.htm', {'pinfo': > request.session['info']} This might be because of your first line here doesn't work as expected. Session is not exactly a dict and one of the things where it differs is that when you put a mutable object (a list, a dict etc.) into it you can't change it in place. Instead you should reassign the whole object: d = request.session['info'] d.update(shape=...) request.session['info'] = 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 -~--~~~~--~~--~--~---
Using {% ifequal %} in my template is not working
Hello, I'm not sure what is going on here. In my template I have the following code: {% ifequal pinfo.shape "Round" %}Its Round{% else %}{{ pinfo.shape }} {% endifequal %} Everytime I run this code it goes directly to the else statement and {{ pinfo.material }} prints out Round. I'm not sure why it goes to the else statement everytime if {{ pinfo.shape }} is Round. My code in my view is as follows: request.session['info'].update(shape=ProductShape.objects.get(id=request['shape'])) return render_to_response('search.htm', {'pinfo': request.session['info']} --~--~-~--~~~---~--~~ 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: Possible ifequal and/or ifnotequal bug
I figured it was something like that. I've also wondered why there wasn't a way to add a variable in the templates. In the end I settled for the CSS fix which was also something I'd never considered before. It works like a charm and I've learned something new. Thanks RajeshD! On Oct 12, 7:04 am, RajeshD <[EMAIL PROTECTED]> wrote: > > The above code is NOT catching the first instance of an NAICS > > description which begins with "A". > > The filter on the first parameter there won't work (as you've already > discovered.) > > 1. If you are using Django SVN trunk, try assigning that filtered > value first to a variable using the 'with' > templatetag:http://www.djangoproject.com/documentation/templates/#with > > 2. Another, probably simpler, solution is to use CSS to hide that > first "Back to the top" link like this: > > Back to the top > > Then, in your CSS add: > > a.letter-A {display:none;} --~--~-~--~~~---~--~~ 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: Possible ifequal and/or ifnotequal bug
> > The above code is NOT catching the first instance of an NAICS > description which begins with "A". The filter on the first parameter there won't work (as you've already discovered.) 1. If you are using Django SVN trunk, try assigning that filtered value first to a variable using the 'with' templatetag: http://www.djangoproject.com/documentation/templates/#with 2. Another, probably simpler, solution is to use CSS to hide that first "Back to the top" link like this: Back to the top Then, in your CSS add: a.letter-A {display:none;} --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Possible ifequal and/or ifnotequal bug
My question is whether I can compare a filtered template variable to a string as in "{% ifequal naics.description|slice:"0:1" 'A' %}" I'm looping through approximately 1800 NAICS description using the code below. I don't want to output the first "Back to the top" link so I'm trying to use the "ifequal" or "ifnotequal" tags and the slice filter. I'm not sure if I've found a bug or if I'm not understanding these tags fully. {% for naics in queryset %} {% ifchanged %} {{ naics.description|slice:"0:1" }} {% ifequal naics.description|slice:"0:1" 'A' %}{% else %}Back to the top{% endifequal %} {% endifchanged %} {{ naics.description }} {% endfor %} The above code is NOT catching the first instance of an NAICS description which begins with "A". --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
possible bug or strange behaviour of ifequal and request.POST.get()
Hi group, I would like to ask you for a feedback about this small piece of code which I make for testing this behaviour. Put the function test_ifequal() as a view into your app, mount it as a URL and see the page and then click the button. The problem I see in this code is - when I access this page via GET, then ifequal works correctly. When I access this page via POST, the ifequal behaves strange. Can anybody explain it? I got the same behaviour with 0.96 and trunk version. When I use {% debug %} I can see that both results (Context for GET or POST) are the same. Thanks for any clues, Michal # -*- coding: UTF-8 -*- from django.db import models from django.http import HttpResponse from django.template import Template, Context CHOICES = ( (0, 'Zero'), (100, 'One hundred.'), (200, 'Two hundred.'), ) class TestItem(models.Model): status = models.IntegerField(default=0, choices=CHOICES) def test_ifequal(request): template_content = ''' {% for choice in choices %} {% ifequal choice.0 item.status %} According to ifequal these values equal: {% else %} According to ifequal these values don't equal: {% endifequal %} {{ choice.0 }}, {{ item.status }} {% endfor %} {% debug %} ''' item = TestItem() status = request.POST.get('status', 100) item.status = status t = Template(template_content) c = Context({'item': item, 'choices': CHOICES}) html = t.render(c) return HttpResponse(html) --~--~-~--~~~---~--~~ 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: ifequal function not working?
John M skrev: > the ID is the primary key ID generated by django on models. > > basically, it's not the syntax im having issue with, i think the > selected_id is being passed / parsed as a string not an intenger like > ID is. > So where do you get the selected_id from? GET/POST variables are always strings. Could you try converting it to an int before you pass it to the template? Nis --~--~-~--~~~---~--~~ 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: ifequal function not working?
hi john - John M wrote: > {% ifequal selected_id recordset.id %} never seems to work. > > where selected_id = 1 > recordset has ID from 1 - 10 just a guess - are selected_id and recordset.id really the same type? {% ifequal %} will not match for example '1' == 1 best, jake --~--~-~--~~~---~--~~ 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: ifequal function not working?
Hmm... What is `recordset`? QuerySet? QuerySet doesn't have id attribute. {% for recod in recodeset %} {% ifequal record.id selected_id %} Selected! {% endifequal %} {% endfor %} --~--~-~--~~~---~--~~ 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: ifequal function not working?
the ID is the primary key ID generated by django on models. basically, it's not the syntax im having issue with, i think the selected_id is being passed / parsed as a string not an intenger like ID is. J On Sep 13, 12:45 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote: > Hmm... What is `recordset`? QuerySet? QuerySet doesn't have id > attribute. > {% for recod in recodeset %} > > {% ifequal record.id selected_id %} > Selected! > {% endifequal %} > > {% endfor %} --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ifequal function not working?
I have a view / template where im passing in a queryset and a value of what the current selected record, and am tring to setup a option pulldown to show the selected record. My problem is that I can't get the passed in selected record to match the ID of the queryset. for example: {% ifequal selected_id recordset.id %} never seems to work. where selected_id = 1 recordset has ID from 1 - 10 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---