generated from Code-Institute-Org/ci-full-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create contact app and complete contact template
- Loading branch information
Showing
20 changed files
with
275 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.contrib import admin | ||
from .models import Contact | ||
|
||
# Register your models here. | ||
@admin.register(Contact) | ||
class ContactAdmin(admin.ModelAdmin): | ||
list_display = ('ticket_id', 'full_name', 'email', 'date_submitted') | ||
search_fields = ('full_name', 'email', 'ticket_id') | ||
list_filter = ('date_submitted',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ContactConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'contact' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django import forms | ||
from .models import Contact | ||
|
||
class ContactForm(forms.ModelForm): | ||
class Meta: | ||
model = Contact | ||
fields = ['full_name', 'email', 'message'] | ||
widgets = { | ||
'message': forms.Textarea(attrs={'rows': 5, 'placeholder': 'Type your message here...'}), | ||
} | ||
labels = { | ||
'full_name': 'Full Name', | ||
'email': 'Email Address', | ||
'message': 'Your Message', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 5.1.2 on 2024-11-23 17:35 | ||
|
||
import uuid | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Contact', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('ticket_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)), | ||
('date_submitted', models.DateTimeField(auto_now_add=True)), | ||
('full_name', models.CharField(max_length=255)), | ||
('email', models.EmailField(max_length=254)), | ||
('message', models.TextField()), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import models | ||
import uuid | ||
|
||
# Create your models here. | ||
class Contact(models.Model): | ||
ticket_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) | ||
date_submitted = models.DateTimeField(auto_now_add=True) | ||
full_name = models.CharField(max_length=255) | ||
email = models.EmailField() | ||
message = models.TextField() | ||
|
||
def __str__(self): | ||
return f"Ticket {self.ticket_id} - {self.full_name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
|
||
{% block content %} | ||
<div class="container d-flex justify-content-center align-items-center min-vh-100 mt-3 mb-3"> | ||
<div class="card p-4 shadow-lg min-vw-20 max-vw-40"> | ||
<div class="card-body"> | ||
<!-- Heading --> | ||
<h2 class="card-title text-center mb-4"> | ||
Contact Us | ||
</h2> | ||
|
||
<!-- Form Description --> | ||
<p class="text-center"> | ||
Have any questions or concerns? Please fill out the form below and we will get back to you as soon as | ||
possible. | ||
</p> | ||
|
||
<!-- Contact Form --> | ||
<form method="post" action="{% url 'contact' %}" class="mt-3"> | ||
{% csrf_token %} | ||
|
||
<!-- Error Handling --> | ||
{% if form.non_field_errors %} | ||
<div class="alert alert-danger"> | ||
{% for error in form.non_field_errors %} | ||
<p>{{ error }}</p> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
|
||
<!-- Full Name Field --> | ||
<div class="mb-3"> | ||
<label for="id_full_name" class="form-label">Full Name:</label> | ||
<input type="text" name="full_name" id="id_full_name" class="form-control" | ||
placeholder="Enter your full name" value="{{ form.full_name.value|default:'' }}" required> | ||
{% if form.full_name.errors %} | ||
<div class="text-danger"> | ||
{% for error in form.full_name.errors %} | ||
<p>{{ error }}</p> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
|
||
<!-- Email Field --> | ||
<div class="mb-3"> | ||
<label for="id_email" class="form-label">Email:</label> | ||
<input type="email" name="email" id="id_email" class="form-control" placeholder="Enter your email" | ||
value="{{ form.email.value|default:'' }}" required> | ||
{% if form.email.errors %} | ||
<div class="text-danger"> | ||
{% for error in form.email.errors %} | ||
<p>{{ error }}</p> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
|
||
<!-- Message Field --> | ||
<div class="mb-3"> | ||
<label for="id_message" class="form-label">Message:</label> | ||
<textarea name="message" id="id_message" class="form-control" rows="5" | ||
placeholder="Type your message here" required>{{ form.message.value|default:'' }}</textarea> | ||
{% if form.message.errors %} | ||
<div class="text-danger"> | ||
{% for error in form.message.errors %} | ||
<p>{{ error }}</p> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
|
||
<!-- Submit Button --> | ||
<div class="d-grid gap-2"> | ||
<button type="submit" class="btn btn-custom-color w-100"> | ||
Submit | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
|
||
{% block extra_css %} | ||
<link rel="stylesheet" href="{% static 'css/contact.css' %}"> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container d-flex justify-content-center align-items-center min-vh-100 mt-3 mb-3"> | ||
<div class="card p-4 shadow-lg min-vw-20 max-vw-40"> | ||
<div class="card-body text-center"> | ||
<!-- Success Message Heading --> | ||
<h2 class="card-title mb-4"> | ||
Thank You for Reaching Out! | ||
</h2> | ||
|
||
<!-- Success Message Content --> | ||
<p class="mb-4"> | ||
Your message has been successfully submitted. Our team will review it and get back to you soon. Below is | ||
your ticket ID for reference. | ||
</p> | ||
|
||
<!-- Ticket ID Display --> | ||
<p class="display-6 font-weight-bold">{{ ticket_id }}</p> | ||
|
||
<!-- Link to Home Button --> | ||
<div class="row justify-content-center mt-5 mb-3"> | ||
<div class="col-auto"> | ||
<a href="{% url 'home' %}" class="btn btn-contact-color w-100 mt-4"> | ||
Return to Home <i class="fa-solid fa-house"></i> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
from . import views | ||
|
||
urlpatterns = [ | ||
path('', views.contact_view, name='contact'), | ||
path('success/', views.contact_success, name='contact_success'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.shortcuts import render, redirect | ||
from django.contrib import messages | ||
from .forms import ContactForm | ||
|
||
# Create your views here. | ||
def contact_view(request): | ||
if request.method == 'POST': | ||
form = ContactForm(request.POST) | ||
if form.is_valid(): | ||
contact = form.save() | ||
# Store the ticket ID in the session | ||
request.session['ticket_id'] = str(contact.ticket_id) | ||
return redirect('contact_success') | ||
else: | ||
form = ContactForm() | ||
|
||
return render(request, 'contact/contact_form.html', {'form': form}) | ||
|
||
|
||
def contact_success(request): | ||
# Retrieve and clear the ticket ID from the session | ||
ticket_id = request.session.get('ticket_id') | ||
if not ticket_id: | ||
# If there's no ticket ID in the session, redirect to the contact form | ||
return redirect('contact') | ||
|
||
# Clear the ticket ID from the session after retrieving it | ||
del request.session['ticket_id'] | ||
|
||
return render(request, 'contact/contact_success.html', {'ticket_id': ticket_id}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* Return to Home button */ | ||
.btn-contact-color { | ||
background-color: #3C0008; | ||
color: #F9F6EE; | ||
} | ||
|
||
.btn-contact-color:hover { | ||
background-color: #F9F6EE; | ||
border: 0.1rem solid #3C0008; | ||
color: #3C0008; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters