Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-27 Thread Sjoerd Job Postmus
Also: inline. On Wednesday, September 27, 2017 at 4:55:32 PM UTC+2, pandyas...@gmail.com wrote: > > 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

Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-27 Thread pandyashreyas1
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 wo

Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-22 Thread Sjoerd Job Postmus
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 retu

Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-22 Thread Adam Johnson
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 wrote: > It as actually possible, just in a very hacky way. Django has a setting > called TEMPLATE_STRING_IF_

Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-21 Thread Tom Forbes
You could perhaps emulate that with a template tag, it seems it would be best if this was kept in the template rather than in some associated Python file: @register.simple_tag(takes_context=True) def requires(context, *names): for name in names: if name not in context: rais

Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-21 Thread Tom Forbes
You could perhaps emulate something like that with a template tag, couldn't you? @register.simple_tag(takes_context=True) def requires(context, *names): for name in names: if name not in context: raise RuntimeError('{0} is not in the template context'.format(name)) And in

Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-21 Thread Zhiqiang Liu
To continue the previous comment. template can raise error give warning if required contexts are not provided or the types are not correct. You can have something not isRequired in contextTypes too but types can be check if the context is actually passed to template. On Thursday, September 21

Re: There should be a way to make Templates substitution to raise an exception on error

2017-09-21 Thread Zhiqiang Liu
This is not 100% related to the ticket, but something to think about. In ReactJS, there a concept called propTypes, which will check all props (they are similar to context in concept I think) listed with types in UI component. So maybe we can have something similar in django template system tha

There should be a way to make Templates substitution to raise an exception on error

2017-09-21 Thread Shreyas Pandya
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 ; Thanks regards Shreyas -- You receive