Browse Source

Added bootstrap5

Adam Day 2 years ago
parent
commit
c75b72995c
8 changed files with 64 additions and 27 deletions
  1. 1 0
      askpatrons/settings.py
  2. BIN
      requirements.txt
  3. 1 1
      vote/admin.py
  4. 7 12
      vote/forms.py
  5. 23 10
      vote/templates/vote/index.html
  6. 16 0
      vote/templates/vote/layout.html
  7. 4 3
      vote/validators.py
  8. 12 1
      vote/views.py

+ 1 - 0
askpatrons/settings.py

@@ -37,6 +37,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'django_bootstrap5',
     'import_export',
     'vote',
 ]

BIN
requirements.txt


+ 1 - 1
vote/admin.py

@@ -12,7 +12,7 @@ class ZipCodeResource(resources.ModelResource):
 class ZipCodeAdmin(ImportExportModelAdmin):
     resource_classes = [ZipCodeResource]
     search_fields = ['zip', 'primary_city']
-    list_display = ['zip', 'primary_city', 'state', 'county', 'latitude', 'longitude', 'irs_estimated_population']
+    list_display = ['state', 'zip', 'primary_city', 'county', 'latitude', 'longitude', 'irs_estimated_population']
     list_filter = ['state',]
     ordering = ['state', 'zip', 'primary_city']
 

+ 7 - 12
vote/forms.py

@@ -1,16 +1,11 @@
 from django import forms
+from .validators import zip_code_validator
+from .models import AgeRange
 
-from .models import Voter, VoterQuestion, Question, Vote
 
-
-class VoterForm(forms.ModelForm):
-    class Meta:
-        model = Voter
-        fields = ['first_name', 'last_name', 'age_range', 'zip_code']
-
-
-class VoterQuestionForm(forms.ModelForm):
-    class Meta:
-        model = VoterQuestion
-        fields = ['question', 'vote']
+class VoterRegistrationForm(forms.Form):
+    first_name = forms.CharField(max_length=100)
+    last_name = forms.CharField(max_length=100)
+    age_range = forms.ModelChoiceField(queryset=AgeRange.objects.all())
+    zip_code = forms.CharField(max_length=5)
 

+ 23 - 10
vote/templates/vote/index.html

@@ -1,10 +1,23 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <title>AskPatrons</title>
-</head>
-<body>
-<h1>AskPatrons</h1>
-</body>
-</html>
+{% extends 'vote/layout.html' %}
+{% load django_bootstrap5 %}
+
+{% block content %}
+    <div class="container">
+        <div class="row justify-content-center">
+            <div class="col-sm-12 col-md-6 col-lg-3">
+                <div class="card">
+                    <div class="card-body">
+                        <div class="text-center">
+                            <h3>Vote on this issue</h3>
+                        </div>
+                        <form method="POST" class="form">
+                            {% csrf_token %}
+                            {% bootstrap_form form %}
+                            {% bootstrap_button button_type="submit" content="Next" extra_classes="w-100" %}
+                        </form>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+{% endblock %}

+ 16 - 0
vote/templates/vote/layout.html

@@ -0,0 +1,16 @@
+<!doctype html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <title>AskPatron</title>
+    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
+  </head>
+  <body class="bg-dark">
+    <div class="text-center mb-5">
+        <h1 class="text-light">AskPatron</h1>
+    </div>
+    {% block content %}{% endblock %}
+    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
+  </body>
+</html>

+ 4 - 3
vote/validators.py

@@ -2,8 +2,9 @@ from django.core.exceptions import ValidationError
 from . models import ZipCode
 
 
-def zi_code_validator(value):
-    zip_codes = ZipCode.objects.all()
-    if value not in zip_codes:
+def zip_code_validator(value):
+    zip_code = ZipCode.objects.filter(zip=value).first()
+
+    if zip_code is None:
         raise ValidationError("Zip code is not valid")
 

+ 12 - 1
vote/views.py

@@ -1,11 +1,22 @@
 from django.shortcuts import render
+from . forms import VoterRegistrationForm
 
 
 # Create your views here.
 def index(request):
 
-    context = {
+    voter_registration_form = VoterRegistrationForm()
+
+    if request.method == 'POST':
+        voter_registration_form = VoterRegistrationForm(request.POST)
+        if voter_registration_form.is_valid():
+            print('Valid')
+            print(voter_registration_form.cleaned_data)
+        else:
+            print('Invalid')
 
+    context = {
+        'form': voter_registration_form,
     }
 
     return render(request, 'vote/index.html', context=context)