Skip to content

Commit

Permalink
context always has a template_inject dict, remove now-redundant checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurin Schmidt committed Nov 11, 2024
1 parent 9d55a87 commit 24ef62a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,7 @@ def on_success(self, context):
output = context["output"]
flash = self.local.flash or ""
if isinstance(output, dict):
if "template_inject" in context:
context["template_inject"]["flash"] = flash
else:
context["template_inject"] = dict(flash=flash)
context["template_inject"]["flash"] = flash
elif self.local.flash is not None:
response.headers.setdefault("component-flash", json.dumps(flash))

Expand Down Expand Up @@ -611,7 +608,7 @@ def on_success(self, context):
ctx = dict(request=request)
ctx.update(HELPERS)
ctx.update(URL=URL)
ctx.update(context.get("template_inject", {}))
ctx.update(context["template_inject"])
ctx.update(output)
ctx["__vars__"] = output
app_folder = os.path.join(os.environ["PY4WEB_APPS_FOLDER"], request.app_name)
Expand Down Expand Up @@ -993,6 +990,7 @@ def wrapper(*args, **kwargs):
"output": None,
"exception": None,
"processed": processed,
"template_inject": {},
}
try:
for fixture in fixtures:
Expand Down
2 changes: 1 addition & 1 deletion py4web/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def deny_action(self, action_name):

def on_success(self, context):
if self.inject:
context["template_inject"] = {"user": self.get_user()}
context["template_inject"]["user"] = self.get_user()

def define_tables(self):
"""Defines the auth_user table"""
Expand Down

0 comments on commit 24ef62a

Please sign in to comment.