Adding request context to scribble context#115
Adding request context to scribble context#115blablacio wants to merge 1 commit intocaktus:masterfrom
Conversation
|
If I'm understanding this correctly, I can see how this would be useful but it makes the preview impossible since the preview view won't have the additional context provided by the original view. |
|
@mlavin How's the preview broken for you? All tests pass for me, and I haven't found any problems during my limited testing. |
|
I read this as you wanted to include all of the outer context from the original template into the scribble context. If that's the case, the preview view won't have that additional context. There won't be any breaking tests since we don't assert anywhere that this context isn't available and Django's template language will just render empty strings for the missing variables. If that isn't want you are proposing here then please clarify. |
There was a problem hiding this comment.
This is modifying a mutable default argument. This has the potential to leak state between pages/requests/templates.
There was a problem hiding this comment.
Potential alternative:
def build_scribble_context(scribble, extra_context=None):
"Create context for rendering a scribble or scribble preview."
context = {
'scribble': scribble,
}
if extra_context:
context.update(extra_context)
return context|
@benred42 Yeah, already fixed that, but still tackling the addition of context to the preview. Will push an update later today probably. |
d188c5f to
90e44c1
Compare
|
@mlavin @blablacio What is status of this PR? The fact, that Can I help somehow with this? |
Adding request context to scribble context. Useful for case like this:
{% load scribbler_tags %} {% scribble 'login' %} <form method="post"> {% csrf_token %} <div class="form-group"> {% for field in form %} {% if field.errors %} <div class="alert alert-danger">{{ field.errors|first }}</div> {% endif %} {% endfor %} {% for error in form.non_field_errors %} <div class="alert alert-danger">{{ error }}</div> {% endfor %} </div> <div class="form-group"> <input type="text" class="form-control" placeholder="Username" name="username"> </div> <button type="submit" class="btn btn-primary center-block">Login</button> </form>When the form is submitted and there are form errors, they're not rendered as the request context is not passed to the scribble template. Not sure what side effects this might have.