diff --git a/backend/.gitignore b/backend/.gitignore index 088ebe0..03c9941 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,3 +1,4 @@ data media -static \ No newline at end of file +static +*.json \ No newline at end of file diff --git a/backend/backend_api/admin.py b/backend/backend_api/admin.py index f3919bf..15a51d0 100644 --- a/backend/backend_api/admin.py +++ b/backend/backend_api/admin.py @@ -3,27 +3,8 @@ from backend_api import models from backend_api.email import MailerThread -from backend_api.models import Discount - - -def desc_creator(selected_model): - class AdminForm(forms.ModelForm): - desc = forms.CharField(widget=forms.Textarea) - - class Meta: - model = selected_model - fields = '__all__' - - class Admin(admin.ModelAdmin): - form = AdminForm - if selected_model == models.Workshop: - list_display = ('__str__', 'capacity', 'cost', 'has_project', 'level', 'no_of_participants', 'year') - readonly_fields = ('participants',) - elif selected_model == models.Presentation: - list_display = ('__str__', 'level', 'no_of_participants', 'year') - readonly_fields = ('participants',) - - return Admin +from backend_api.models import Discount, Presentation +from utils.skyroom_exporter import SkyroomCredentials, convert_credentials_to_csv_response class TeacherAdminForm(forms.ModelForm): @@ -129,6 +110,54 @@ class Meta: fields = '__all__' +class PresentationAdmin(admin.ModelAdmin): + list_display = ('__str__', 'level', 'no_of_participants', 'year') + readonly_fields = ('participants',) + actions = ['export_login_credentials'] + + class Meta: + model = Presentation + fields = '__all__' + + @admin.action(description='Export login credentials') + def export_login_credentials(self, request, obj): + user_credentials: list[SkyroomCredentials] = [] + for presentation in obj: + for presentation_registration in presentation.presentationparticipation_set.all(): + user_credentials.append( + SkyroomCredentials(presentation_registration.username, presentation_registration.password, + presentation_registration.user.account.email)) + return convert_credentials_to_csv_response(user_credentials) + + +class WorkshopAdmin(admin.ModelAdmin): + list_display = ('__str__', 'capacity', 'cost', 'has_project', 'level', 'no_of_participants', 'year') + readonly_fields = ('participants',) + actions = ['export_login_credentials'] + + class Meta: + model = models.Workshop + fields = '__all__' + + @admin.action(description='Export login credentials') + def export_login_credentials(self, request, obj): + user_credentials: list[SkyroomCredentials] = [] + for workshop in obj: + for workshop_registration in workshop.workshopregistration_set.all(): + user_credentials.append( + SkyroomCredentials(workshop_registration.username, workshop_registration.password, + workshop_registration.user.account.email)) + return convert_credentials_to_csv_response(user_credentials) + + +class MiscAdmin(admin.ModelAdmin): + list_display = ('__str__', 'year') + + class Meta: + model = models.Misc + fields = '__all__' + + admin.site.register(models.Teacher, TeacherAdmin) admin.site.register(models.Presenter, PresenterAdmin) admin.site.register(models.User, UserAdmin) @@ -141,6 +170,6 @@ class Meta: admin.site.register(models.Committee) admin.site.register(models.FieldOfInterest) admin.site.register(models.Staff) -admin.site.register(models.Workshop, desc_creator(models.Workshop)) -admin.site.register(models.Presentation, desc_creator(models.Presentation)) -admin.site.register(models.Misc, desc_creator(models.Misc)) +admin.site.register(models.Workshop, WorkshopAdmin) +admin.site.register(models.Presentation, PresentationAdmin) +admin.site.register(models.Misc, MiscAdmin) diff --git a/backend/backend_api/migrations/0057_make_passwords_random.py b/backend/backend_api/migrations/0057_make_passwords_random.py new file mode 100644 index 0000000..1b4d256 --- /dev/null +++ b/backend/backend_api/migrations/0057_make_passwords_random.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.4 on 2023-12-05 21:26 + +from django.db import migrations + +from utils.random import create_random_string + + +def make_passwords_random(apps, schema_editor): + WorkshopRegistration = apps.get_model('backend_api', 'WorkshopRegistration') + PresentationParticipation = apps.get_model('backend_api', 'PresentationParticipation') + for registration in WorkshopRegistration.objects.all(): + registration.password = create_random_string(16) + registration.save() + for participation in PresentationParticipation.objects.all(): + participation.password = create_random_string(16) + participation.save() + + +class Migration(migrations.Migration): + dependencies = [ + ('backend_api', '0056_presentationparticipation_password_and_more'), + ] + + operations = [ + migrations.RunPython(make_passwords_random) + ] diff --git a/backend/backend_api/models.py b/backend/backend_api/models.py index d14ed6f..22ac4e7 100644 --- a/backend/backend_api/models.py +++ b/backend/backend_api/models.py @@ -1,5 +1,6 @@ import datetime import uuid +from urllib.parse import quote from urllib.parse import urljoin from django.contrib.auth.models import AbstractBaseUser @@ -10,10 +11,10 @@ from django.template.loader import render_to_string from django.urls import reverse from django.utils import timezone +from django.utils.html import escape from django.utils.translation import gettext_lazy as _ -from rest_framework.exceptions import ValidationError from rest_framework import status -from django.utils.html import escape +from rest_framework.exceptions import ValidationError from aaiss_backend import settings from aaiss_backend.settings import BASE_URL @@ -21,7 +22,6 @@ from backend_api.email import MailerThread from utils.random import create_random_string from utils.renderers import new_detailed_response -from urllib.parse import quote SMALL_MAX_LENGTH = 255 BIG_MAX_LENGTH = 65535 diff --git a/backend/requirements.txt b/backend/requirements.txt index d1a0766..719333d 100644 Binary files a/backend/requirements.txt and b/backend/requirements.txt differ diff --git a/backend/templates/html/AAISS_Info.html b/backend/templates/html/AAISS_Info.html deleted file mode 100644 index 1a93096..0000000 --- a/backend/templates/html/AAISS_Info.html +++ /dev/null @@ -1,412 +0,0 @@ - - - -
- - - - - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
-