fix #181: allow FilterExpressions in bird tags #229
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a draft PR for #181. It's a bit of a reshuffle for parameters, in particular the
Value
class, whereraw
is now expected to be aFilterExpression
(fromdjango.template.base
).This means we can now call components as such, and the Django filters are correctly parsed:
A summary of the changes:
bird
tag (anda bird:prop
tag) are parsed into key/value pairs split on=
, where the value is aFilterExpression
instanceFilterExpression
instance is passed directly to theValue
class when parsing theParams
from the nodeFilterExpression
is rendered with the context to provide the final value, and this greatly simplifies theValue.render
methoddisabled=False
disappear from theattrs
rather than appearing asdisabled="False"
—i.e. to mimic current behaviour.There is one side effect that I'm not sure whether it's a problem or not. Currently, a prop passed with an in-template value of
False
ends up with a value ofNone
inside the component, but with the above changes it will come through as it was originally withFalse
.My biggest bugbear with it is having to test the
VariableDoesNotExist
before calling the filter's resolve function, because the function itself has no way to stop it swallowing the error and returning the default empty string. I'd rather not do this, but it would mean no longer supporting unquoted raw strings. Personally I think that'd be an improvement, though…I'm only considering the PR a draft because it clearly needs your input, @joshuadavidthomas — and I'm also not sure how best to rewrite all the
test_params.py
tests that don't expectFilterExpression
instances all over the place! I've rejiggle a couple of the other tests (but locally the asset tests are also failing for seemingly unrelated reasons, so I'm not sure what will happen when they're run under CI).All thoughts appreciated! I realise this isn't a "one-line change" and therefore a trivial PR to review/approve/reject.