Skip to content

Commit ed78ca1

Browse files
committed
Biggest-yolo
Co-authored-by: Odd Stråbø <oddstr13@openshell.no>
1 parent c6dcd3e commit ed78ca1

10 files changed

Lines changed: 309 additions & 30 deletions

backendapi/forms.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
from django import forms
2+
from .models import Attendant # Import your model
3+
4+
class RegistrationForm(forms.ModelForm):
5+
class Meta:
6+
model = Attendant # Link the form to the Attendant model
7+
fields = [
8+
'first_name',
9+
'last_name',
10+
'email',
11+
'discord',
12+
'phone_number',
13+
'crew',
14+
'ticketCrewID',
15+
'profile_image'
16+
]
17+
widgets = {
18+
'first_name': forms.TextInput(attrs={"class": "form-input", "placeholder": "Ola"}),
19+
'last_name': forms.TextInput(attrs={"class": "form-input", "placeholder": "Nordmann"}),
20+
'email': forms.EmailInput(attrs={"class": "form-input", "placeholder": "example@email.com"}),
21+
'discord': forms.TextInput(attrs={"class": "form-input", "placeholder": "Discord#1234"}),
22+
'phone_number': forms.TextInput(attrs={"class": "form-input", "placeholder": "+123456789"}),
23+
'crew': forms.TextInput(attrs={"class": "form-input", "placeholder": "Enter your crew name"}),
24+
'ticketCrewID': forms.TextInput(attrs={"class": "form-input", "placeholder": "Ticket ID", "disabled": True}),
25+
}
26+
ticketCrewID = forms.CharField(required=False)
227

328

429

5-
class RegistrationForm(forms.Form):
6-
first_name = forms.CharField(label="Enter your name", max_length=100, required=True)
7-
last_name = forms.CharField(label="Last Name", max_length=100, required=True)
8-
email = forms.CharField(label="Discord", max_length=100, required=True)
9-
phone_number = forms.CharField(label="Phone", max_length=100, required=True)
10-
crew = forms.CharField(label="Crew", max_length=100, required=True)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Generated by Django 4.2.7 on 2025-02-19 18:05
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('backendapi', '0003_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='attendant',
15+
name='crew',
16+
field=models.CharField(default='Undefined crew', max_length=100),
17+
),
18+
migrations.AddField(
19+
model_name='attendant',
20+
name='discord',
21+
field=models.CharField(default=False, max_length=100),
22+
preserve_default=False,
23+
),
24+
migrations.AddField(
25+
model_name='attendant',
26+
name='profile_image',
27+
field=models.ImageField(blank=True, null=True, upload_to='profile_images/'),
28+
),
29+
migrations.AddField(
30+
model_name='attendant',
31+
name='ticketCrewID',
32+
field=models.CharField(default=False, max_length=100),
33+
preserve_default=False,
34+
),
35+
migrations.AlterField(
36+
model_name='attendant',
37+
name='email',
38+
field=models.EmailField(max_length=200),
39+
),
40+
migrations.AlterField(
41+
model_name='attendant',
42+
name='first_name',
43+
field=models.CharField(max_length=100),
44+
),
45+
migrations.AlterField(
46+
model_name='attendant',
47+
name='last_name',
48+
field=models.CharField(max_length=100),
49+
),
50+
migrations.AlterField(
51+
model_name='attendant',
52+
name='phone_number',
53+
field=models.CharField(max_length=15),
54+
),
55+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.7 on 2025-02-19 18:10
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('backendapi', '0004_attendant_crew_attendant_discord_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='attendant',
15+
name='crew',
16+
field=models.CharField(max_length=100),
17+
),
18+
migrations.AlterField(
19+
model_name='attendant',
20+
name='ticketCrewID',
21+
field=models.CharField(max_length=100, null=True),
22+
),
23+
]

backendapi/models.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
from django.contrib.auth.models import User
44

55

