#334 Fix amend template tag context #425
Merged
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.
Oprava
{% amend %}
template tagu, aby spravne pracoval s svojou context premennou_amend
.Doteraz sa
_amend
premenna do kontextu vkladala az pri prvom pouziti tagov ako{% prepend %}
a podobne, ktore si premennu_amend
v kontexte vytvorili sami. To vsak sposobovalo problem, ze ak sa{% prepend %}
nachadzalo v importnutom sub-template, tak django pri importovani sub-templatu vytvorilo novu vrstvu kontextucontext.push()
, ktora sa na konci importnuteho sum-template zahodilacontext.pop()
, cim sa stratila premenna_amend
, ktoru do kontextu vlozil{% prepend %}
.Bug bol zakerny v tom, ze sa prejavoval iba ak
{% prepend %}
bolo pouzite v sub-template, a to aj iba vtedy, ak v hlavnom template nebol predtym pouzity nejaky iny tag, ktory by premmenu_amend
do contextu uz pridal. Pretoze, ak premenna_amend
v kontexte uz pri importe sub-template bola, vytvorenie novej vrstvy kontextu ju zachovalo a tak tag{% prepend %}
v sub-template mal nadalej pristup k_amend
z hlavneho templatu, do ktoreho zapisal svoje data.Bug som fixol tak, ze premenna
_amend
sa do kontextu prida hned na zaciatku pri otvarajucom tagu{% amend %}
. Takze vsetky taky ako{% prepend %}
vo vnutri{% amend %}
budu mat premennu_amend
uz k dispozicii v kontexte, bez ohladu na to, ci sa nachadzaju v hlavnom template, alebo v sub-template.Navyse na zaciatku pri otvarajucom tagu
{% amend %}
okrem pridania_amend
do kontextu, vyrobim v kontexte novu vrstvu, ktoru na konci, za{% endamend %}
dropnem (kontext managerwith context.push
ju dropne automaticky). Takze by mali fungovat aj vnorene{% amend %}
tagy. Pri vnorenych{% amend %}
tagov kazdy{% amend %}
tag aplikuje tie prikazy, ktore su v jeho vrstve kontextu.Pls poriadne pretestuj, ci to funguje, alebo ci sa nieco nepokazilo niekde.
Edit: Pridal som dva testy, ktore na aktualnom masteri failuju a na tomto PR vyzeraju, ze uz funguju. Pls pozri ich a pretestuj:
test_amend_tag_on_imported_content
test_nested_amend_tags_with_operation_tags_before_content