Turn debug off
This commit is contained in:
parent
76ef47caaf
commit
12e6edc3dc
6 changed files with 66 additions and 7 deletions
|
|
@ -9,10 +9,8 @@ SECRET_KEY = os.environ.get('SECRET_KEY')
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
'45.79.52.230',
|
|
||||||
'housewars.c4thebomb101.com',
|
'housewars.c4thebomb101.com',
|
||||||
'csmb-housewars.herokuapp.com',
|
'csmb-housewars.herokuapp.com',
|
||||||
'*'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = [
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from housewars.models import House
|
||||||
@admin.register(House)
|
@admin.register(House)
|
||||||
class HouseAdmin(admin.ModelAdmin):
|
class HouseAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'points', 'current_points', 'total_points')
|
list_display = ('name', 'points', 'current_points', 'total_points')
|
||||||
actions = ['finalize_points']
|
|
||||||
|
|
||||||
@admin.display(description='Current Housewars Points')
|
@admin.display(description='Current Housewars Points')
|
||||||
def current_points(self, obj):
|
def current_points(self, obj):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.db.models import F
|
||||||
|
|
||||||
from housewars.models import Teacher
|
import io
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
from housewars.utils import load_pdf
|
||||||
|
from housewars.models import Teacher, UserEntry
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Teacher)
|
@admin.register(Teacher)
|
||||||
|
|
@ -13,3 +19,37 @@ class TeacherAdmin(admin.ModelAdmin):
|
||||||
]
|
]
|
||||||
|
|
||||||
list_display = ('first_name', 'last_name', 'house', 'grade', 'activity')
|
list_display = ('first_name', 'last_name', 'house', 'grade', 'activity')
|
||||||
|
|
||||||
|
actions = ['generate_passwords', 'export_mentor_to_pdf']
|
||||||
|
|
||||||
|
@admin.action(description='Export mentor to pdf')
|
||||||
|
def export_mentor_to_pdf(self, request, queryset):
|
||||||
|
file_list = {}
|
||||||
|
|
||||||
|
for teacher in queryset:
|
||||||
|
user_entries = UserEntry.objects.filter(
|
||||||
|
grade=teacher.grade, house=teacher.house)
|
||||||
|
|
||||||
|
# Augment the queryset with extra data
|
||||||
|
user_entries = user_entries.annotate(
|
||||||
|
a1_room=F('activity1__room_number')).annotate(a2_room=F('activity2__room_number'))
|
||||||
|
|
||||||
|
# Select headers that are to be unpacked
|
||||||
|
headers = ['first_name', 'last_name', 'grade', 'house',
|
||||||
|
'activity1', 'a1_room', 'activity2', 'a2_room']
|
||||||
|
|
||||||
|
file = load_pdf(user_entries, headers)
|
||||||
|
|
||||||
|
file_list[f"{teacher.last_name}, {teacher.first_name}"] = file
|
||||||
|
|
||||||
|
outfile = io.BytesIO()
|
||||||
|
with zipfile.ZipFile(outfile, 'w') as zf:
|
||||||
|
for name, file in file_list.items():
|
||||||
|
zf.writestr(f"{name}.pdf", file.getvalue())
|
||||||
|
outfile = outfile.getvalue()
|
||||||
|
|
||||||
|
response = HttpResponse(
|
||||||
|
outfile, content_type='application/octet-stream')
|
||||||
|
response['Content-Disposition'] = 'attachment; filename=mentor.zip'
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
|
||||||
18
housewars/migrations/0009_alter_activity_room_number.py
Normal file
18
housewars/migrations/0009_alter_activity_room_number.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.0.4 on 2023-05-16 03:39
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('housewars', '0008_merge_20220907_2259'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='activity',
|
||||||
|
name='room_number',
|
||||||
|
field=models.CharField(blank=True, default=None, max_length=100, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -13,7 +13,8 @@ class Activity(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
default_quota = models.IntegerField(default=0)
|
default_quota = models.IntegerField(default=0)
|
||||||
time = models.IntegerField(choices=TimeslotChoices)
|
time = models.IntegerField(choices=TimeslotChoices)
|
||||||
room_number = models.IntegerField(blank=True, null=True, default=None)
|
room_number = models.CharField(
|
||||||
|
max_length=100, blank=True, null=True, default=None)
|
||||||
password = models.CharField(
|
password = models.CharField(
|
||||||
max_length=100, blank=True, null=True, default=None)
|
max_length=100, blank=True, null=True, default=None)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,15 @@ class EntryCreateView(SessionWizardView):
|
||||||
UserEntry.objects.create(**cleaned_data)
|
UserEntry.objects.create(**cleaned_data)
|
||||||
|
|
||||||
activity1 = cleaned_data['activity1']
|
activity1 = cleaned_data['activity1']
|
||||||
activity1_room = activity1.room_number
|
|
||||||
activity2 = cleaned_data['activity2']
|
activity2 = cleaned_data['activity2']
|
||||||
activity2_room = activity2.room_number
|
|
||||||
|
|
||||||
# Build the response string.
|
# Build the response string.
|
||||||
a1_string = f'You are in {activity1}'
|
a1_string = f'You are in {activity1}'
|
||||||
|
activity1_room = activity1.room_number
|
||||||
|
|
||||||
if (activity1_room != None):
|
if (activity1_room != None):
|
||||||
a1_string += f' in Room {activity1_room}'
|
a1_string += f' in Room {activity1_room}'
|
||||||
|
|
||||||
if (hasattr(activity1, 'teacher')):
|
if (hasattr(activity1, 'teacher')):
|
||||||
activity1_teacher = activity1.teacher
|
activity1_teacher = activity1.teacher
|
||||||
a1_string += f' with {activity1_teacher}.'
|
a1_string += f' with {activity1_teacher}.'
|
||||||
|
|
@ -67,6 +68,8 @@ class EntryCreateView(SessionWizardView):
|
||||||
a2_string = ''
|
a2_string = ''
|
||||||
if (activity2 != None):
|
if (activity2 != None):
|
||||||
a2_string = f'You are in {activity2}'
|
a2_string = f'You are in {activity2}'
|
||||||
|
|
||||||
|
activity2_room = activity2.room_number
|
||||||
if (activity2_room != None):
|
if (activity2_room != None):
|
||||||
a2_string += f' in Room {activity2_room}'
|
a2_string += f' in Room {activity2_room}'
|
||||||
if (hasattr(activity2, 'teacher')):
|
if (hasattr(activity2, 'teacher')):
|
||||||
|
|
|
||||||
Reference in a new issue