6-
# this is the Attendant model, im unsure if we need more data? Maby date of birth? => 18 years maby?
6+
77
class Attendant(models.Model):
8-
first_name = models.CharField(max_length=30)
9-
last_name = models.CharField(max_length=30)
10-
email = models.EmailField(max_length=100)
11-
phone_number = models.CharField(max_length=12)
8+
first_name = models.CharField(max_length=100)
9+
last_name = models.CharField(max_length=100)
10+
email = models.EmailField(max_length=200)
11+
discord = models.CharField(max_length=100)
12+
phone_number = models.CharField(max_length=15)
13+
crew = models.CharField(max_length=100)
14+
ticketCrewID = models.CharField(max_length=100, null=True)
15+
profile_image = models.ImageField(upload_to='profile_images/', blank=True, null=True)
1216

1317
def __str__(self):
1418
return f"{self.first_name} {self.last_name}"
1519

16-
1720
# Create your models here.

backendapi/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,15 @@ def base_view(request): #basic frontend registration view.
111111

112112

113113
def registration_view(request):
114-
context = {'form' : RegistrationForm()}
114+
context = {"form" : RegistrationForm(),
115+
"success" : True,
116+
}
117+
if request.method == 'POST':
118+
form = RegistrationForm(request.POST, request.FILES)
119+
if form.is_valid():
120+
form.save()
121+
context["success"] = True
122+
else:
123+
context["success"] = False
124+
115125
return render(request, "registration.html", context)

config/settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@
131131
# Static files (CSS, JavaScript, Images)
132132
# https://docs.djangoproject.com/en/5.0/howto/static-files/
133133

134-
STATIC_URL = "static/"
134+
STATIC_URL = "/static/"
135135
STATIC_ROOT = os.getenv("DJANGO_STATIC_ROOT")
136-
TAILWIND_APP_NAME = 'theme'
136+
STATICFILES_DIRS = [
137+
os.path.join(BASE_DIR, "theme"),
138+
]
137139

138140
# Default primary key field type
139141
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ django-urlconfchecks==0.11.0 # TODO: Add to CI
33
daphne==4.1.2
44
psycopg2-binary==2.9.10
55
djangorestframework==3.15.2
6+
pillow==11.1.0
67

78

theme/styles.css

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/* General body styles */
2+
body {
3+
font-family: Arial, sans-serif;
4+
background-color: #f0f0f5;
5+
margin: 0;
6+
padding: 20px;
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
height: 100vh;
11+
}
12+
13+
.container {
14+
max-width: 600px;
15+
width: 100%;
16+
padding: 20px;
17+
box-sizing: border-box;
18+
}
19+
20+
.form-container {
21+
background-color: #ffffff;
22+
padding: 20px;
23+
border-radius: 10px;
24+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
25+
width: 100%;
26+
max-width: 400px;
27+
margin: 0 auto;
28+
box-sizing: border-box;
29+
}
30+
31+
label {
32+
font-weight: bold;
33+
margin-bottom: 5px;
34+
display: block;
35+
}
36+
37+
input[type="text"],
38+
input[type="email"] {
39+
width: 100%;
40+
padding: 10px;
41+
margin-bottom: 15px;
42+
font-size: 16px;
43+
border: 1px solid #ccc;
44+
border-radius: 5px;
45+
box-sizing: border-box;
46+
}
47+
48+
.submit-btn {
49+
background-color: #007bff;
50+
color: white;
51+
padding: 12px;
52+
border: none;
53+
border-radius: 5px;
54+
font-size: 16px;
55+
cursor: pointer;
56+
width: 100%;
57+
}
58+
59+
.submit-btn:hover {
60+
background-color: #0056b3;
61+
}
62+
63+
/* Responsive Design */
64+
@media (max-width: 600px) {
65+
.form-container {
66+
padding: 15px;
67+
}
68+
69+
input[type="text"],
70+
input[type="email"] {
71+
font-size: 14px;
72+
}
73+
74+
.submit-btn {
75+
font-size: 14px;
76+
padding: 10px;
77+
}
78+
}
79+
80+
/* Toast message styles */
81+
.toast {
82+
visibility: hidden;
83+
max-width: 50px;
84+
height: 50px;
85+
margin-left: -125px;
86+
margin-bottom: 50px;
87+
background-color: #4CAF50;
88+
color: white;
89+
text-align: center;
90+
border-radius: 2px;
91+
padding: 16px;
92+
position: fixed;
93+
z-index: 1;
94+
left: 50%;
95+
bottom: 30px;
96+
font-size: 17px;
97+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
98+
}
99+
100+
.toast.show {
101+
visibility: visible;
102+
animation: fadein 0.5s, fadeout 1.5s 4s;
103+
}
104+
105+
@keyframes fadein {
106+
from {
107+
bottom: 0;
108+
opacity: 0;
109+
}
110+
111+
to {
112+
bottom: 30px;
113+
opacity: 1;
114+
}
115+
}
116+
117+
@keyframes fadeout {
118+
from {
119+
opacity: 1;
120+
}
121+
122+
to {
123+
opacity: 0;
124+
}
125+
}

theme/templates/base.html

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,57 @@
1+
{% load static %}
12
<!DOCTYPE html>
23
<html lang="en">
34
<head>
4-
<title>Django Tailwind</title>
5+
<title>Django Form</title>
56
<meta charset="UTF-8">
67
<meta name="viewport" content="width=device-width, initial-scale=1.0">
78
<meta http-equiv="X-UA-Compatible" content="ie=edge">
9+
<link rel="stylesheet" href="{% static 'styles.css' %}">
810
</head>
911

1012
<body>
11-
<div>
12-
{% block content %}
13-
{% endblock %}
13+
<div id="toast" class="toast">
14+
{% block toast %}
15+
{% endblock %}
16+
</div>
17+
<div class="container">
18+
{% block content %}
19+
{% endblock %}
1420
</div>
1521
</body>
1622
</html>
23+
<script>
24+
document.getElementById('submitBtn').addEventListener('click', function(event) {
25+
const form = document.getElementById('myForm');
26+
27+
// Prevent the form from submitting until we show the toast
28+
event.preventDefault();
29+
30+
// Create a FormData object
31+
const formData = new FormData(form);
32+
33+
// Convert the form data to a JSON object (for demonstration)
34+
const data = {};
35+
formData.forEach((value, key) => {
36+
data[key] = value;
37+
});
38+
39+
// Log the form data to the console (you can replace this with your form submission logic)
40+
// Display the toast
41+
// Submit the form (submit after showing toast)
42+
form.submit();
43+
44+
showToast();
45+
});
46+
47+
// Function to show the toast
48+
function showToast() {
49+
const toast = document.getElementById('toast');
50+
toast.classList.add('show');
51+
52+
// Hide the toast after 5 seconds
53+
setTimeout(function() {
54+
toast.classList.remove('show');
55+
}, 5000); // Toast stays visible for 5 seconds
56+
}
57+
</script>

theme/templates/registration.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{% extends "base.html" %}
22

3-
4-
{% block title %}registration{% endblock %}
3+
{% block title %}User Registration{% endblock %}
54

65
{% block content %}
7-
<div>
8-
<form>
6+
<div class="form-container">
7+
<form method="post" id="RegisterForm">
98
{% csrf_token %}
10-
11-
<!-- Render Crispy Form -->
129
{{ form.as_p }}
13-
14-
<!-- Submit Button -->
15-
<Button>
16-
Register
17-
</button>
10+
<button type="submit" class="submit-btn" id="RegisterButton">Register</button>
1811
</form>
12+
<div></div>
1913
</div>
2014
{% endblock %}
15+
16+
{% block toast %}
17+
{% if success %}
18+
Saved!
19+
{% endif %}
20+
{% endblock %}

0 commit comments

Comments
 (0)