diff --git a/UWEFlix/__pycache__/admin.cpython-310.pyc b/UWEFlix/__pycache__/admin.cpython-310.pyc index a4b3473f0bd376f1dd049c6e831f50c99cd2a0c2..28bab0e0cd4e5956a49e92a6aeff983b5e87f63e 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 dc1fb7161809d003f928da322212e998b12f95ff..aa41da47cd667f7d935764a44d5900f7abdd51d9 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 defe40172299e2850e833e0d99ec35f01db44b82..5f795547eebe5388510cc095edcb847bb235e51b 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 9be615b1473ef52ab0e6e3911aed19c7263ffd7d..5a4a8efcf7222896a7b8d292ece61a08d3fa6b11 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 1820bc410e1e1dbd187c9f86cc8f2bdb00d88969..3b088c486ba9b25d0c54ef89871b4f511bd93c54 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 2377a13216d732af2db629ad5fa07e4ce733047c..df5b56a33a4eaa4f6587354ac090ad1f636907c3 100644 --- a/UWEFlix/admin.py +++ b/UWEFlix/admin.py @@ -1,4 +1,4 @@ from django.contrib import admin -from .models import CinemaManager, User, AccountManager, ClubRepresentative +from .models import CinemaManager, User, AccountManager # Register your models here. admin.site.register(User) \ No newline at end of file diff --git a/UWEFlix/forms.py b/UWEFlix/forms.py index 8166a8b1545c3d6276a12998da5aa62b77014bad..7218de6152c00f9c47c6fc4c5b66801b8fe456f1 100644 --- a/UWEFlix/forms.py +++ b/UWEFlix/forms.py @@ -4,9 +4,10 @@ from .models import Account, User, Club, ClubRepresentative, Screen, Cinema, Sho from django.contrib.auth.forms import AuthenticationForm, UserCreationForm class AccountForm(forms.ModelForm): + club = forms.ModelChoiceField(queryset=Club.objects.all()) class Meta: model = Account - fields = ['club', 'payment_card_number', 'payment_card_expiry_date', 'discount_rate'] + fields = ['payment_card_number', 'payment_card_expiry_date', 'discount_rate', 'club'] class UserRegistrationForm(UserCreationForm): @@ -17,19 +18,18 @@ class UserRegistrationForm(UserCreationForm): class ClubForm(forms.ModelForm): + representative = forms.ModelChoiceField(queryset=User.objects.all()) 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()) + group = forms.ChoiceField(choices=[ + ('account_manager', 'Account Manager'), + ('cinema_manager', 'Cinema Manager') + ]) class Meta: model = User diff --git a/UWEFlix/migrations/0007_alter_user_groups_alter_user_user_permissions.py b/UWEFlix/migrations/0007_alter_user_groups_alter_user_user_permissions.py new file mode 100644 index 0000000000000000000000000000000000000000..64e42b83405241c95cbaf09edbc544f08600dd29 --- /dev/null +++ b/UWEFlix/migrations/0007_alter_user_groups_alter_user_user_permissions.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.4 on 2023-01-05 20:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ('UWEFlix', '0006_film_genre'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='groups', + field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups'), + ), + migrations.AlterField( + model_name='user', + name='user_permissions', + field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions'), + ), + ] diff --git a/UWEFlix/migrations/0008_remove_clubrepresentative_club_user_club_and_more.py b/UWEFlix/migrations/0008_remove_clubrepresentative_club_user_club_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..dd6bac592f9721288a19dffbcfb640f35747d62a --- /dev/null +++ b/UWEFlix/migrations/0008_remove_clubrepresentative_club_user_club_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.1.4 on 2023-01-05 23:05 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('UWEFlix', '0007_alter_user_groups_alter_user_user_permissions'), + ] + + operations = [ + migrations.RemoveField( + model_name='clubrepresentative', + name='club', + ), + migrations.AddField( + model_name='user', + name='club', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='club_members', to='UWEFlix.club'), + ), + migrations.AddField( + model_name='user', + name='club_rep', + field=models.BooleanField(default=False), + preserve_default=False, + ), + ] diff --git a/UWEFlix/migrations/0009_remove_account_club_club_account.py b/UWEFlix/migrations/0009_remove_account_club_club_account.py new file mode 100644 index 0000000000000000000000000000000000000000..87354779f223eaffde41e9afacbaa4deee241a65 --- /dev/null +++ b/UWEFlix/migrations/0009_remove_account_club_club_account.py @@ -0,0 +1,23 @@ +# Generated by Django 4.1.4 on 2023-01-06 00:36 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('UWEFlix', '0008_remove_clubrepresentative_club_user_club_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='account', + name='club', + ), + migrations.AddField( + model_name='club', + name='account', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='club_account', to='UWEFlix.account'), + ), + ] diff --git a/UWEFlix/migrations/0010_remove_user_club_alter_club_representative.py b/UWEFlix/migrations/0010_remove_user_club_alter_club_representative.py new file mode 100644 index 0000000000000000000000000000000000000000..c3a16b5701de1258f344c107e4b0b24f9bfb7d1d --- /dev/null +++ b/UWEFlix/migrations/0010_remove_user_club_alter_club_representative.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.4 on 2023-01-06 01:21 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('UWEFlix', '0009_remove_account_club_club_account'), + ] + + operations = [ + migrations.RemoveField( + model_name='user', + name='club', + ), + migrations.AlterField( + model_name='club', + name='representative', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='clubs', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/UWEFlix/migrations/0011_account_club.py b/UWEFlix/migrations/0011_account_club.py new file mode 100644 index 0000000000000000000000000000000000000000..b0feeec4349169810fc78cf3a76ead5083338cf2 --- /dev/null +++ b/UWEFlix/migrations/0011_account_club.py @@ -0,0 +1,19 @@ +# Generated by Django 4.1.4 on 2023-01-06 01:29 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('UWEFlix', '0010_remove_user_club_alter_club_representative'), + ] + + operations = [ + migrations.AddField( + model_name='account', + name='club', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='account_of_club', to='UWEFlix.club'), + ), + ] diff --git a/UWEFlix/migrations/0012_remove_account_club.py b/UWEFlix/migrations/0012_remove_account_club.py new file mode 100644 index 0000000000000000000000000000000000000000..f26bd558a1e1924358eeec827baa68bd42c96444 --- /dev/null +++ b/UWEFlix/migrations/0012_remove_account_club.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.4 on 2023-01-06 01:48 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('UWEFlix', '0011_account_club'), + ] + + operations = [ + migrations.RemoveField( + model_name='account', + name='club', + ), + ] diff --git a/UWEFlix/migrations/__pycache__/0007_alter_user_groups_alter_user_user_permissions.cpython-310.pyc b/UWEFlix/migrations/__pycache__/0007_alter_user_groups_alter_user_user_permissions.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a6afb2b31660490c1105e9b58406c0aa2005011b Binary files /dev/null and b/UWEFlix/migrations/__pycache__/0007_alter_user_groups_alter_user_user_permissions.cpython-310.pyc differ diff --git a/UWEFlix/migrations/__pycache__/0008_remove_clubrepresentative_club_user_club_and_more.cpython-310.pyc b/UWEFlix/migrations/__pycache__/0008_remove_clubrepresentative_club_user_club_and_more.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3d9c88a157c3f8727c059ffdf32a77e1a3c4e520 Binary files /dev/null and b/UWEFlix/migrations/__pycache__/0008_remove_clubrepresentative_club_user_club_and_more.cpython-310.pyc differ diff --git a/UWEFlix/migrations/__pycache__/0009_remove_account_club_club_account.cpython-310.pyc b/UWEFlix/migrations/__pycache__/0009_remove_account_club_club_account.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8bae791f1e87c0c0735a401827f0040eff1903e0 Binary files /dev/null and b/UWEFlix/migrations/__pycache__/0009_remove_account_club_club_account.cpython-310.pyc differ diff --git a/UWEFlix/migrations/__pycache__/0010_remove_user_club_alter_club_representative.cpython-310.pyc b/UWEFlix/migrations/__pycache__/0010_remove_user_club_alter_club_representative.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..41fb61a62434a81943821f3ee6fbb04852dcd0a4 Binary files /dev/null and b/UWEFlix/migrations/__pycache__/0010_remove_user_club_alter_club_representative.cpython-310.pyc differ diff --git a/UWEFlix/migrations/__pycache__/0011_account_club.cpython-310.pyc b/UWEFlix/migrations/__pycache__/0011_account_club.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..da378414c58600f18c1ae514d6dee63f78e0caa9 Binary files /dev/null and b/UWEFlix/migrations/__pycache__/0011_account_club.cpython-310.pyc differ diff --git a/UWEFlix/migrations/__pycache__/0012_remove_account_club.cpython-310.pyc b/UWEFlix/migrations/__pycache__/0012_remove_account_club.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2b1073ff31c6c0ffa3f3b8048c8d8fcf2a606107 Binary files /dev/null and b/UWEFlix/migrations/__pycache__/0012_remove_account_club.cpython-310.pyc differ diff --git a/UWEFlix/models.py b/UWEFlix/models.py index 2394c805f5ab38a307ddf95d07afec29c6f8c0a9..ef3fd0fefdfafe6ec1d322ef32c791028c00165b 100644 --- a/UWEFlix/models.py +++ b/UWEFlix/models.py @@ -5,33 +5,11 @@ from django.contrib.auth.models import AbstractUser, Group, Permission class User(AbstractUser): - # ... - groups = models.ManyToManyField( - Group, - related_name='uweflix_groups', - blank=True, - help_text=( - 'The groups this user belongs to. A user will get all permissions granted to each of their groups.' - ), - verbose_name='groups', - ) - user_permissions = models.ManyToManyField( - Permission, - related_name='uweflix_user_permissions', - blank=True, - help_text='Specific permissions for this user.', - verbose_name='user permissions', - ) + club_rep = models.BooleanField(default=False) # ... class ClubRepresentative(User): - club = models.ForeignKey( - 'Club', - on_delete=models.CASCADE, - related_name='club_representatives', - null=True, - blank=True - ) + pass class AccountManager(User): pass @@ -49,7 +27,7 @@ class Club(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=50) representative = models.ForeignKey( - 'ClubRepresentative', + 'User', on_delete=models.CASCADE, related_name='clubs', null=True, @@ -57,23 +35,17 @@ class Club(models.Model): ) address_details = models.TextField(max_length=100, default='') contact_details = models.TextField(max_length=50, default='') - - def register_representative(self, representative): - pass - - def update_representative(self, representative): - pass - - -class Account(models.Model): - id = models.AutoField(primary_key=True) - club = models.ForeignKey( - 'Club', + account = models.ForeignKey( + 'Account', on_delete=models.CASCADE, - related_name='accounts', + related_name='club_account', null=True, blank=True ) + + +class Account(models.Model): + id = models.AutoField(primary_key=True) payment_card_number = models.CharField(max_length=20) payment_card_expiry_date = models.DateField() discount_rate = models.DecimalField(max_digits=5, decimal_places=2) diff --git a/UWEFlix/templates/base.html b/UWEFlix/templates/base.html index a177bee76da0cb927ebe3ec6d9f3d0c4caa56353..e70a98f8e9389b8c87f6e00919f39a644dea52db 100644 --- a/UWEFlix/templates/base.html +++ b/UWEFlix/templates/base.html @@ -21,6 +21,14 @@ </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav"> + {% if not user.is_authenticated %} + <li class="nav-item"> + <a class="nav-link" href="{% url 'login' %}">Login</a> + </li> + <li class="nav-item"> + <a class="nav-link" href="{% url 'register' %}">Signup</a> + </li> + {% endif %} <li class="nav-item active"> <a class="nav-link" href="{% url 'index' %}">Home</a> </li> @@ -34,7 +42,14 @@ <li class="nav-item"> <a class = "nav-link" href="{% url 'view_details' %}">View My Details</a> </li> + <li class="nav-item"> + <a class = "nav-link" href="{% url 'manage_screens' %}">Manage Screens</a> + </li> + <li class="nav-item"> + <a class = "nav-link" href="{% url 'manage_clubs' %}">Manage Clubs</a> + </li> {% endif %} + </ul> </div> </nav> diff --git a/UWEFlix/templates/create_account.html b/UWEFlix/templates/create_account.html index 3645ec9051f6f1e94fed4b9ff8a8f389c683ef84..9f2e01b41f34090a353971fc0430167619a5168d 100644 --- a/UWEFlix/templates/create_account.html +++ b/UWEFlix/templates/create_account.html @@ -4,33 +4,30 @@ <div class="container mt-4"> <h1>Create New Account</h1> - <form method="post" action="{% url 'create_account' %}"> + <form method="POST" action="{% url 'create_account' %}"> {% 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> + <label for="payment_card_number">Payment Card Number</label> + {{ form.payment_card_number }} </div> <div class="form-group"> - <label for="paymentCardNumber">Payment Card Number</label> - <input type="text" class="form-control" id="paymentCardNumber" name="paymentCardNumber" placeholder="Payment Card Number"> + <label for="payment_card_expiry_date">Payment Card Expiry Date</label> + <input type="date" class="form-control" id="payment_card_expiry_date" name="payment_card_expiry_date" required> </div> <div class="form-group"> - <label for="paymentCardExpiryDate">Payment Card Expiry Date</label> - <input type="date" class="form-control" id="paymentCardExpiryDate" name="paymentCardExpiryDate" placeholder="Payment Card Expiry Date"> + <label for="discount_rate">Discount Rate</label> + {{ form.discount_rate }} </div> <div class="form-group"> - <label for="discountRate">Discount Rate</label> - <input type="number" class="form-control" id="discountRate" name="discountRate" placeholder="Discount Rate"> + <label for="club">Club</label> + <select class="form-control" id="club" name="club" required> + {% for club in clubs %} + <option value="{{ club.id }}">{{ club.name }}</option> + {% endfor %} + </select> + </div> </div> <button type="submit" class="btn btn-primary">Create Account</button> - </form> </div> -{% endblock %} - - - +{% endblock %} \ No newline at end of file diff --git a/UWEFlix/templates/create_cinema.html b/UWEFlix/templates/create_cinema.html new file mode 100644 index 0000000000000000000000000000000000000000..7012047a1aa67f6666b09de896eed8e7aa84c9e7 --- /dev/null +++ b/UWEFlix/templates/create_cinema.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} + +{% block content %} + +<div class="container mt-4"> + <h1>Create Cinema</h1> + <form method="post" action="{% url 'create_cinema' %}"> + {% csrf_token %} + <div class="form-group"> + <label for="name">Name</label> + <input type="text" class="form-control" id="name" name="name" required> + </div> + <div class = "form-group"> + <label for = "location">Location</label> + <input type="text" class="form-control" id="location" name="location" required> + </div> + <button type="submit" class="btn btn-primary">Create Cinema</button> + + </form> +</div> + +{% endblock %} \ No newline at end of file diff --git a/UWEFlix/templates/create_club.html b/UWEFlix/templates/create_club.html index 155363bb40d7db48530607cb20bb059f64ef42e5..1d99c1e54504ba8bae38d2f3f244bc22fbd16c7c 100644 --- a/UWEFlix/templates/create_club.html +++ b/UWEFlix/templates/create_club.html @@ -14,7 +14,7 @@ <label for="representative">Representative</label> <select class="form-control" id="representative" name="representative"> {% for representative in representatives %} - <option value="{{ representative.id }}">{{ representative.first_name }} {{ representative.last_name }}</option> + <option value="{{ representative.id }}">{{ representative.username }}</option> {% endfor %} </select> </div> @@ -26,7 +26,7 @@ <label for="contact_details">Contact Details</label> <textarea class="form-control" id="contact_details" name="contact_details" rows="3"></textarea> </div> - <button type="submit" class="btn btn-primary">Create Club</button> + <button type="submit" class="btn btn-primary">Create Club</button> </form> </div> diff --git a/UWEFlix/templates/create_showing.html b/UWEFlix/templates/create_showing.html index 95807e6bf4451b88916ba666aed8473b98ced98b..5100af40cf424994232cf245d2000b1fb691b213 100644 --- a/UWEFlix/templates/create_showing.html +++ b/UWEFlix/templates/create_showing.html @@ -16,7 +16,7 @@ </div> <div class="form-group"> <label for="screen">Screen</label> - <select class="form-control" id="screen" name="screen" disabled> + <select class="form-control" id="screen" name="screen" required> {% for screen in screens %} <option value="{{ screen.id }}">{{ screen.cinema.name }} - Screen {{ screen.screen_number }}</option> {% endfor %} diff --git a/UWEFlix/templates/elevate_user.html b/UWEFlix/templates/elevate_user.html index 876340d1c0925b487716342a338099ce72700a73..45087d6697134f77fdfede29ae7ddd0f414ee938 100644 --- a/UWEFlix/templates/elevate_user.html +++ b/UWEFlix/templates/elevate_user.html @@ -15,11 +15,11 @@ </select> </div> <div class="form-check"> - <input class="form-check-input" type="radio" name="role" id="account_manager" value="account_manager" required> + <input class="form-check-input" type="radio" name="group" 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> + <input class="form-check-input" type="radio" name="group" 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> diff --git a/UWEFlix/templates/index.html b/UWEFlix/templates/index.html index 198e1ce1179f7fb81ff714d7f56c4f54e917f2e3..ce45d6c6e274592005f92dd13d7d2f2c44de639f 100644 --- a/UWEFlix/templates/index.html +++ b/UWEFlix/templates/index.html @@ -10,9 +10,6 @@ <p>Welcome! You have access to the following pages:</p> {% endif %} <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> </div> diff --git a/UWEFlix/templates/manage_clubs.html b/UWEFlix/templates/manage_clubs.html new file mode 100644 index 0000000000000000000000000000000000000000..b793656c5a2e51af7c5b3cb63e042ec79163845d --- /dev/null +++ b/UWEFlix/templates/manage_clubs.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} + +{% block content %} + +<div class="container mt-4"> + <h1>Manage Clubs</h1> + {% if clubs %} + {% for club in clubs %} + <div class="card mb-3"> + <div class="card-body"> + <h5 class="card-title">{{ club.name }}</h5> + <p class="card-text">Account: {{ club.account.id }}</p> + <p class="card-text">Club Representative: {{ club.representative.username }}</p> + <a href="{% url 'update_club' pk=club.pk %}" class="btn btn-primary">Update</a> + <a href="{% url 'delete_club' pk=club.pk %}" class="btn btn-danger">Delete</a> + <a href="{% url 'create_account' %}" class="btn btn-secondary">Create Account</a> + </div> + </div> + {% endfor %} + {% else %} + <p>No clubs to display.</p> + {% endif %} + <a href="{% url 'create_club' %}" class="btn btn-success mt-2">Create Club</a> +</div> +{% endblock %} \ No newline at end of file diff --git a/UWEFlix/templates/manage_screens.html b/UWEFlix/templates/manage_screens.html index 9c8199b57d2115e7f78d202e52e727064181d0cd..4c50b9982fddc983fa6bafc293ae95e735c86682 100644 --- a/UWEFlix/templates/manage_screens.html +++ b/UWEFlix/templates/manage_screens.html @@ -13,13 +13,15 @@ <p class="card-text">Seating Capacity: {{ screen.seating_capacity }}</p> <a href="{% url 'update_screen' pk=screen.pk %}" class="btn btn-primary">Update</a> <a href="{% url 'delete_screen' pk=screen.pk %}" class="btn btn-danger">Delete</a> - <a href="{% url 'create_showing' pk=screen.pk origin=0 %}" class="btn btn-success mt-2">Create Showing</a> + <a href="{% url 'create_showing' %}" class="btn btn-success mt-2">Create Showing</a> {% if screen.showings %} <h6 class="mt-3">Showings:</h6> <ul> {% for showing in showings %} {% if showing.screen.pk == screen.pk %} <li>{{ showing.film.title }} - {{ showing.start_time|date:'g:i A' }}</li> + <a href="{% url 'update_showing' pk=showing.pk %}" class="btn btn-primary">Update</a> + <a href="{% url 'delete_showing' pk=showing.pk %}" class="btn btn-danger">Delete</a> {% endif %} {% endfor %} </ul> diff --git a/UWEFlix/templates/no_access.html b/UWEFlix/templates/no_access.html new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/UWEFlix/templates/update_club.html b/UWEFlix/templates/update_club.html new file mode 100644 index 0000000000000000000000000000000000000000..a4b004836beb12060c7d771501b28b12bec7c07e --- /dev/null +++ b/UWEFlix/templates/update_club.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} + <div class="container mt-4"> + <h1>Update Club</h1> + <form method="post" action="{% url 'update_club' club.id %}"> + {% csrf_token %} + {{ form.as_p }} + <button type="submit" class="btn btn-primary">Update Club</button> + <a href="{% url 'manage_clubs' %}" class="btn btn-secondary">Cancel</a> + </form> + </div> +{% endblock %} \ No newline at end of file diff --git a/UWEFlix/templates/view_details.html b/UWEFlix/templates/view_details.html index a33b810e41759860b72a4082eef8cb049b0f1340..1e70ac74d2e0c28ced848262c849df65ae1ec6ec 100644 --- a/UWEFlix/templates/view_details.html +++ b/UWEFlix/templates/view_details.html @@ -8,6 +8,7 @@ <p>First Name: {{ user.first_name }}</p> <p>Last Name: {{ user.last_name }}</p> <p>Email: {{ user.email }}</p> + <p>Groups: {{ user.groups.all }}</p> </div> {% endblock %} \ No newline at end of file diff --git a/UWEFlix/urls.py b/UWEFlix/urls.py index 818e444c538c17de50068505f5df08c10efa5253..cfb861ed1d2f71c5dc64fb90b2a7ece00e53a09a 100644 --- a/UWEFlix/urls.py +++ b/UWEFlix/urls.py @@ -5,12 +5,12 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns = [ path('', views.index_view, name='index'), + path('no_access/', views.no_access_redirect, name='no_access'), 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('representative_registration/', views.representative_registration, name='representative_registration'), + path('create_club/', views.club_create, name='create_club'), + path('create_cinema/', views.create_cinema, name="create_cinema"), path('elevate_user', views.elevate_user_view, name='elevate_user'), path('view_details/', views.view_my_details, name='view_details'), path('manage_screens/', views.screen_list, name='manage_screens'), @@ -19,5 +19,11 @@ urlpatterns = [ path('manage_screens/delete_screen/<int:pk>/', views.screen_delete, name='delete_screen'), path('manage_screens/screen_list/', views.screen_list, name='screen_list'), path('manage_screens/showings/create_showing/', views.showing_create, name='create_showing'), + path('manage_screens/showings/update_showing/<int:pk>', views.showing_update, name='update_showing'), + path('manage_screens/showings/delete_showing/<int:pk>', views.showing_delete, name='delete_showing'), + path('manage_clubs/', views.clubs_list, name='manage_clubs'), + path('manage_clubs/<int:pk>/update', views.club_update, name='update_club'), + path('manage_clubs/<int:pk>/delete', views.club_delete, name='delete_club'), + path('manage_clubs/create_account/', views.account_create, name='create_account'), path('create_film/', views.film_create, name='create_film') ] diff --git a/UWEFlix/views.py b/UWEFlix/views.py index ee3acbe9956e0fe26295cdc910fe6a9975f69a92..5e616fef843e8a7771df968f63443d61b7e199ce 100644 --- a/UWEFlix/views.py +++ b/UWEFlix/views.py @@ -2,8 +2,8 @@ from django.shortcuts import render, redirect, HttpResponseRedirect, get_object_ from django.contrib import messages from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required -from .forms import AccountForm, UserRegistrationForm, ClubForm, RepresentativeRegistrationForm, ElevateUserForm, ScreenForm, ShowingForm, FilmForm -from .models import Account, User, ClubRepresentative, Club, Screen, Cinema, Film, Showing +from .forms import AccountForm, UserRegistrationForm, ClubForm, ElevateUserForm, ScreenForm, ShowingForm, FilmForm, CinemaForm +from .models import Account, User, Club, Screen, Cinema, Film, Showing from django.http import JsonResponse from django.contrib.auth.models import AbstractUser, Group, Permission @@ -12,9 +12,11 @@ from django.contrib.auth.models import AbstractUser, Group, Permission def index_view(request): return render(request, 'index.html') +def no_access_redirect(request): + return render(request, 'no_access.html') -def login_view(request): +def login_view(request): ### IF USER HAS SUBMITTED FORM ### if request.method == "POST": # Validate the form data @@ -23,7 +25,7 @@ def login_view(request): user = authenticate(request, username=username, password=password) if user is not None: login(request, user) - return redirect('home') + return redirect('index') else: error_message = "Invalid username or password" context = {'error_message': error_message} @@ -54,49 +56,20 @@ def register_view(request): return render(request, 'register.html', {'form': form}) -def create_account(request): - ### USER SUBMITS FORM ### - if request.method == 'POST': - # code to handle form submission and create a new account - form = AccountForm(request.POST) +def create_cinema(request): + if request.method == "POST": + form = CinemaForm(request.POST) if form.is_valid(): form.save(commit=True) - return redirect('/index/') + return redirect('manage_screens') else: - # render the form with errors + form = CinemaForm() context = {'form': form, 'user': request.user} - return render(request, 'create_account.html', context) - else: - ### USER REQUESTS FORM ### - # render the empty form - form = AccountForm() - context = {'form': form, 'user': request.user} - return render(request, 'create_account.html', context) - + return render(request, 'create_cinema.html', context) -def create_club(request): - if request.method == 'POST': - form = ClubForm(request.POST) - if form.is_valid(): - club = form.save(commit=True) - #return redirect('club_detail', pk=club.pk) - return redirect('/index/') - form = ClubForm() + form = CinemaForm() context = {'form': form, 'user': request.user} - return render(request, 'create_club.html', context) - - -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') - - form = RepresentativeRegistrationForm() - context = {'form': form, 'user': request.user, 'clubs': clubs} - return render(request, 'representative_registration.html', context) + return render(request, 'create_cinema.html', context) def elevate_user_view(request): @@ -104,26 +77,22 @@ def elevate_user_view(request): form = ElevateUserForm(request.POST) if form.is_valid(): # Form is valid, process the data and return a response - user_id = form.cleaned_data['user'] - user = User.objects.get(id=user_id) - role = form.cleaned_data['role'] - - if role == 'account_manager': - group, created = Group.objects.get_or_create(name='Account Manager') - user.groups.add(group) - elif role == 'cinema_manager': - group, created = Group.objects.get_or_create(name='Cinema Manager') - user.groups.add(group) - else: - # Handle invalid role selection - pass + username = form.cleaned_data['user'] + user = User.objects.get(username=username) + group_name = form.cleaned_data['group'] + + group, created = Group.objects.get_or_create(name=group_name) + user.groups.add(group) # Save changes to the user instance user.save() return redirect('index') + else: + print('invalid form') + else: + form = ElevateUserForm() - form = ElevateUserForm() context = {'form': form, 'user': request.user, 'users': User.objects.all()} return render(request, 'elevate_user.html', context) @@ -136,7 +105,9 @@ def view_my_details(request): return render(request, 'view_details.html', {'user': user}) -### SCREEN MANAGEMENT ### +#################### SCREEN MANAGEMENT ######################## + + def screen_list(request): screens = Screen.objects.all() showings = Showing.objects.all() @@ -154,7 +125,8 @@ def screen_create(request): #if request.user.cinema == form.cleaned_data['cinema']: form.save() form = ScreenForm() - + context = {'form': form, 'user': request.user, 'cinemas': Cinema.objects.all()} + return redirect('manage_screens') form = ScreenForm() context = {'form': form, 'user': request.user, 'cinemas': Cinema.objects.all()} return render(request, 'create_screen.html', {'form': form, 'cinemas': cinemas}) @@ -181,14 +153,115 @@ def showing_create(request): screens = Screen.objects.all() if request.method == 'POST': form = ShowingForm(request.POST) + print(form.errors) if form.is_valid(): - form.save() - form = ShowingForm() - + form.save(commit=True) + return redirect('manage_screens') + else: + print('invalid form') form = ShowingForm() context = {'form': form, 'user': request.user, 'films': films, 'screens': screens} return render(request, 'create_showing.html', context) +def showing_update(request, pk): + showing = get_object_or_404(Showing, pk=pk) + films = Film.objects.all() + screens = Screen.objects.all() + if request.method == 'POST': + form = ShowingForm(request.POST, instance=showing) + if form.is_valid(): + form.save() + return redirect('manage_screens') + form = ShowingForm(instance=showing) + context = {'form': form, 'user': request.user, 'films': films, 'screens': screens} + return render(request, 'update_showing.html', context) + +def showing_delete(request, pk): + showing = get_object_or_404(Showing, pk=pk) + if request.method == 'POST': + showing.delete() + + +############### ACCOUNT MANAGEMENT ##################### + +def clubs_list(request): + clubs = Club.objects.all() + accounts = Account.objects.all() + #representatives = User.objects.all().filter(club_rep=True) + context = {'user': request.user, 'clubs': clubs, 'accounts': accounts} + return render(request, 'manage_clubs.html', context) + +def club_update(request, pk): + club = get_object_or_404(Club, pk=pk) + + # Check if the request method is POST + if request.method == 'POST': + # Bind the form with the POST data + form = ClubForm(request.POST, instance=club) + # Check if the form is valid + if form.is_valid(): + # Save the form and redirect to the club list page + form.save() + return redirect('manage_clubs') + # If the request is not POST, or the form is invalid, + # render the update page with the club instance and the form + form = ClubForm(instance=club) + context = {'form': form, 'club': club, 'pk': pk} + return render(request, 'update_club.html', context) + +def club_delete(request, pk): + club = get_object_or_404(Club, pk=pk) + if request.method == 'POST': + club.delete() + +def club_create(request): + representatives = User.objects.all() + if request.method == 'POST': + form = ClubForm(request.POST) + if form.is_valid(): + club = form.save(commit=True) + #return redirect('club_detail', pk=club.pk) + return redirect('/index/') + form = ClubForm() + context = {'form': form, 'user': request.user, 'representatives': representatives} + return render(request, 'create_club.html', context) + +def account_create(request): + clubs = Club.objects.all() + ### USER SUBMITS FORM ### + if not request.user.groups.all().filter(name='account_manager').exists(): + print(request.user.user_permissions) + return redirect('no_access') + + if request.method == 'POST': + # code to handle form submission and create a new account + form = AccountForm(request.POST) + print(form.errors) + if form.is_valid(): + account = form.save(commit=True) + club = form.cleaned_data['club'] + club.account = account + club.save() + return redirect('manage_clubs') + else: + # render the form with errors + context = {'form': form, 'user': request.user, 'clubs': clubs} + return render(request, 'create_account.html', context) + else: + ### USER REQUESTS FORM ### + # render the empty form + form = AccountForm() + context = {'form': form, 'user': request.user, 'clubs': clubs} + return render(request, 'create_account.html', context) + + + + + + +### FILM MANAGEMENT + + def film_create(request, pk=None): success = False if request.method == 'POST': @@ -200,4 +273,6 @@ def film_create(request, pk=None): form = FilmForm() context = {'form': form, 'user': request.user, 'pk': pk} return render(request, 'create_film.html', context) - \ No newline at end of file + + + diff --git a/db.sqlite3 b/db.sqlite3 index 8ec1ce490ae91f42862f2fd18ff2c333fec58a2c..182072771686fd233b4f322819946de11d81dc48 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 6b2203b33813da9af119f7b26cffbfa62a4ff4b4..ddd11519db875f520fde4e2a1b4d2eb2087a4e47 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/settings.py b/web_project/settings.py index 123b3436d77b7f83150e9ccafa93de88470efe7d..b83829cb8128a9a23d2b2228bba9cb825376b56c 100644 --- a/web_project/settings.py +++ b/web_project/settings.py @@ -122,3 +122,5 @@ STATIC_URL = 'static/' # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +AUTH_USER_MODEL = 'UWEFlix.User'