├── crispy-forms-1 ├── .gitignore ├── core │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── templates │ │ ├── base.html │ │ └── index.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── crispy_forms_project │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py ├── crispy-forms-2 ├── .gitignore ├── core │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ ├── models.py │ ├── templates │ │ ├── base.html │ │ ├── index.html │ │ └── profile.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── crispy_forms_project │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py ├── crispy-forms-3 ├── .gitignore ├── core │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ ├── models.py │ ├── templates │ │ ├── base.html │ │ ├── index.html │ │ ├── partials │ │ │ └── field.html │ │ └── profile.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── crispy_forms_project │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py └── starter-code ├── .gitignore ├── core ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ └── __init__.py ├── models.py ├── templates │ ├── base.html │ └── index.html ├── tests.py ├── urls.py └── views.py ├── crispy_forms_project ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py └── manage.py /crispy-forms-1/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | db.sqlite3 4 | notes*.txt -------------------------------------------------------------------------------- /crispy-forms-1/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-1/core/__init__.py -------------------------------------------------------------------------------- /crispy-forms-1/core/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /crispy-forms-1/core/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CoreConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core' 7 | -------------------------------------------------------------------------------- /crispy-forms-1/core/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from datetime import datetime 3 | from django.urls import reverse_lazy 4 | from crispy_forms.helper import FormHelper 5 | from crispy_forms.layout import Submit 6 | 7 | class UniversityForm(forms.Form): 8 | 9 | def __init__(self, *args, **kwargs): 10 | super().__init__(*args, **kwargs) 11 | self.helper = FormHelper(self) 12 | self.helper.form_action = reverse_lazy('index') 13 | self.helper.form_method = 'GET' 14 | self.helper.add_input(Submit('submit', 'Submit')) 15 | 16 | SUBJECT_CHOICES = ( 17 | (1, 'Web Development'), 18 | (2, 'Systems Programming'), 19 | (3, 'Data Science'), 20 | ) 21 | 22 | name = forms.CharField(widget=forms.TextInput(attrs={ 23 | 'hx-get': reverse_lazy('index'), 24 | 'hx-trigger': 'keyup' 25 | })) 26 | age = forms.IntegerField() 27 | subject = forms.ChoiceField( 28 | choices=SUBJECT_CHOICES, 29 | widget=forms.RadioSelect() 30 | ) 31 | date_of_birth = forms.DateField(widget=forms.DateInput(attrs={'type': 'date', 'max': datetime.now().date()})) 32 | -------------------------------------------------------------------------------- /crispy-forms-1/core/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-1/core/migrations/__init__.py -------------------------------------------------------------------------------- /crispy-forms-1/core/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /crispy-forms-1/core/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Django Primers 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | {% block content %} 22 | {% endblock %} 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /crispy-forms-1/core/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | {% load crispy_forms_tags %} 3 | 4 | {% block content %} 5 | 6 | {% crispy form %} 7 | 8 | {% endblock %} -------------------------------------------------------------------------------- /crispy-forms-1/core/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /crispy-forms-1/core/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.index, name='index'), 6 | ] 7 | -------------------------------------------------------------------------------- /crispy-forms-1/core/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | from core.forms import UniversityForm 4 | 5 | # Create your views here. 6 | def index(request): 7 | context = {'form': UniversityForm()} 8 | return render(request, 'index.html', context) -------------------------------------------------------------------------------- /crispy-forms-1/crispy_forms_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-1/crispy_forms_project/__init__.py -------------------------------------------------------------------------------- /crispy-forms-1/crispy_forms_project/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /crispy-forms-1/crispy_forms_project/settings.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 4 | BASE_DIR = Path(__file__).resolve().parent.parent 5 | 6 | 7 | # Quick-start development settings - unsuitable for production 8 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 9 | 10 | # SECURITY WARNING: keep the secret key used in production secret! 11 | SECRET_KEY = 'django-insecure-%hjisw!0c0)bs&s9m#0e(#(=g54-#f+q2-d3+p%puk)0=5qrp#' 12 | 13 | # SECURITY WARNING: don't run with debug turned on in production! 14 | DEBUG = True 15 | 16 | ALLOWED_HOSTS = [] 17 | 18 | 19 | # Application definition 20 | 21 | INSTALLED_APPS = [ 22 | 'django.contrib.admin', 23 | 'django.contrib.auth', 24 | 'django.contrib.contenttypes', 25 | 'django.contrib.sessions', 26 | 'django.contrib.messages', 27 | 'django.contrib.staticfiles', 28 | 'django_extensions', 29 | 'crispy_forms', 30 | 'core' 31 | ] 32 | 33 | MIDDLEWARE = [ 34 | 'django.middleware.security.SecurityMiddleware', 35 | 'django.contrib.sessions.middleware.SessionMiddleware', 36 | 'django.middleware.common.CommonMiddleware', 37 | 'django.middleware.csrf.CsrfViewMiddleware', 38 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 39 | 'django.contrib.messages.middleware.MessageMiddleware', 40 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 41 | ] 42 | 43 | ROOT_URLCONF = 'crispy_forms_project.urls' 44 | 45 | TEMPLATES = [ 46 | { 47 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 48 | 'DIRS': [], 49 | 'APP_DIRS': True, 50 | 'OPTIONS': { 51 | 'context_processors': [ 52 | 'django.template.context_processors.debug', 53 | 'django.template.context_processors.request', 54 | 'django.contrib.auth.context_processors.auth', 55 | 'django.contrib.messages.context_processors.messages', 56 | ], 57 | }, 58 | }, 59 | ] 60 | 61 | WSGI_APPLICATION = 'crispy_forms_project.wsgi.application' 62 | 63 | 64 | # Database 65 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 66 | 67 | DATABASES = { 68 | 'default': { 69 | 'ENGINE': 'django.db.backends.sqlite3', 70 | 'NAME': BASE_DIR / 'db.sqlite3', 71 | } 72 | } 73 | 74 | 75 | # Password validation 76 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 77 | 78 | AUTH_PASSWORD_VALIDATORS = [ 79 | { 80 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 81 | }, 82 | { 83 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 84 | }, 85 | { 86 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 87 | }, 88 | { 89 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 90 | }, 91 | ] 92 | 93 | 94 | # Internationalization 95 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 96 | 97 | LANGUAGE_CODE = 'en-us' 98 | 99 | TIME_ZONE = 'UTC' 100 | 101 | USE_I18N = True 102 | 103 | USE_TZ = True 104 | 105 | 106 | # Static files (CSS, JavaScript, Images) 107 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 108 | 109 | STATIC_URL = 'static/' 110 | 111 | # Default primary key field type 112 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 113 | 114 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 115 | 116 | CRISPY_TEMPLATE_PACK = 'bootstrap4' -------------------------------------------------------------------------------- /crispy-forms-1/crispy_forms_project/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import include, path 3 | 4 | urlpatterns = [ 5 | path('admin/', admin.site.urls), 6 | path('', include('core.urls')) 7 | ] 8 | -------------------------------------------------------------------------------- /crispy-forms-1/crispy_forms_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /crispy-forms-1/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('DJANGO_SETTINGS_MODULE', 'crispy_forms_project.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /crispy-forms-2/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | db.sqlite3 4 | notes*.txt -------------------------------------------------------------------------------- /crispy-forms-2/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-2/core/__init__.py -------------------------------------------------------------------------------- /crispy-forms-2/core/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /crispy-forms-2/core/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CoreConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core' 7 | -------------------------------------------------------------------------------- /crispy-forms-2/core/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from datetime import datetime 3 | from django.urls import reverse_lazy 4 | from crispy_forms.helper import FormHelper 5 | from crispy_forms.layout import Submit 6 | 7 | from .models import User 8 | 9 | 10 | class UniversityForm(forms.ModelForm): 11 | 12 | def __init__(self, *args, **kwargs): 13 | super().__init__(*args, **kwargs) 14 | self.helper = FormHelper(self) 15 | # self.helper.form_action = reverse_lazy('index') 16 | # self.helper.form_method = 'POST' 17 | self.helper.form_id = 'university-form' 18 | self.helper.attrs = { 19 | 'hx-post': reverse_lazy('index'), 20 | 'hx-target': '#university-form', 21 | 'hx-swap': 'outerHTML' 22 | } 23 | self.helper.add_input(Submit('submit', 'Submit')) 24 | 25 | subject = forms.ChoiceField( 26 | choices=User.Subjects.choices 27 | ) 28 | date_of_birth = forms.DateField(widget=forms.DateInput(attrs={'type': 'date', 'max': datetime.now().date()})) 29 | 30 | class Meta: 31 | model = User 32 | fields = ('username', 'password', 'date_of_birth', 'subject') 33 | widgets = { 34 | 'password': forms.PasswordInput() 35 | } 36 | 37 | def clean_username(self): 38 | username = self.cleaned_data['username'] 39 | if len(username) <= 3: 40 | raise forms.ValidationError("Username is too short") 41 | return username 42 | 43 | def save(self, commit=True): 44 | """ Hash user's password on save """ 45 | user = super().save(commit=False) 46 | user.set_password(self.cleaned_data['password']) 47 | if commit: 48 | user.save() 49 | return user 50 | -------------------------------------------------------------------------------- /crispy-forms-2/core/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.1 on 2022-01-21 18:25 2 | 3 | import django.contrib.auth.models 4 | import django.contrib.auth.validators 5 | from django.db import migrations, models 6 | import django.utils.timezone 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ('auth', '0012_alter_user_first_name_max_length'), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name='User', 20 | fields=[ 21 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 22 | ('password', models.CharField(max_length=128, verbose_name='password')), 23 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 24 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 25 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 26 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), 27 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 28 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 29 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 30 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 31 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 32 | ('subject', models.PositiveSmallIntegerField(choices=[(1, 'Web Development'), (2, 'Systems Programming'), (3, 'Data Science')])), 33 | ('date_of_birth', models.DateField()), 34 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), 35 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), 36 | ], 37 | options={ 38 | 'verbose_name': 'user', 39 | 'verbose_name_plural': 'users', 40 | 'abstract': False, 41 | }, 42 | managers=[ 43 | ('objects', django.contrib.auth.models.UserManager()), 44 | ], 45 | ), 46 | ] 47 | -------------------------------------------------------------------------------- /crispy-forms-2/core/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-2/core/migrations/__init__.py -------------------------------------------------------------------------------- /crispy-forms-2/core/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import AbstractUser 3 | 4 | # Create your models here. 5 | class User(AbstractUser): 6 | 7 | class Subjects(models.IntegerChoices): 8 | WEB_DEVELOPMENT = 1 9 | SYSTEMS_PROGRAMMING = 2 10 | DATA_SCIENCE = 3 11 | 12 | subject = models.PositiveSmallIntegerField(choices=Subjects.choices) 13 | date_of_birth = models.DateField() -------------------------------------------------------------------------------- /crispy-forms-2/core/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Django Primers 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | {% block content %} 22 | {% endblock %} 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /crispy-forms-2/core/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | {% load crispy_forms_tags %} 3 | 4 | {% block content %} 5 | 6 | {% crispy form %} 7 | 8 | {% endblock %} -------------------------------------------------------------------------------- /crispy-forms-2/core/templates/profile.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | {% block content %} 4 | 5 | {% if user.is_authenticated %} 6 |

