Skip to content

Commit

Permalink
fix(django): incorrect context overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Oct 5, 2023
1 parent f94caa9 commit 497984e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions django/django.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,5 @@ func RenderTemplate(name string, ctx Context) (string, error) {
if err != nil {
return "", err
}
mergedCtx := runtimeGlobals()
CopyPongoContextRecursive(mergedCtx, ctx)
return tpl.Execute(mergedCtx)
return tpl.Execute(MergeContext(instance.Globals, runtimeGlobals(), ctx))
}
8 changes: 8 additions & 0 deletions django/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ func CopyPongoContextRecursive(dst, src pongo2.Context) {
}
}
}

func MergeContext(contexts ...Context) Context {
var ctx = make(Context)
for _, c := range contexts {
CopyPongoContextRecursive(ctx, c)
}
return ctx
}

0 comments on commit 497984e

Please sign in to comment.