Please find comment inline

On Friday, 22 September 2017 15:44:38 UTC+5:30, Sjoerd Job Postmus wrote:
>
> Indeed it could be!
>
> What if it was not `string_if_invalid` but `if_invalid`. The value could 
> be:
>
> * An Exception instance (which would then be raised)
> * An Exception class (which would be instantiated with the "invalid" 
> thing), and then be raised
> * A callable (which would be called, and must return a string or raise), 
> and the result used (unless it raises an exception, in which case that 
> exception is propogated upwards)
> * A string (which would be interpolated with `%` if it contains "%s") to 
> be used instead.
>
This seems like an overkill. What if we instead provide an additional 
boolean flag `raise_if_invalid`

>
> (in that order).
>
> We also use the `string_if_invalid` trick with a custom class that 
> provides `__mod__`/`__contains__`. Would be great if we could handle that 
> at the Django layer.
>
> On Friday, September 22, 2017 at 11:00:00 AM UTC+2, Adam Johnson wrote:
>>
>> I've used a solution like the one Emil links to before to great success, 
>> though perhaps there's scope to make it a bit less hacky in Django.
>>
>> On 22 September 2017 at 07:10, Emil Stenström <e...@kth.se> wrote:
>>
>>> It as actually possible, just in a very hacky way. Django has a setting 
>>> called TEMPLATE_STRING_IF_INVALID (or TEMPLATES[0]["OPTIONS"]["
>>> string_if_invalid"] in current versions of Django). If you override it 
>>> and set it to a class with a __str__ that raises an exception you can get 
>>> the effect you want. We use this in tests to find missing variables quickly.
>>>
>>> Reference code: https://djangosnippets.org/snippets/646/
>>>
>>> On Thursday, 21 September 2017 13:05:28 UTC+2, Shreyas Pandya wrote:
>>>>
>>>> Hi All,
>>>>
>>>> What is your opinion on having an option to raise an error in template 
>>>> if variable is not found in context. This may be useful for automated 
>>>>  tests as discussed in ticket. 
>>>>
>>>> reference ticket #28618 <https://code.djangoproject.com/ticket/28618>
>>>>  ; 
>>>>
>>>> Thanks
>>>>
>>>> regards
>>>> Shreyas
>>>>
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django developers (Contributions to Django itself)" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-develop...@googlegroups.com.
>>> To post to this group, send email to django-d...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-developers.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-developers/02995ca2-2721-4526-89de-408bb3be642d%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-developers/02995ca2-2721-4526-89de-408bb3be642d%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> Adam
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/0a194518-856a-4c6a-a6e2-7ee15d27f84c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to