From f2290077cceec2fa66f57f5904d8f6bf8e2ea42c Mon Sep 17 00:00:00 2001 From: adamghill Date: Sun, 11 Feb 2024 15:15:03 -0500 Subject: [PATCH] Add example of property having access to `self.request`. #650 --- example/unicorn/components/hello_world.py | 9 +++++++++ example/unicorn/templates/unicorn/hello-world-test.html | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/example/unicorn/components/hello_world.py b/example/unicorn/components/hello_world.py index 9c143925..ae96bfaa 100644 --- a/example/unicorn/components/hello_world.py +++ b/example/unicorn/components/hello_world.py @@ -11,3 +11,12 @@ class HelloWorldView(UnicornView): def set_name(self): self.name = "set_name method called" return "set_name called at " + now().strftime("%H:%M:%S.%f") + + @property + def user(self): + return self.request.user + + class Meta: + javascript_exclude = ( + "user", + ) diff --git a/example/unicorn/templates/unicorn/hello-world-test.html b/example/unicorn/templates/unicorn/hello-world-test.html index 722155f7..0ad6f00b 100644 --- a/example/unicorn/templates/unicorn/hello-world-test.html +++ b/example/unicorn/templates/unicorn/hello-world-test.html @@ -8,6 +8,11 @@ +
+ User: {{ user }} +
+
+ Hello, {{ name|default:'World' }}!