Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions example/unicorn/components/child.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from datetime import datetime
from django_unicorn.components import UnicornView

class ChildView(UnicornView):
def foo(self):
print("child clicked, calling parent's foo()")
self.parent.foo()
11 changes: 11 additions & 0 deletions example/unicorn/components/parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from datetime import datetime
from django.utils import timezone
from django_unicorn.components import UnicornView

class ParentView(UnicornView):
def mount(self):
print("parent mount: request=", self.request)


def foo(self):
print("parent click: request=", self.request)
5 changes: 5 additions & 0 deletions example/unicorn/templates/unicorn/child.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<div style="width:100px;height:100px;margin:10px;background-color:#ffaaaa" unicorn:click="foo()">
Child
</div>
</div>
10 changes: 10 additions & 0 deletions example/unicorn/templates/unicorn/parent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load unicorn %}
<div>
<div style="width:200px;height:200px;margin:10px;background-color:#aaffaa" unicorn:click="foo()">
Parent
</div>

<hr>

{% unicorn "child" dt=foobar parent=view %}
</div>
3 changes: 2 additions & 1 deletion example/www/templates/www/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ <h1>django-unicorn</h1>
<li><a href="{% url 'www:template' 'js' %}">JavaScript integration</a></li>
<li><a href="{% url 'www:direct-view' %}">Direct View</a></li>
<li><a href="{% url 'www:redirects' %}">Redirects</a></li>
<li><a href="{% url 'www:template' 'parent' %}">Test Parent/Child</a></li>
</ul>

{% block content %}{% endblock content %}

</main>
</body>

</html>
</html>
12 changes: 12 additions & 0 deletions example/www/templates/www/parent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "www/base.html" %}
{% load static unicorn %}

{% block content %}

<h2>Parent/Child</h2>

This is the "parent" component, which in turn loads the "child" component. Click each.

{% unicorn 'parent' %}

{% endblock content %}