{{ request.user.username }}

7 | 8 |

You are studying {{ request.user.get_subject_display }}

9 | 10 | {% csrf_token %} 11 | 12 | 13 | {% else %} 14 | 15 |

You are not allowed

16 | 17 | {% endif %} 18 | 19 | 24 | {% endblock %} -------------------------------------------------------------------------------- /crispy-forms-2/core/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /crispy-forms-2/core/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from django.contrib.auth.views import LogoutView 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path('', views.index, name='index'), 7 | path('logout', LogoutView.as_view(), name='logout') 8 | ] 9 | -------------------------------------------------------------------------------- /crispy-forms-2/core/views.py: -------------------------------------------------------------------------------- 1 | from django.http import HttpResponse 2 | from django.shortcuts import render 3 | from django.template.context_processors import csrf 4 | from crispy_forms.utils import render_crispy_form 5 | from django.contrib.auth import login 6 | 7 | from core.forms import UniversityForm 8 | 9 | # Create your views here. 10 | def index(request): 11 | if request.method == 'GET': 12 | context = {'form': UniversityForm()} 13 | return render(request, 'index.html', context) 14 | 15 | elif request.method == 'POST': 16 | form = UniversityForm(request.POST) 17 | if form.is_valid(): 18 | user = form.save() 19 | login(request, user) 20 | template = render(request, 'profile.html') 21 | template['Hx-Push'] = '/profile/' 22 | return template 23 | 24 | ctx = {} 25 | ctx.update(csrf(request)) 26 | form_html = render_crispy_form(form, context=ctx) 27 | return HttpResponse(form_html) 28 | -------------------------------------------------------------------------------- /crispy-forms-2/crispy_forms_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-2/crispy_forms_project/__init__.py -------------------------------------------------------------------------------- /crispy-forms-2/crispy_forms_project/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /crispy-forms-2/crispy_forms_project/settings.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 4 | BASE_DIR = Path(__file__).resolve().parent.parent 5 | 6 | 7 | # Quick-start development settings - unsuitable for production 8 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 9 | 10 | # SECURITY WARNING: keep the secret key used in production secret! 11 | SECRET_KEY = 'django-insecure-%hjisw!0c0)bs&s9m#0e(#(=g54-#f+q2-d3+p%puk)0=5qrp#' 12 | 13 | # SECURITY WARNING: don't run with debug turned on in production! 14 | DEBUG = True 15 | 16 | ALLOWED_HOSTS = [] 17 | 18 | 19 | # Application definition 20 | 21 | INSTALLED_APPS = [ 22 | 'django.contrib.admin', 23 | 'django.contrib.auth', 24 | 'django.contrib.contenttypes', 25 | 'django.contrib.sessions', 26 | 'django.contrib.messages', 27 | 'django.contrib.staticfiles', 28 | 'django_extensions', 29 | 'crispy_forms', 30 | 'core' 31 | ] 32 | 33 | MIDDLEWARE = [ 34 | 'django.middleware.security.SecurityMiddleware', 35 | 'django.contrib.sessions.middleware.SessionMiddleware', 36 | 'django.middleware.common.CommonMiddleware', 37 | 'django.middleware.csrf.CsrfViewMiddleware', 38 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 39 | 'django.contrib.messages.middleware.MessageMiddleware', 40 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 41 | ] 42 | 43 | ROOT_URLCONF = 'crispy_forms_project.urls' 44 | 45 | TEMPLATES = [ 46 | { 47 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 48 | 'DIRS': [], 49 | 'APP_DIRS': True, 50 | 'OPTIONS': { 51 | 'context_processors': [ 52 | 'django.template.context_processors.debug', 53 | 'django.template.context_processors.request', 54 | 'django.contrib.auth.context_processors.auth', 55 | 'django.contrib.messages.context_processors.messages', 56 | ], 57 | }, 58 | }, 59 | ] 60 | 61 | WSGI_APPLICATION = 'crispy_forms_project.wsgi.application' 62 | 63 | 64 | # Database 65 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 66 | 67 | DATABASES = { 68 | 'default': { 69 | 'ENGINE': 'django.db.backends.sqlite3', 70 | 'NAME': BASE_DIR / 'db.sqlite3', 71 | } 72 | } 73 | 74 | 75 | # Password validation 76 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 77 | 78 | AUTH_PASSWORD_VALIDATORS = [ 79 | { 80 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 81 | }, 82 | { 83 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 84 | }, 85 | { 86 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 87 | }, 88 | { 89 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 90 | }, 91 | ] 92 | 93 | 94 | # Internationalization 95 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 96 | 97 | LANGUAGE_CODE = 'en-us' 98 | 99 | TIME_ZONE = 'UTC' 100 | 101 | USE_I18N = True 102 | 103 | USE_TZ = True 104 | 105 | 106 | # Static files (CSS, JavaScript, Images) 107 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 108 | 109 | STATIC_URL = 'static/' 110 | 111 | # Default primary key field type 112 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 113 | 114 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 115 | 116 | CRISPY_TEMPLATE_PACK = 'bootstrap4' 117 | 118 | AUTH_USER_MODEL = 'core.User' 119 | 120 | LOGOUT_REDIRECT_URL = '/' -------------------------------------------------------------------------------- /crispy-forms-2/crispy_forms_project/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import include, path 3 | 4 | urlpatterns = [ 5 | path('admin/', admin.site.urls), 6 | path('', include('core.urls')) 7 | ] 8 | -------------------------------------------------------------------------------- /crispy-forms-2/crispy_forms_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /crispy-forms-2/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('DJANGO_SETTINGS_MODULE', 'crispy_forms_project.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /crispy-forms-3/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | db.sqlite3 4 | notes*.txt -------------------------------------------------------------------------------- /crispy-forms-3/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-3/core/__init__.py -------------------------------------------------------------------------------- /crispy-forms-3/core/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /crispy-forms-3/core/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CoreConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core' 7 | -------------------------------------------------------------------------------- /crispy-forms-3/core/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from datetime import datetime 3 | from django.urls import reverse_lazy 4 | from crispy_forms.helper import FormHelper 5 | from crispy_forms.layout import Submit 6 | 7 | from .models import User 8 | 9 | 10 | class UniversityForm(forms.ModelForm): 11 | 12 | def __init__(self, *args, **kwargs): 13 | super().__init__(*args, **kwargs) 14 | self.helper = FormHelper(self) 15 | # self.helper.form_action = reverse_lazy('index') 16 | # self.helper.form_method = 'POST' 17 | self.helper.form_id = 'university-form' 18 | self.helper.attrs = { 19 | 'hx-post': reverse_lazy('index'), 20 | 'hx-target': '#university-form', 21 | 'hx-swap': 'outerHTML' 22 | } 23 | self.helper.add_input(Submit('submit', 'Submit')) 24 | 25 | subject = forms.ChoiceField( 26 | choices=User.Subjects.choices, 27 | widget=forms.Select(attrs={ 28 | 'hx-get': reverse_lazy('check-subject'), 29 | 'hx-target': '#div_id_subject', 30 | 'hx-trigger': 'change' 31 | }) 32 | ) 33 | date_of_birth = forms.DateField(widget=forms.DateInput(attrs={'type': 'date', 'max': datetime.now().date()})) 34 | 35 | class Meta: 36 | model = User 37 | fields = ('username', 'password', 'date_of_birth', 'subject') 38 | widgets = { 39 | 'password': forms.PasswordInput(), 40 | 'username': forms.TextInput(attrs={ 41 | 'hx-get': reverse_lazy('check-username'), 42 | 'hx-target': '#div_id_username', 43 | 'hx-trigger': 'keyup[target.value.length > 3]' 44 | }) 45 | } 46 | 47 | def clean_username(self): 48 | username = self.cleaned_data['username'] 49 | if len(username) <= 3: 50 | raise forms.ValidationError("Username is too short") 51 | return username 52 | 53 | def clean_subject(self): 54 | subject = self.cleaned_data['subject'] 55 | if User.objects.filter(subject=subject).count() > 3: 56 | raise forms.ValidationError("There are no spaces on this course") 57 | return subject 58 | 59 | 60 | def save(self, commit=True): 61 | """ Hash user's password on save """ 62 | user = super().save(commit=False) 63 | user.set_password(self.cleaned_data['password']) 64 | if commit: 65 | user.save() 66 | return user 67 | -------------------------------------------------------------------------------- /crispy-forms-3/core/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.1 on 2022-01-21 18:25 2 | 3 | import django.contrib.auth.models 4 | import django.contrib.auth.validators 5 | from django.db import migrations, models 6 | import django.utils.timezone 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ('auth', '0012_alter_user_first_name_max_length'), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name='User', 20 | fields=[ 21 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 22 | ('password', models.CharField(max_length=128, verbose_name='password')), 23 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 24 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 25 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 26 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), 27 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 28 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 29 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 30 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 31 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 32 | ('subject', models.PositiveSmallIntegerField(choices=[(1, 'Web Development'), (2, 'Systems Programming'), (3, 'Data Science')])), 33 | ('date_of_birth', models.DateField()), 34 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), 35 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), 36 | ], 37 | options={ 38 | 'verbose_name': 'user', 39 | 'verbose_name_plural': 'users', 40 | 'abstract': False, 41 | }, 42 | managers=[ 43 | ('objects', django.contrib.auth.models.UserManager()), 44 | ], 45 | ), 46 | ] 47 | -------------------------------------------------------------------------------- /crispy-forms-3/core/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-3/core/migrations/__init__.py -------------------------------------------------------------------------------- /crispy-forms-3/core/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import AbstractUser 3 | 4 | # Create your models here. 5 | class User(AbstractUser): 6 | 7 | class Subjects(models.IntegerChoices): 8 | WEB_DEVELOPMENT = 1 9 | SYSTEMS_PROGRAMMING = 2 10 | DATA_SCIENCE = 3 11 | 12 | subject = models.PositiveSmallIntegerField(choices=Subjects.choices) 13 | date_of_birth = models.DateField() -------------------------------------------------------------------------------- /crispy-forms-3/core/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Django Primers 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | {% block content %} 22 | {% endblock %} 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /crispy-forms-3/core/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | {% load crispy_forms_tags %} 3 | 4 | {% block content %} 5 | 6 | {% crispy form %} 7 | 8 | {% endblock %} -------------------------------------------------------------------------------- /crispy-forms-3/core/templates/partials/field.html: -------------------------------------------------------------------------------- 1 | {{ field|safe }} 2 | 3 | {% if valid %} 4 | 10 | {% else %} 11 | 18 | {% endif %} -------------------------------------------------------------------------------- /crispy-forms-3/core/templates/profile.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | {% block content %} 4 | 5 | {% if user.is_authenticated %} 6 |

