mirror of
https://github.com/Rushilwiz/relish.git
synced 2025-04-09 14:30:19 -04:00
feat: finished site
This commit is contained in:
parent
2a41a3fff9
commit
e4ba632119
7
Pipfile
7
Pipfile
|
@ -4,12 +4,15 @@ verify_ssl = true
|
|||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
django = "*"
|
||||
Django = "*"
|
||||
python-dotenv = "*"
|
||||
django-phonenumber-field = "*"
|
||||
django-address = "*"
|
||||
django-crispy-forms = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.8"
|
||||
|
||||
[packages.django-phonenumber-field]
|
||||
extras = [ "phonenumbers",]
|
||||
|
|
17
Pipfile.lock
generated
17
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "008f09930a447935f2210147becbc00e5519c714f2b19b07647972de19557cc4"
|
||||
"sha256": "57c6fcc08d5613c3832161125af0b9cd702aaa552d0efd5baf912d44aa97d9ab"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -61,6 +61,14 @@
|
|||
"index": "pypi",
|
||||
"version": "==0.2.5"
|
||||
},
|
||||
"django-crispy-forms": {
|
||||
"hashes": [
|
||||
"sha256:35887b8851a931374dd697207a8f56c57a9c5cb9dbf0b9fa54314da5666cea5b",
|
||||
"sha256:bc4d2037f6de602d39c0bc452ac3029d1f5d65e88458872cc4dbc01c3a400604"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.14.0"
|
||||
},
|
||||
"django-phonenumber-field": {
|
||||
"hashes": [
|
||||
"sha256:897b902a1654b0eb21f6268498a3359e2c4eb90af9585cb8693af186ede8c5bb",
|
||||
|
@ -69,6 +77,13 @@
|
|||
"index": "pypi",
|
||||
"version": "==6.1.0"
|
||||
},
|
||||
"phonenumbers": {
|
||||
"hashes": [
|
||||
"sha256:1c8270a2e257d6c65458a42283f82d3eca7f7b9d925454a6966e2f04df75e1cf",
|
||||
"sha256:386ea186019e8f4d646e48e9da9c3e786c254cfb1bd541cc0a8d0a2ccb85d3ca"
|
||||
],
|
||||
"version": "==8.12.43"
|
||||
},
|
||||
"python-dotenv": {
|
||||
"hashes": [
|
||||
"sha256:32b2bdc1873fd3a3c346da1c6db83d0053c3c62f28f1f38516070c4c8971b1d3",
|
||||
|
|
|
@ -26,6 +26,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = os.getenv("SECRET_KEY")
|
||||
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = os.getenv("DEBUG", "False") == "True"
|
||||
|
@ -49,6 +50,8 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
'crispy_forms',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -133,3 +136,11 @@ STATIC_URL = 'static/'
|
|||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
||||
# Phone numbers
|
||||
|
||||
PHONENUMBER_DB_FORMAT = 'NATIONAL'
|
||||
PHONENUMBER_DEFAULT_REGION = 'US'
|
||||
PHONENUMBER_DEFAULT_FORMAT = 'NATIONAL'
|
|
@ -1,3 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from .models import Response
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Response)
|
|
@ -1,9 +1,15 @@
|
|||
from ast import Mod
|
||||
import imp
|
||||
from django.forms import ModelForm
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit
|
||||
from django import forms
|
||||
from .models import Response
|
||||
|
||||
class ResponseForm(ModelForm):
|
||||
class ResponseForm(forms.ModelForm):
|
||||
helper = FormHelper()
|
||||
helper.form_method = 'post'
|
||||
helper.form_action = ''
|
||||
|
||||
helper.add_input(Submit('submit', 'submit'))
|
||||
|
||||
class Meta:
|
||||
model = Response
|
||||
fields = ['name', 'email', 'phone', 'address']
|
||||
fields = ['name', 'email', 'phone', 'address']
|
||||
|
|
34
form/migrations/0001_initial.py
Normal file
34
form/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Generated by Django 4.0.2 on 2022-02-16 01:22
|
||||
|
||||
import address.models
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import phonenumber_field.modelfields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('address', '0004_alter_address_id_alter_country_id_alter_locality_id_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Response',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('email', models.EmailField(blank=True, max_length=100, null=True)),
|
||||
('phone', phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, null=True, region=None)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('address', address.models.AddressField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='address.address')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Response',
|
||||
'verbose_name_plural': 'Responses',
|
||||
'ordering': ['created_at'],
|
||||
},
|
||||
),
|
||||
]
|
|
@ -1,11 +1,14 @@
|
|||
from django.db import models
|
||||
from address.models import AddressField
|
||||
from phonenumber_field.modelfields import PhoneNumberField
|
||||
|
||||
# Create your models here.
|
||||
class Response(models.Model):
|
||||
|
||||
name = models.CharField(max_length=100)
|
||||
email = models.EmailField(max_length=100)
|
||||
text = models.TextField()
|
||||
email = models.EmailField(max_length=100, blank=True, null=True)
|
||||
phone = PhoneNumberField(blank=True, null=True)
|
||||
address = AddressField(on_delete=models.CASCADE, blank=True, null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Internet Form</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
|
|
|
@ -1,4 +1,36 @@
|
|||
{% extends 'form/base.html' %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block head %}
|
||||
{{ form.media }}
|
||||
|
||||
<style>
|
||||
|
||||
body {
|
||||
margin-top: 1rem;
|
||||
background-color: #ebe5f5;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.asteriskField {
|
||||
display: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>index.</h1>
|
||||
<div class="container w-25">
|
||||
{% if success %}
|
||||
<h1>Response submitted. Thank you for your help!</h1>
|
||||
{% else %}
|
||||
<h1>Form</h1>
|
||||
<i>all fields are optional</i>
|
||||
{% crispy form %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,6 +1,21 @@
|
|||
from django.shortcuts import render
|
||||
from .forms import ResponseForm
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
if request.method == 'GET':
|
||||
return render(request, 'form/index.html')
|
||||
success = False
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ResponseForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
success = True
|
||||
else:
|
||||
form = ResponseForm()
|
||||
|
||||
context = {
|
||||
'form': form,
|
||||
'success': success,
|
||||
}
|
||||
|
||||
return render(request, 'form/index.html', context)
|
Loading…
Reference in New Issue
Block a user