django-bs

Bootstrap integration for django using widget templates
git clone https://git.ce9e.org/django-bs.git

commit
fb289e5ab671e50ab2d6642aa1c1a71d740be32f
parent
256a3d1f041dce922909c8da3b52c45ae3e57819
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-04-18 18:18
add example project

Diffstat

A example/__init__.py 0
A example/forms.py 30 ++++++++++++++++++++++++++++++
A example/manage.py 9 +++++++++
A example/settings.py 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A example/templates/form.html 18 ++++++++++++++++++
A example/urls.py 7 +++++++
A example/views.py 8 ++++++++

7 files changed, 143 insertions, 0 deletions


diff --git a/example/__init__.py b/example/__init__.py

diff --git a/example/forms.py b/example/forms.py

@@ -0,0 +1,30 @@
   -1     1 from django import forms
   -1     2 
   -1     3 LOREM = (
   -1     4     'Consequuntur consequatur commodi ut doloremque voluptatum quo ipsa '
   -1     5     'debitis. Nesciunt voluptatibus possimus maxime sint expedita sit quia '
   -1     6     'perferendis. Amet voluptatem sed sed molestiae. Magni totam est aut et '
   -1     7     'eaque autem omnis.'
   -1     8 )
   -1     9 CHOICES = [
   -1    10     ('apple', 'apple'),
   -1    11     ('orange', 'orange'),
   -1    12     ('banana', 'banana'),
   -1    13 ]
   -1    14 
   -1    15 
   -1    16 class ExampleForm(forms.Form):
   -1    17     char = forms.CharField(help_text=LOREM)
   -1    18     disabled = forms.CharField(disabled=True)
   -1    19     hidden = forms.CharField(widget=forms.HiddenInput)
   -1    20     text = forms.CharField(widget=forms.Textarea)
   -1    21     boolean = forms.BooleanField()
   -1    22     file = forms.FileField()
   -1    23     select = forms.ChoiceField(choices=CHOICES)
   -1    24     select_multiple = forms.MultipleChoiceField(choices=CHOICES)
   -1    25     radio = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect)
   -1    26     checkbox_multiple = forms.MultipleChoiceField(
   -1    27         choices=CHOICES, widget=forms.CheckboxSelectMultiple
   -1    28     )
   -1    29     date = forms.DateField(widget=forms.SelectDateWidget())
   -1    30     date_time = forms.SplitDateTimeField()

diff --git a/example/manage.py b/example/manage.py

@@ -0,0 +1,9 @@
   -1     1 #!/bin/env python3
   -1     2 
   -1     3 import os
   -1     4 import sys
   -1     5 
   -1     6 from django.core.management import execute_from_command_line
   -1     7 
   -1     8 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings')
   -1     9 execute_from_command_line(sys.argv)

diff --git a/example/settings.py b/example/settings.py

@@ -0,0 +1,71 @@
   -1     1 from pathlib import Path
   -1     2 
   -1     3 DATABASES = {
   -1     4     'default': {
   -1     5         'ENGINE': 'django.db.backends.sqlite3',
   -1     6         'NAME': ':memory:',
   -1     7     }
   -1     8 }
   -1     9 
   -1    10 CACHES = {
   -1    11     'default': {
   -1    12         'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
   -1    13     }
   -1    14 }
   -1    15 
   -1    16 MIDDLEWARE = [
   -1    17     'django.middleware.common.CommonMiddleware',
   -1    18     'django.contrib.sessions.middleware.SessionMiddleware',
   -1    19     'django.contrib.auth.middleware.AuthenticationMiddleware',
   -1    20     'django.contrib.messages.middleware.MessageMiddleware',
   -1    21 ]
   -1    22 
   -1    23 AUTHENTICATION_BACKENDS = [
   -1    24     'django.contrib.auth.backends.ModelBackend',
   -1    25 ]
   -1    26 
   -1    27 PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher']
   -1    28 
   -1    29 ROOT_URLCONF = 'example.urls'
   -1    30 
   -1    31 INSTALLED_APPS = [
   -1    32     'django.contrib.auth',
   -1    33     'django.contrib.contenttypes',
   -1    34     'django.contrib.sessions',
   -1    35     'django.contrib.messages',
   -1    36     'django.contrib.admin',
   -1    37     'django_bs',
   -1    38     'django.forms',
   -1    39 ]
   -1    40 
   -1    41 TEMPLATES = [
   -1    42     {
   -1    43         'BACKEND': 'django.template.backends.django.DjangoTemplates',
   -1    44         'DIRS': [Path(__file__).parent / 'templates'],
   -1    45         'APP_DIRS': True,
   -1    46         'OPTIONS': {
   -1    47             'context_processors': [
   -1    48                 'django.template.context_processors.debug',
   -1    49                 'django.template.context_processors.request',
   -1    50                 'django.contrib.auth.context_processors.auth',
   -1    51                 'django.contrib.messages.context_processors.messages',
   -1    52             ]
   -1    53         },
   -1    54     }
   -1    55 ]
   -1    56 
   -1    57 FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
   -1    58 
   -1    59 SECRET_KEY = 'too-secret-for-test'
   -1    60 SITE_ID = 1
   -1    61 
   -1    62 USE_I18N = False
   -1    63 USE_L10N = False
   -1    64 USE_TZ = False
   -1    65 
   -1    66 LOGIN_URL = '/login/'
   -1    67 LOGIN_REDIRECT_URL = '/'
   -1    68 
   -1    69 DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
   -1    70 
   -1    71 DEBUG = True

diff --git a/example/templates/form.html b/example/templates/form.html

@@ -0,0 +1,18 @@
   -1     1 {% load bootstrap %}
   -1     2 <!DOCTYPE html>
   -1     3 <html lang="en">
   -1     4 <head>
   -1     5     <meta charset="utf-8" />
   -1     6     <meta name="viewport" content="width=device-width" />
   -1     7     <title>django-bs example</title>
   -1     8     <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
   -1     9 </head>
   -1    10 <body>
   -1    11     <div class="container my-4">
   -1    12         <form>
   -1    13             {% bootstrap_form form %}
   -1    14             <button class="btn btn-primary">Submit</button>
   -1    15         </form>
   -1    16     </div>
   -1    17 </body>
   -1    18 </html>

diff --git a/example/urls.py b/example/urls.py

@@ -0,0 +1,7 @@
   -1     1 from django.urls import path
   -1     2 
   -1     3 from .views import ExampleFormView
   -1     4 
   -1     5 urlpatterns = [
   -1     6     path('', ExampleFormView.as_view()),
   -1     7 ]

diff --git a/example/views.py b/example/views.py

@@ -0,0 +1,8 @@
   -1     1 from django.views.generic import FormView
   -1     2 
   -1     3 from .forms import ExampleForm
   -1     4 
   -1     5 
   -1     6 class ExampleFormView(FormView):
   -1     7     form_class = ExampleForm
   -1     8     template_name = 'form.html'