From fc19fe1f393547a0ada97b81a84bc02adc050b90 Mon Sep 17 00:00:00 2001 From: adamghill Date: Sat, 14 May 2022 16:39:55 -0400 Subject: [PATCH] Sample code to replicate issue #397. --- example/unicorn/components/issue_397.py | 24 +++++++++++++++++ .../unicorn/templates/unicorn/issue-397.html | 27 +++++++++++++++++++ example/www/urls.py | 6 +++++ 3 files changed, 57 insertions(+) create mode 100644 example/unicorn/components/issue_397.py create mode 100644 example/unicorn/templates/unicorn/issue-397.html diff --git a/example/unicorn/components/issue_397.py b/example/unicorn/components/issue_397.py new file mode 100644 index 00000000..47599ed0 --- /dev/null +++ b/example/unicorn/components/issue_397.py @@ -0,0 +1,24 @@ +from typing import Dict + +from django_unicorn.components import UnicornView + + +class Issue397View(UnicornView): + counter: int = 1 + counter2: Dict = None + + def mount(self): + self.counter2 = {"more": 8} + + def inc(self): + self.counter += 1 + self.counter2["more"] += 1 + + def updated_counter(self, value): + print(f"updated_counter: {value}") + + def updated_counter2(self, value): + print(f"updated_counter2: {value}") + + def updated(self, name, value): + print(f"updated: {name}, {value}") diff --git a/example/unicorn/templates/unicorn/issue-397.html b/example/unicorn/templates/unicorn/issue-397.html new file mode 100644 index 00000000..fbabc092 --- /dev/null +++ b/example/unicorn/templates/unicorn/issue-397.html @@ -0,0 +1,27 @@ +{% extends "www/base.html" %} +{% load unicorn %} + +{% block content %} + +
+
+ counter: {{ counter }} +
+
+ counter2.more: {{ counter2.more }} +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +{% endblock content %} \ No newline at end of file diff --git a/example/www/urls.py b/example/www/urls.py index 0f74458d..7ea243a1 100644 --- a/example/www/urls.py +++ b/example/www/urls.py @@ -1,6 +1,7 @@ from django.urls import path from example.unicorn.components.direct_view import DirectViewView +from example.unicorn.components.issue_397 import Issue397View from . import views @@ -14,5 +15,10 @@ DirectViewView.as_view(), name="direct-view", ), + path( + "issue-397", + Issue397View.as_view(), + name="issue-397", + ), path("", views.template, name="template"), ]