Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#334 Fix amend template tag context #425

Merged
merged 2 commits into from
Apr 11, 2022

Conversation

martinmacko47
Copy link
Owner

@martinmacko47 martinmacko47 commented Apr 2, 2022

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 kontextu context.push(), ktora sa na konci importnuteho sum-template zahodila context.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 manager with 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

@martinmacko47 martinmacko47 merged commit c91e384 into master Apr 11, 2022
@martinmacko47 martinmacko47 deleted the feature/334/fix-amend-context branch April 11, 2022 18:01
viliambalaz pushed a commit that referenced this pull request Apr 12, 2022
* #334 Fix amend template tag context

* #334 Test fixed amend template tag context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants