diff --git a/UWEFlix/__pycache__/admin.cpython-310.pyc b/UWEFlix/__pycache__/admin.cpython-310.pyc index c52617413dc72f6f597fb572c7cc16ccee1453c4..fde77289443a35787c1ec96aa13a138cea227276 100644 Binary files a/UWEFlix/__pycache__/admin.cpython-310.pyc and b/UWEFlix/__pycache__/admin.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/forms.cpython-310.pyc b/UWEFlix/__pycache__/forms.cpython-310.pyc index 2a15a8f239f8c74ca0fb700750485041a9b26d52..7d2b8dd23d19dede122396aa0092323147eb2923 100644 Binary files a/UWEFlix/__pycache__/forms.cpython-310.pyc and b/UWEFlix/__pycache__/forms.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/models.cpython-310.pyc b/UWEFlix/__pycache__/models.cpython-310.pyc index ee1086273651f5b3d43e3db4555bfcf4d91a4860..324fde43e74156df9fe7ae18e0509858eeaad2fd 100644 Binary files a/UWEFlix/__pycache__/models.cpython-310.pyc and b/UWEFlix/__pycache__/models.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/urls.cpython-310.pyc b/UWEFlix/__pycache__/urls.cpython-310.pyc index 173adb6634f0c2e1d119d0c32bce4ac4ec0dfab0..6cfc9aa41ddd2770aa51101ac76cb8f8304f3360 100644 Binary files a/UWEFlix/__pycache__/urls.cpython-310.pyc and b/UWEFlix/__pycache__/urls.cpython-310.pyc differ diff --git a/UWEFlix/__pycache__/views.cpython-310.pyc b/UWEFlix/__pycache__/views.cpython-310.pyc index 9e35dbd04438a367d36f5ef63f051235148eec6d..b17f35df47ad4f5f5950f2189e2484c0a0b557a7 100644 Binary files a/UWEFlix/__pycache__/views.cpython-310.pyc and b/UWEFlix/__pycache__/views.cpython-310.pyc differ diff --git a/UWEFlix/admin.py b/UWEFlix/admin.py index 8c38f3f3dad51e4585f3984282c2a4bec5349c1e..d1649fe0cd229505fe5d7c75c63249f3badae343 100644 --- a/UWEFlix/admin.py +++ b/UWEFlix/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin - +from .models import CinemaManager # Register your models here. + +admin.site.register(CinemaManager) \ No newline at end of file diff --git a/UWEFlix/forms.py b/UWEFlix/forms.py index bc7f172902b8e0a7473e693baf972929addc39b6..f819381dd55bb23e683acd5174837a9a78bf158e 100644 --- a/UWEFlix/forms.py +++ b/UWEFlix/forms.py @@ -1,5 +1,6 @@ from django import forms -from .models import Account, User, Club +from django.contrib.auth.models import User, Group +from .models import Account, User, Club, ClubRepresentative from django.contrib.auth.forms import AuthenticationForm, UserCreationForm class AccountForm(forms.ModelForm): @@ -20,3 +21,13 @@ class ClubForm(forms.ModelForm): class Meta: model = Club fields = ['name', 'address_details', 'contact_details', 'representative'] + +class RepresentativeRegistrationForm(forms.ModelForm): + club = forms.ChoiceField(choices=[(c.id, c.name) for c in Club.objects.all()]) + class Meta: + model = ClubRepresentative + fields = ['club'] + +class ElevateUserForm(forms.ModelForm): + user = forms.ModelChoiceField(queryset=User.objects.all()) + group = forms.ModelChoiceField(queryset=Group.objects.all()) \ No newline at end of file diff --git a/UWEFlix/migrations/0003_cinema_film_screen_showing_cinemamanager_cinema.py b/UWEFlix/migrations/0003_cinema_film_screen_showing_cinemamanager_cinema.py new file mode 100644 index 0000000000000000000000000000000000000000..dd774f5ca1ccea7092c3a69aa49fd503310a9048 --- /dev/null +++ b/UWEFlix/migrations/0003_cinema_film_screen_showing_cinemamanager_cinema.py @@ -0,0 +1,54 @@ +# Generated by Django 4.1.4 on 2023-01-03 01:01 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('UWEFlix', '0002_club_address_details_club_contact_details_club_name_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='Cinema', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('location', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Film', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255)), + ('length', models.PositiveIntegerField()), + ('rating', models.PositiveSmallIntegerField()), + ], + ), + migrations.CreateModel( + name='Screen', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('screen_number', models.PositiveSmallIntegerField()), + ('seating_capacity', models.PositiveIntegerField()), + ('cinema', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='screens', to='UWEFlix.cinema')), + ], + ), + migrations.CreateModel( + name='Showing', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('start_time', models.DateTimeField()), + ('film', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='showings', to='UWEFlix.film')), + ('screen', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='showings', to='UWEFlix.screen')), + ], + ), + migrations.AddField( + model_name='cinemamanager', + name='cinema', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='cinema', to='UWEFlix.cinema'), + ), + ] diff --git a/UWEFlix/migrations/__pycache__/0003_cinema_film_screen_showing_cinemamanager_cinema.cpython-310.pyc b/UWEFlix/migrations/__pycache__/0003_cinema_film_screen_showing_cinemamanager_cinema.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..44917e9b9d8b6069d7a70a1520f8b95560735747 Binary files /dev/null and b/UWEFlix/migrations/__pycache__/0003_cinema_film_screen_showing_cinemamanager_cinema.cpython-310.pyc differ diff --git a/UWEFlix/models.py b/UWEFlix/models.py index d9c4c23e0ad527a39f3b3f4e5200845b15fcbf13..8efe4a78094d9f37a9f2b0536ae50ad4275c72fd 100644 --- a/UWEFlix/models.py +++ b/UWEFlix/models.py @@ -37,7 +37,13 @@ class AccountManager(User): pass class CinemaManager(User): - pass + cinema = models.ForeignKey( + 'Cinema', + on_delete=models.CASCADE, + related_name='cinema', + null=True, + blank=True + ) class Club(models.Model): id = models.AutoField(primary_key=True) @@ -73,3 +79,21 @@ class Account(models.Model): discount_rate = models.DecimalField(max_digits=5, decimal_places=2) end_of_month_statements = models.TextField() +class Cinema(models.Model): + name = models.CharField(max_length=255) + location = models.CharField(max_length=255) + +class Film(models.Model): + title = models.CharField(max_length=255) + length = models.PositiveIntegerField() + rating = models.PositiveSmallIntegerField() + +class Screen(models.Model): + cinema = models.ForeignKey(Cinema, on_delete=models.CASCADE, related_name='screens') + screen_number = models.PositiveSmallIntegerField() + seating_capacity = models.PositiveIntegerField() + +class Showing(models.Model): + film = models.ForeignKey(Film, on_delete=models.CASCADE, related_name='showings') + screen = models.ForeignKey(Screen, on_delete=models.CASCADE, related_name='showings') + start_time = models.DateTimeField() \ No newline at end of file diff --git a/UWEFlix/templates/elevate_user.html b/UWEFlix/templates/elevate_user.html new file mode 100644 index 0000000000000000000000000000000000000000..2ccd0c309d1f01ffde92fa5e1b7ca95a37c95c70 --- /dev/null +++ b/UWEFlix/templates/elevate_user.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} + +{% block content %} + +<div class="container mt-4"> + <h1>Elevate User</h1> + <form method="post" action="{% url 'elevate_user' %}" class="needs-validation" novalidate> + {% csrf_token %} + <div class="form-group"> + <label for="user">User</label> + <select class="form-control" id="user" name="user" required> + {% for user in users %} + <option value="{{ user.id }}">{{ user.first_name }} {{ user.last_name }}</option> + {% endfor %} + </select> + </div> + <div class="form-check"> + <input class="form-check-input" type="radio" name="role" id="account_manager" value="account_manager" required> + <label class="form-check-label" for="account_manager">Account Manager</label> + </div> + <div class="form-check"> + <input class="form-check-input" type="radio" name="role" id="cinema_manager" value="cinema_manager" required> + <label class="form-check-label" for="cinema_manager">Cinema Manager</label> + </div> + <button type="submit" class="btn btn-primary">Elevate</button> + </form> +</div> + +{% endblock %} \ No newline at end of file diff --git a/UWEFlix/templates/index.html b/UWEFlix/templates/index.html new file mode 100644 index 0000000000000000000000000000000000000000..35837f0f690cd1efc93996d735bf13f693e0ae10 --- /dev/null +++ b/UWEFlix/templates/index.html @@ -0,0 +1,44 @@ +{% extends 'base.html' %} + +{% block content %} + +<div class="container mt-4"> + <h1>Index</h1> + {% if request.user.is_authenticated %} + {% if request.user.is_staff or request.user.is_superuser %} + <p>Welcome, {{ request.user.first_name }}! As an administrator, you have access to the following pages:</p> + <ul> + <li><a href="{% url 'create_account' %}">Create Account</a></li> + <li><a href="{% url 'representative_registration' %}">Representative Registration</a></li> + <li><a href="{% url 'create_club' %}">Club Registration</a></li> + <li><a href="{% url 'elevate_user' %}" class="btn btn-secondary mt-2">Elevate User</a></li> + </ul> + {% elif request.user.groups.filter(name='Cinema Manager').exists %} + <p>Welcome, {{ request.user.first_name }}! As a Cinema Manager, you have access to the following pages:</p> + <ul> + <li><a href="{% url 'create_account' %}">Create Account</a></li> + <li><a href="{% url 'representative_registration' %}">Representative Registration</a></li> + <li><a href="{% url 'create_club' %}">Club Registration</a></li> + </ul> + {% elif request.user.user_type == 'CR' %} + <p>Welcome, {{ request.user.first_name }}! As a club representative, you have access to the following pages:</p> + <ul> + <li><a href="{% url 'create_club' %}">Create Club</a></li> + </ul> + {% else %} + <p>Welcome, {{ request.user.first_name }}! You have access to the following pages:</p> + <ul> + <li><a href="{% url 'login' %}">Login</a></li> + <li><a href="{% url 'register' %}">Register</a></li> + </ul> + {% endif %} + {% else %} + <p>Welcome! You have access to the following pages:</p> + <ul> + <li><a href="{% url 'login' %}">Login</a></li> + <li><a href="{% url 'register' %}">Register</a></li> + </ul> + {% endif %} +</div> + +{% endblock %} \ No newline at end of file diff --git a/UWEFlix/templates/representative_registration.html b/UWEFlix/templates/representative_registration.html new file mode 100644 index 0000000000000000000000000000000000000000..c864c38f45344a03820c74dc59f357077acd2d9d --- /dev/null +++ b/UWEFlix/templates/representative_registration.html @@ -0,0 +1,38 @@ +{% extends 'base.html' %} + +{% block content %} + +<div class="container mt-4"> + <h1>Register as Club Representative</h1> + <form method="post" action="{% url 'representative_registration' %}"> + {% csrf_token %} + <div class="form-group"> + <label for="club">Club</label> + <select class="form-control" id="club" name="club"> + {% for club in clubs %} + <option value="{{ club.id }}">{{ club.name }}</option> + {% endfor %} + </select> + </div> + <div class="form-group"> + <label for="first_name">First Name</label> + <input type="text" class="form-control" id="first_name" name="first_name"> + </div> + <div class="form-group"> + <label for="last_name">Last Name</label> + <input type="text" class="form-control" id="last_name" name="last_name"> + </div> + <div class="form-group"> + <label for="email">Email</label> + <input type="email" class="form-control" id="email" name="email"> + </div> + <div class="form-group"> + <label for="password">Password</label> + <input type="password" class="form-control" id="password" name="password"> + </div> + <button type="submit" class="btn btn-primary">Submit</button> + </form> +</div> + + +{% endblock %} \ No newline at end of file diff --git a/UWEFlix/urls.py b/UWEFlix/urls.py index 9505be94d4e8b8cd56744bf4e3b953c7245434f3..c72a35eb037c7892c7907d99ff0058268fef9b1d 100644 --- a/UWEFlix/urls.py +++ b/UWEFlix/urls.py @@ -4,8 +4,11 @@ from . import views from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns = [ + path('', views.index_view, name='index'), + path('index/', views.index_view, name='index'), path('login/', views.login_view, name='login'), path('create_account/', views.create_account, name='create_account'), path('register/', views.register_view, name='register'), - path('create_club/', views.create_club, name='create_club') + path('create_club/', views.create_club, name='create_club'), + path('representative_registration/', views.representative_registration, name='representative_registration'), ] diff --git a/UWEFlix/views.py b/UWEFlix/views.py index 305be8006b3188cd2edd26e1dea2cd40b727330a..c60d8a233de0ac1b075b42cc8bc314e6870e13be 100644 --- a/UWEFlix/views.py +++ b/UWEFlix/views.py @@ -1,10 +1,17 @@ from django.shortcuts import render, redirect, HttpResponseRedirect from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required -from .forms import AccountForm, UserRegistrationForm, ClubForm -from .models import Account, User +from .forms import AccountForm, UserRegistrationForm, ClubForm, RepresentativeRegistrationForm, ElevateUserForm +from .models import Account, User, ClubRepresentative, Club +from django.http import JsonResponse + # Create your views here. + +def index_view(request): + return render(request, 'index.html') + + def login_view(request): if request.method == "POST": # Validate the form data @@ -30,8 +37,8 @@ def create_account(request): # code to handle form submission and create a new account form = AccountForm(request.POST) if form.is_valid(): - form.save() - # redirect to a success page + form.save(commit=True) + return redirect('/index/') else: # render the form with errors return render(request, 'create_account.html', {'form': form}) @@ -44,12 +51,12 @@ def register_view(request): if request.method == "POST": form = UserRegistrationForm(request.POST) if form.is_valid(): - form.save() + form.save(commit=True) email = form.cleaned_data['email'] password = form.cleaned_data['password1'] user = authenticate(request, email=email, password=password) login(request, user) - return redirect('success') + return redirect('/index/') else: form = UserRegistrationForm() return render(request, 'register.html', {'form': form}) @@ -59,8 +66,33 @@ def create_club(request): if request.method == 'POST': form = ClubForm(request.POST) if form.is_valid(): - club = form.save() - return redirect('club_detail', pk=club.pk) + club = form.save(commit=True) + #return redirect('club_detail', pk=club.pk) + return redirect('/index/') else: form = ClubForm() - return render(request, 'create_club.html', {'form': form}) \ No newline at end of file + return render(request, 'create_club.html', {'form': form}) + + +def representative_registration(request): + clubs = Club.objects.all() + if request.method == 'POST': + form = RepresentativeRegistrationForm(request.POST) + if form.is_valid(): + form.save(commit=True) + return redirect('login') + else: + form = RepresentativeRegistrationForm() + return render(request, 'representative_registration.html', {'form': form, 'clubs': clubs}) + + +def elevate_user_view(request): + if request.method== 'POST': + form = ElevateUserForm(request.POST) + if form.is_valid(): + form.save(commit=True) + return redirect('/index/') + + else: + form = ElevateUserForm() + return render(request, 'elevate_user.html', {'form': form}) \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index c5f2a3bb7f28e7043c462aaba2d74844d1f42fb6..26aff06e47ad63b3887aa7f7559f41d03c5cbb93 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/web_project/__pycache__/settings.cpython-310.pyc b/web_project/__pycache__/settings.cpython-310.pyc index f82e0004e1675d4942672ea7ccfcde028c0bef55..6b2203b33813da9af119f7b26cffbfa62a4ff4b4 100644 Binary files a/web_project/__pycache__/settings.cpython-310.pyc and b/web_project/__pycache__/settings.cpython-310.pyc differ diff --git a/web_project/__pycache__/urls.cpython-310.pyc b/web_project/__pycache__/urls.cpython-310.pyc index b82b5c64e80e5e702f96fcf5c19e9f24d0e357ea..33683b7453a7a4525307d0492ddd713425fcde44 100644 Binary files a/web_project/__pycache__/urls.cpython-310.pyc and b/web_project/__pycache__/urls.cpython-310.pyc differ