├── app
├── __init__.py
├── components
│ ├── __init__.py
│ └── test_component.py
├── migrations
│ ├── __init__.py
│ └── 0001_initial.py
├── admin.py
├── tests.py
├── models.py
├── apps.py
├── views.py
└── templates
│ ├── unicorn
│ └── test_component.html
│ └── main.html
├── django_unicorn_forms_test
├── __init__.py
├── asgi.py
├── wsgi.py
├── urls.py
└── settings.py
├── .gitignore
├── requirements.txt
├── README.md
└── manage.py
/app/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/components/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/django_unicorn_forms_test/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | db.sqlite3
2 | __pycache__
3 | .venv
4 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | django
2 | django-unicorn
3 | django-crispy-forms
4 |
--------------------------------------------------------------------------------
/app/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/app/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/app/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 |
4 | class Foo(models.Model):
5 | name = models.CharField(max_length=25)
6 |
--------------------------------------------------------------------------------
/app/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class AppConfig(AppConfig):
5 | default_auto_field = "django.db.models.BigAutoField"
6 | name = "app"
7 |
--------------------------------------------------------------------------------
/app/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render
2 | from django.views.generic import TemplateView
3 |
4 |
5 | class MainView(TemplateView):
6 | template_name = "main.html"
7 |
--------------------------------------------------------------------------------
/app/templates/unicorn/test_component.html:
--------------------------------------------------------------------------------
1 | {% load crispy_forms_tags %}
2 |
3 |
Crispy Form
4 | {% crispy get_form %}
5 | Normal variable
6 | {{ count }}
7 |
--------------------------------------------------------------------------------
/app/templates/main.html:
--------------------------------------------------------------------------------
1 | {% load unicorn %}
2 |
3 |
4 |
5 |
6 | Unicorn test
7 |
8 |
9 | {% unicorn "test_component" %}
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unicorn test project for forms
2 |
3 |
4 | ```bash
5 | git clone https://github.com/nerdoc/django-unicorn-forms-test.git
6 | cd django-unicorn-forms-test
7 | virtualenv .venv && . .venv/bin/activate
8 | pip install -U pip && pip install -r requirements.txt
9 | ./manage.py migrate
10 | manage.py runserver
11 | ```
12 |
--------------------------------------------------------------------------------
/django_unicorn_forms_test/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for django_unicorn_forms_test project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_unicorn_forms_test.settings")
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/django_unicorn_forms_test/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for django_unicorn_forms_test project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_unicorn_forms_test.settings")
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/app/components/test_component.py:
--------------------------------------------------------------------------------
1 | from django_unicorn.components import UnicornView
2 | from django import forms
3 | from ..models import Foo
4 |
5 |
6 | class ExampleForm(forms.Form):
7 | c = forms.CharField(max_length=23)
8 |
9 |
10 | class ExampleModelForm(forms.ModelForm):
11 | class Meta:
12 | model = Foo
13 | fields = ["name"]
14 |
15 |
16 | class TestComponentView(UnicornView):
17 | # template_name = "unicorn/test_component.html"
18 | # form = ExampleForm
19 | form_class = ExampleModelForm
20 | count = 1
21 |
22 | def get_form(self):
23 | # Instantiate the form with the component's attributes
24 | return self.form_class(self._attributes())
25 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault(
10 | "DJANGO_SETTINGS_MODULE", "django_unicorn_forms_test.settings"
11 | )
12 | try:
13 | from django.core.management import execute_from_command_line
14 | except ImportError as exc:
15 | raise ImportError(
16 | "Couldn't import Django. Are you sure it's installed and "
17 | "available on your PYTHONPATH environment variable? Did you "
18 | "forget to activate a virtual environment?"
19 | ) from exc
20 | execute_from_command_line(sys.argv)
21 |
22 |
23 | if __name__ == "__main__":
24 | main()
25 |
--------------------------------------------------------------------------------
/app/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.0.3 on 2022-03-07 09:26
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = []
11 |
12 | operations = [
13 | migrations.CreateModel(
14 | name="Foo",
15 | fields=[
16 | (
17 | "id",
18 | models.BigAutoField(
19 | auto_created=True,
20 | primary_key=True,
21 | serialize=False,
22 | verbose_name="ID",
23 | ),
24 | ),
25 | ("name", models.CharField(max_length=25)),
26 | ],
27 | ),
28 | ]
29 |
--------------------------------------------------------------------------------
/django_unicorn_forms_test/urls.py:
--------------------------------------------------------------------------------
1 | """django_unicorn_forms_test URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/4.0/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path
18 | from app.views import MainView
19 |
20 | urlpatterns = [
21 | path("admin/", admin.site.urls),
22 | path("", MainView.as_view(), name="home"),
23 | ]
24 |
--------------------------------------------------------------------------------
/django_unicorn_forms_test/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for django_unicorn_forms_test project.
3 |
4 | Generated by 'django-admin startproject' using Django 4.0.3.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/4.0/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/4.0/ref/settings/
11 | """
12 |
13 | from pathlib import Path
14 |
15 | # Build paths inside the project like this: BASE_DIR / 'subdir'.
16 | BASE_DIR = Path(__file__).resolve().parent.parent
17 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = "django-insecure-y(!=c2)3wtl&)22dfo()-y%5mw)7w-bc_m3x_xv1tm=ycvv9*&"
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = []
29 |
30 |
31 | # Application definition
32 |
33 | INSTALLED_APPS = [
34 | "django.contrib.admin",
35 | "django.contrib.auth",
36 | "django.contrib.contenttypes",
37 | "django.contrib.sessions",
38 | "django.contrib.messages",
39 | "django.contrib.staticfiles",
40 | "django_unicorn",
41 | "crispy_forms",
42 | "app",
43 | ]
44 |
45 | MIDDLEWARE = [
46 | "django.middleware.security.SecurityMiddleware",
47 | "django.contrib.sessions.middleware.SessionMiddleware",
48 | "django.middleware.common.CommonMiddleware",
49 | "django.middleware.csrf.CsrfViewMiddleware",
50 | "django.contrib.auth.middleware.AuthenticationMiddleware",
51 | "django.contrib.messages.middleware.MessageMiddleware",
52 | "django.middleware.clickjacking.XFrameOptionsMiddleware",
53 | ]
54 |
55 | ROOT_URLCONF = "django_unicorn_forms_test.urls"
56 |
57 | TEMPLATES = [
58 | {
59 | "BACKEND": "django.template.backends.django.DjangoTemplates",
60 | "DIRS": [],
61 | "APP_DIRS": True,
62 | "OPTIONS": {
63 | "context_processors": [
64 | "django.template.context_processors.debug",
65 | "django.template.context_processors.request",
66 | "django.contrib.auth.context_processors.auth",
67 | "django.contrib.messages.context_processors.messages",
68 | ],
69 | },
70 | },
71 | ]
72 |
73 | WSGI_APPLICATION = "django_unicorn_forms_test.wsgi.application"
74 |
75 |
76 | # Database
77 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases
78 |
79 | DATABASES = {
80 | "default": {
81 | "ENGINE": "django.db.backends.sqlite3",
82 | "NAME": BASE_DIR / "db.sqlite3",
83 | }
84 | }
85 |
86 |
87 | # Password validation
88 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
89 |
90 | AUTH_PASSWORD_VALIDATORS = [
91 | {
92 | "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
93 | },
94 | {
95 | "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
96 | },
97 | {
98 | "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
99 | },
100 | {
101 | "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
102 | },
103 | ]
104 |
105 |
106 | # Internationalization
107 | # https://docs.djangoproject.com/en/4.0/topics/i18n/
108 |
109 | LANGUAGE_CODE = "en-us"
110 |
111 | TIME_ZONE = "UTC"
112 |
113 | USE_I18N = True
114 |
115 | USE_TZ = True
116 |
117 |
118 | # Static files (CSS, JavaScript, Images)
119 | # https://docs.djangoproject.com/en/4.0/howto/static-files/
120 |
121 | STATIC_URL = "static/"
122 |
123 | # Default primary key field type
124 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
125 |
126 | DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
127 |
--------------------------------------------------------------------------------