Skip to content

Commit

Permalink
Add example direct view.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed Dec 18, 2021
1 parent b0231e8 commit 69c96aa
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 45 deletions.
7 changes: 7 additions & 0 deletions example/unicorn/components/direct_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.utils.timezone import now

from django_unicorn.components import UnicornView


class DirectViewView(UnicornView):
name = "test"
13 changes: 13 additions & 0 deletions example/unicorn/templates/unicorn/direct-view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "www/base.html" %}
{% load unicorn %}

{% block content %}

<div unicorn:view>
<h2>Direct View</h2>

<input u:model="name" />
{{ name }}
</div>

{% endblock content %}
90 changes: 47 additions & 43 deletions example/www/templates/www/base.html
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
{% load static unicorn %}

<html>
<head>
<title>django-unicorn examples</title>
<link rel="stylesheet" href="{% static 'css/marx.min.css' %}">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<style>
#menu {
list-style: none;
}
#menu li {
display: inline;
padding: 0 10px;
border-left: solid 1px black;
}
#menu li:first-child {
border-left: none !important;
}
</style>

{% unicorn_scripts %}
</head>

<body>
<main>
{% csrf_token %}

<h1>django-unicorn</h1>

<ul id="menu">
<li><a href="{% url 'www:index' %}">Index</a></li>
<li><a href="{% url 'www:template' 'text-inputs' %}">Text inputs</a></li>
<li><a href="{% url 'www:template' 'html-inputs' %}">Other inputs</a></li>
<li><a href="{% url 'www:template' 'objects' %}">Objects</a></li>
<li><a href="{% url 'www:template' 'validation' %}">Validation</a></li>
<li><a href="{% url 'www:template' 'polling' %}">Polling</a></li>
<li><a href="{% url 'www:template' 'models' %}">Models</a></li>
<li><a href="{% url 'www:template' 'nested' %}">Nested components (table)</a></li>
<li><a href="{% url 'www:template' 'js' %}">JavaScript integration</a></li>
</ul>

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

</main>
</body>

<head>
<title>django-unicorn examples</title>
<link rel="stylesheet" href="{% static 'css/marx.min.css' %}">
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
<style>
#menu {
list-style: none;
}

#menu li {
display: inline;
padding: 0 10px;
border-left: solid 1px black;
}

#menu li:first-child {
border-left: none !important;
}
</style>

{% unicorn_scripts %}
</head>

<body>
<main>
{% csrf_token %}

<h1>django-unicorn</h1>

<ul id="menu">
<li><a href="{% url 'www:index' %}">Index</a></li>
<li><a href="{% url 'www:template' 'text-inputs' %}">Text inputs</a></li>
<li><a href="{% url 'www:template' 'html-inputs' %}">Other inputs</a></li>
<li><a href="{% url 'www:template' 'objects' %}">Objects</a></li>
<li><a href="{% url 'www:template' 'validation' %}">Validation</a></li>
<li><a href="{% url 'www:template' 'polling' %}">Polling</a></li>
<li><a href="{% url 'www:template' 'models' %}">Models</a></li>
<li><a href="{% url 'www:template' 'nested' %}">Nested components (table)</a></li>
<li><a href="{% url 'www:template' 'js' %}">JavaScript integration</a></li>
<li><a href="{% url 'www:direct-view' %}">Direct View</a></li>
</ul>

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

</main>
</body>

</html>
4 changes: 2 additions & 2 deletions example/www/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path

from example.unicorn.components.text_inputs import TextInputsView
from example.unicorn.components.direct_view import DirectViewView

from . import views

Expand All @@ -11,7 +11,7 @@
path("", views.index, name="index"),
path(
"direct-view",
TextInputsView.as_view(),
DirectViewView.as_view(),
name="direct-view",
),
path("<str:name>", views.template, name="template"),
Expand Down

0 comments on commit 69c96aa

Please sign in to comment.