{{ request.user.username }}

7 | 8 |

You are studying {{ request.user.get_subject_display }}

9 | 10 | {% csrf_token %} 11 | 12 | 13 | {% else %} 14 | 15 |

You are not allowed

16 | 17 | {% endif %} 18 | 19 | 24 | {% endblock %} -------------------------------------------------------------------------------- /crispy-forms-3/core/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /crispy-forms-3/core/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from django.contrib.auth.views import LogoutView 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path('', views.index, name='index'), 7 | path('logout', LogoutView.as_view(), name='logout') 8 | ] 9 | 10 | htmx_urlpatterns = [ 11 | path('check-username', views.check_username, name='check-username'), 12 | path('check-subject', views.check_subject, name='check-subject') 13 | ] 14 | 15 | urlpatterns += htmx_urlpatterns -------------------------------------------------------------------------------- /crispy-forms-3/core/views.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth import login 2 | from django.http import HttpResponse 3 | from django.shortcuts import render 4 | from django.template.context_processors import csrf 5 | from crispy_forms.utils import render_crispy_form 6 | from crispy_forms.templatetags.crispy_forms_filters import as_crispy_field 7 | 8 | from core.forms import UniversityForm 9 | 10 | # Create your views here. 11 | def index(request): 12 | if request.method == 'GET': 13 | context = {'form': UniversityForm()} 14 | return render(request, 'index.html', context) 15 | 16 | elif request.method == 'POST': 17 | form = UniversityForm(request.POST) 18 | if form.is_valid(): 19 | user = form.save() 20 | login(request, user) 21 | template = render(request, 'profile.html') 22 | template['Hx-Push'] = '/profile/' 23 | return template 24 | 25 | ctx = {} 26 | ctx.update(csrf(request)) 27 | form_html = render_crispy_form(form, context=ctx) 28 | return HttpResponse(form_html) 29 | 30 | 31 | def check_username(request): 32 | form = UniversityForm(request.GET) 33 | context = { 34 | 'field': as_crispy_field(form['username']), 35 | 'valid': not form['username'].errors 36 | } 37 | return render(request, 'partials/field.html', context) 38 | 39 | def check_subject(request): 40 | form = UniversityForm(request.GET) 41 | context = { 42 | 'field': as_crispy_field(form['subject']), 43 | 'valid': not form['subject'].errors 44 | } 45 | return render(request, 'partials/field.html', context) -------------------------------------------------------------------------------- /crispy-forms-3/crispy_forms_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/crispy-forms-3/crispy_forms_project/__init__.py -------------------------------------------------------------------------------- /crispy-forms-3/crispy_forms_project/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /crispy-forms-3/crispy_forms_project/settings.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 4 | BASE_DIR = Path(__file__).resolve().parent.parent 5 | 6 | 7 | # Quick-start development settings - unsuitable for production 8 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 9 | 10 | # SECURITY WARNING: keep the secret key used in production secret! 11 | SECRET_KEY = 'django-insecure-%hjisw!0c0)bs&s9m#0e(#(=g54-#f+q2-d3+p%puk)0=5qrp#' 12 | 13 | # SECURITY WARNING: don't run with debug turned on in production! 14 | DEBUG = True 15 | 16 | ALLOWED_HOSTS = [] 17 | 18 | 19 | # Application definition 20 | 21 | INSTALLED_APPS = [ 22 | 'django.contrib.admin', 23 | 'django.contrib.auth', 24 | 'django.contrib.contenttypes', 25 | 'django.contrib.sessions', 26 | 'django.contrib.messages', 27 | 'django.contrib.staticfiles', 28 | 'django_extensions', 29 | 'crispy_forms', 30 | 'core' 31 | ] 32 | 33 | MIDDLEWARE = [ 34 | 'django.middleware.security.SecurityMiddleware', 35 | 'django.contrib.sessions.middleware.SessionMiddleware', 36 | 'django.middleware.common.CommonMiddleware', 37 | 'django.middleware.csrf.CsrfViewMiddleware', 38 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 39 | 'django.contrib.messages.middleware.MessageMiddleware', 40 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 41 | ] 42 | 43 | ROOT_URLCONF = 'crispy_forms_project.urls' 44 | 45 | TEMPLATES = [ 46 | { 47 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 48 | 'DIRS': [], 49 | 'APP_DIRS': True, 50 | 'OPTIONS': { 51 | 'context_processors': [ 52 | 'django.template.context_processors.debug', 53 | 'django.template.context_processors.request', 54 | 'django.contrib.auth.context_processors.auth', 55 | 'django.contrib.messages.context_processors.messages', 56 | ], 57 | }, 58 | }, 59 | ] 60 | 61 | WSGI_APPLICATION = 'crispy_forms_project.wsgi.application' 62 | 63 | 64 | # Database 65 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 66 | 67 | DATABASES = { 68 | 'default': { 69 | 'ENGINE': 'django.db.backends.sqlite3', 70 | 'NAME': BASE_DIR / 'db.sqlite3', 71 | } 72 | } 73 | 74 | 75 | # Password validation 76 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 77 | 78 | AUTH_PASSWORD_VALIDATORS = [ 79 | { 80 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 81 | }, 82 | { 83 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 84 | }, 85 | { 86 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 87 | }, 88 | { 89 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 90 | }, 91 | ] 92 | 93 | 94 | # Internationalization 95 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 96 | 97 | LANGUAGE_CODE = 'en-us' 98 | 99 | TIME_ZONE = 'UTC' 100 | 101 | USE_I18N = True 102 | 103 | USE_TZ = True 104 | 105 | 106 | # Static files (CSS, JavaScript, Images) 107 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 108 | 109 | STATIC_URL = 'static/' 110 | 111 | # Default primary key field type 112 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 113 | 114 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 115 | 116 | CRISPY_TEMPLATE_PACK = 'bootstrap4' 117 | 118 | AUTH_USER_MODEL = 'core.User' 119 | 120 | LOGOUT_REDIRECT_URL = '/' -------------------------------------------------------------------------------- /crispy-forms-3/crispy_forms_project/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import include, path 3 | 4 | urlpatterns = [ 5 | path('admin/', admin.site.urls), 6 | path('', include('core.urls')) 7 | ] 8 | -------------------------------------------------------------------------------- /crispy-forms-3/crispy_forms_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /crispy-forms-3/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('DJANGO_SETTINGS_MODULE', 'crispy_forms_project.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /starter-code/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | db.sqlite3 4 | notes*.txt -------------------------------------------------------------------------------- /starter-code/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/starter-code/core/__init__.py -------------------------------------------------------------------------------- /starter-code/core/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /starter-code/core/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CoreConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core' 7 | -------------------------------------------------------------------------------- /starter-code/core/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/starter-code/core/migrations/__init__.py -------------------------------------------------------------------------------- /starter-code/core/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /starter-code/core/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Django Primers 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | {% block content %} 22 | {% endblock %} 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /starter-code/core/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | {% block content %} 4 | Hi 5 | {% endblock %} -------------------------------------------------------------------------------- /starter-code/core/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /starter-code/core/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.index, name='index'), 6 | ] 7 | -------------------------------------------------------------------------------- /starter-code/core/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | def index(request): 5 | context = {} 6 | return render(request, 'index.html', context) -------------------------------------------------------------------------------- /starter-code/crispy_forms_project/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bugbytes-io/crispy-forms-htmx/baf603ee4e03563cfc9cfeeea30d178dc19b969f/starter-code/crispy_forms_project/__init__.py -------------------------------------------------------------------------------- /starter-code/crispy_forms_project/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /starter-code/crispy_forms_project/settings.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 4 | BASE_DIR = Path(__file__).resolve().parent.parent 5 | 6 | 7 | # Quick-start development settings - unsuitable for production 8 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 9 | 10 | # SECURITY WARNING: keep the secret key used in production secret! 11 | SECRET_KEY = 'django-insecure-%hjisw!0c0)bs&s9m#0e(#(=g54-#f+q2-d3+p%puk)0=5qrp#' 12 | 13 | # SECURITY WARNING: don't run with debug turned on in production! 14 | DEBUG = True 15 | 16 | ALLOWED_HOSTS = [] 17 | 18 | 19 | # Application definition 20 | 21 | INSTALLED_APPS = [ 22 | 'django.contrib.admin', 23 | 'django.contrib.auth', 24 | 'django.contrib.contenttypes', 25 | 'django.contrib.sessions', 26 | 'django.contrib.messages', 27 | 'django.contrib.staticfiles', 28 | 'django_extensions', 29 | 'core' 30 | ] 31 | 32 | MIDDLEWARE = [ 33 | 'django.middleware.security.SecurityMiddleware', 34 | 'django.contrib.sessions.middleware.SessionMiddleware', 35 | 'django.middleware.common.CommonMiddleware', 36 | 'django.middleware.csrf.CsrfViewMiddleware', 37 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 38 | 'django.contrib.messages.middleware.MessageMiddleware', 39 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 40 | ] 41 | 42 | ROOT_URLCONF = 'crispy_forms_project.urls' 43 | 44 | TEMPLATES = [ 45 | { 46 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 47 | 'DIRS': [], 48 | 'APP_DIRS': True, 49 | 'OPTIONS': { 50 | 'context_processors': [ 51 | 'django.template.context_processors.debug', 52 | 'django.template.context_processors.request', 53 | 'django.contrib.auth.context_processors.auth', 54 | 'django.contrib.messages.context_processors.messages', 55 | ], 56 | }, 57 | }, 58 | ] 59 | 60 | WSGI_APPLICATION = 'crispy_forms_project.wsgi.application' 61 | 62 | 63 | # Database 64 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 65 | 66 | DATABASES = { 67 | 'default': { 68 | 'ENGINE': 'django.db.backends.sqlite3', 69 | 'NAME': BASE_DIR / 'db.sqlite3', 70 | } 71 | } 72 | 73 | 74 | # Password validation 75 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 76 | 77 | AUTH_PASSWORD_VALIDATORS = [ 78 | { 79 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 80 | }, 81 | { 82 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 83 | }, 84 | { 85 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 86 | }, 87 | { 88 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 89 | }, 90 | ] 91 | 92 | 93 | # Internationalization 94 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 95 | 96 | LANGUAGE_CODE = 'en-us' 97 | 98 | TIME_ZONE = 'UTC' 99 | 100 | USE_I18N = True 101 | 102 | USE_TZ = True 103 | 104 | 105 | # Static files (CSS, JavaScript, Images) 106 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 107 | 108 | STATIC_URL = 'static/' 109 | 110 | # Default primary key field type 111 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 112 | 113 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 114 | -------------------------------------------------------------------------------- /starter-code/crispy_forms_project/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import include, path 3 | 4 | urlpatterns = [ 5 | path('admin/', admin.site.urls), 6 | path('', include('core.urls')) 7 | ] 8 | -------------------------------------------------------------------------------- /starter-code/crispy_forms_project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for crispy_forms_project 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', 'crispy_forms_project.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /starter-code/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('DJANGO_SETTINGS_MODULE', 'crispy_forms_project.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | --------------------------------------------------------------------------------