Skip to content
Snippets Groups Projects
Commit 0d670ddb authored by Julian's avatar Julian
Browse files

Create example project

parent 3995c39e
No related branches found
No related tags found
No related merge requests found
Please install `django` and `django-yarnpkg`
\ No newline at end of file
from django import forms
from django_splitted_input import SplittedInput
class SplittedInputForm(forms.Form):
splitted_input_1 = forms.CharField(label='3 3-wide text inputs', widget=SplittedInput(sizes=(3, 3, 3)))
splitted_input_2 = forms.CharField(label='4 different sized password inputs',
widget=SplittedInput(sizes=(1, 2, 3, 4), input_widget=forms.PasswordInput))
"""
Django settings for example project.
Generated by 'django-admin startproject' using Django 3.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'do-not-use-in-production!'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.staticfiles',
'django_splitted_input',
'django_yarnpkg',
'example'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'example.urls'
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"django_yarnpkg.finders.NodeModulesFinder",
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
],
},
},
]
WSGI_APPLICATION = 'example.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
YARN_INSTALLED_APPS = [
"jquery",
]
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Splitted Input Form</title>
<script type="text/javascript" src="{% static "jquery/dist/jquery.min.js" %}"></script>
<script>
window.clear_splitted_inputs = {% firstof clear "true" %};
</script>
{{ splitted_form.media }}
<style>
body {
width: 80%;
position: absolute;
left: 10%;
font-family: Roboto, sans-serif;
}
th {
text-align: left;
}
</style>
</head>
<body>
<h1>Splitted Text Inputs</h1>
<h2>Forms</h2>
<form method="post">
{% csrf_token %}
<table>
{{ splitted_form.as_table }}
</table>
<input type="submit" value="Submit"/>
</form>
{% if request.POST %}
<h2>Result:</h2>
<table>
<tr>
<th>POST key</th>
<th>POST value</th>
</tr>
{% for key, value in request.POST.items %}
<tr>
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
<tr>
<th>form.cleaned_data key</th>
<th>form.cleaned_data value</th>
</tr>
{% for key, value in splitted_form.cleaned_data.items %}
<tr>
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</body>
</html>
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.form)
]
from django.shortcuts import render
from .forms import SplittedInputForm
def form(request):
if request.method == 'POST':
context = {
"splitted_form": SplittedInputForm(request.POST),
"clear": True,
}
else:
context = {
"splitted_form": SplittedInputForm(),
}
return render(request, 'form.html', context)
"""
WSGI config for example project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
application = get_wsgi_application()
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
{
"dependencies": {
"jquery": "^3.5.1"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
jquery@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.5.1.tgz#d7b4d08e1bfdb86ad2f1a3d039ea17304717abb5"
integrity sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment