Skip to content

Commit

Permalink
feat(backend): add room_name on exporting login credentials (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adibov authored Dec 6, 2023
1 parent 19e2707 commit a26e93e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/aaiss_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@
#ZIFY
ZIFY_AUTH = env.str("ZIFY_AUTH", "")

SKYROOM_URL = env.str("SKYROOM_URL", "https://www.skyroom.online/ch/aut_ceit_ssc/aaiss")
SKYROOM_BASE_URL = env.str("SKYROOM_URL", "https://www.skyroom.online/ch/aut_ceit_ssc")
21 changes: 16 additions & 5 deletions backend/backend_api/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django import forms
from django.contrib import admin
from django.template.loader import render_to_string
from django.contrib.admin.helpers import ActionForm

from aaiss_backend.settings import SKYROOM_URL
from aaiss_backend.settings import SKYROOM_BASE_URL
from backend_api import models
from backend_api.email import MailerThread
from backend_api.models import Discount, Presentation, PresentationParticipation, WorkshopRegistration
Expand Down Expand Up @@ -67,9 +68,14 @@ class Meta:


class PresentationAdmin(admin.ModelAdmin):
class PresentationForm(ActionForm):
_CHOISES = (('aaiss', 'aaiss'), ('aaiss2', 'aaiss2'))
room_name = forms.ChoiceField(choices=_CHOISES, required=True)

list_display = ('__str__', 'level', 'no_of_participants', 'year')
readonly_fields = ('participants',)
actions = ['export_login_credentials', 'send_registration_emails']
action_form = PresentationForm

class Meta:
model = Presentation
Expand All @@ -83,7 +89,7 @@ def export_login_credentials(self, request, obj):
status=PresentationParticipation.StatusChoices.PURCHASED):
user_credentials.append(
SkyroomCredentials(registration.username, registration.password,
registration.user.name))
registration.user.name, request.POST['room_name']))
return convert_credentials_to_csv_response(user_credentials)

@admin.action(description='Send registration emails')
Expand All @@ -97,16 +103,21 @@ def send_registration_emails(self, request, obj):
{
'username': registration.username,
'password': registration.password,
'meeting_url': SKYROOM_URL,
'meeting_url': SKYROOM_BASE_URL + '/' + request.POST['room_name'],
'meeting_type': 'presentation',
'meeting_title': presentation.name,
})).start()


class WorkshopAdmin(admin.ModelAdmin):
class WorkshopForm(ActionForm):
_CHOISES = (('aaiss', 'aaiss'), ('aaiss2', 'aaiss2'))
room_name = forms.ChoiceField(choices=_CHOISES, required=True)

list_display = ('__str__', 'capacity', 'cost', 'has_project', 'level', 'no_of_participants', 'year')
readonly_fields = ('participants',)
actions = ['export_login_credentials', 'send_registration_emails']
action_form = WorkshopForm

class Meta:
model = models.Workshop
Expand All @@ -120,7 +131,7 @@ def export_login_credentials(self, request, obj):
status=WorkshopRegistration.StatusChoices.PURCHASED):
user_credentials.append(
SkyroomCredentials(registration.username, registration.password,
registration.user.name))
registration.user.name, request.POST['room_name']))
return convert_credentials_to_csv_response(user_credentials)

@admin.action(description='Send registration emails')
Expand All @@ -134,7 +145,7 @@ def send_registration_emails(self, request, obj):
{
'username': registration.username,
'password': registration.password,
'meeting_url': SKYROOM_URL,
'meeting_url': SKYROOM_BASE_URL + '/' + request.POST['room_name'],
'meeting_type': 'workshop',
'meeting_title': workshop.name,
})).start()
Expand Down
4 changes: 3 additions & 1 deletion backend/utils/skyroom_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class SkyroomCredentials:
username: str
password: str
full_name: str
room_name: str


def convert_credentials_to_csv_response(credentials: list[SkyroomCredentials]) -> HttpResponse:
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="login_credentials.csv"'
writer = csv.writer(response)
for credential in credentials:
writer.writerow([credential.username, credential.password, credential.full_name, 'aaiss', 'normal'])
writer.writerow(
[credential.username, credential.password, credential.full_name, credential.room_name, 'normal'])
return response

0 comments on commit a26e93e

Please sign in to comment.