Skip to content

Commit

Permalink
Include registration types
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Sep 7, 2023
1 parent aebf67f commit 0db1814
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
16 changes: 10 additions & 6 deletions cfl_common/common/migrations/0042_totalactivity.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Generated by Django 3.2.20 on 2023-09-05 15:07
# Generated by Django 3.2.20 on 2023-09-07 01:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("common", "0041_populate_gb_counties"),
('common', '0041_populate_gb_counties'),
]

operations = [
migrations.CreateModel(
name="TotalActivity",
name='TotalActivity',
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("registrations", models.PositiveIntegerField(default=0)),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('teacher_registrations', models.PositiveIntegerField(default=0)),
('student_registrations', models.PositiveIntegerField(default=0)),
('independent_registrations', models.PositiveIntegerField(default=0)),
],
options={"verbose_name_plural": "Total activity"},
options={
'verbose_name_plural': 'Total activity',
},
),
]
15 changes: 9 additions & 6 deletions cfl_common/common/migrations/0043_add_total_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ def add_total_activity(apps, schema_editor):
Initialises it with the total number of registrations at the time of the migration.
"""
TotalActivity = apps.get_model("common", "TotalActivity")
User = apps.get_model("auth", "User")
TotalActivity.objects.create(registrations=User.objects.all().count())
Teacher = apps.get_model("common", "Teacher")
Student = apps.get_model("common", "Student")
TotalActivity.objects.create(
teacher_registrations=Teacher.objects.all().count(),
student_registrations=Student.objects.filter(class_field__isnull=False).count(),
independent_registrations=Student.objects.filter(class_field__isnull=True).count(),
)


def remove_total_activity(apps, schema_editor):
Expand All @@ -19,9 +24,7 @@ def remove_total_activity(apps, schema_editor):
class Migration(migrations.Migration):

dependencies = [
('common', '0042_totalactivity'),
("common", "0042_totalactivity"),
]

operations = [
migrations.RunPython(add_total_activity, remove_total_activity)
]
operations = [migrations.RunPython(add_total_activity, remove_total_activity)]
4 changes: 3 additions & 1 deletion cfl_common/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ class TotalActivity(models.Model):
An example of this is total ever registrations.
"""

registrations = models.PositiveIntegerField(default=0)
teacher_registrations = models.PositiveIntegerField(default=0)
student_registrations = models.PositiveIntegerField(default=0)
independent_registrations = models.PositiveIntegerField(default=0)

class Meta:
verbose_name_plural = "Total activity"
Expand Down
10 changes: 6 additions & 4 deletions portal/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ def test_registrations_increment_data(self):
c = Client()

total_activity = TotalActivity.objects.get(id=1)
registration_count = total_activity.registrations
teacher_registration_count = total_activity.teacher_registrations
student_registration_count = total_activity.student_registrations
independent_registration_count = total_activity.independent_registrations

response = c.post(
reverse("register"),
Expand All @@ -733,7 +735,7 @@ def test_registrations_increment_data(self):

total_activity = TotalActivity.objects.get(id=1)

assert total_activity.registrations == registration_count + 1
assert total_activity.teacher_registrations == teacher_registration_count + 1

response = c.post(
reverse("register"),
Expand All @@ -754,7 +756,7 @@ def test_registrations_increment_data(self):

total_activity = TotalActivity.objects.get(id=1)

assert total_activity.registrations == registration_count + 2
assert total_activity.independent_registrations == independent_registration_count + 1

teacher_email, teacher_password = signup_teacher_directly()
create_organisation_directly(teacher_email)
Expand All @@ -767,7 +769,7 @@ def test_registrations_increment_data(self):

total_activity = TotalActivity.objects.get(id=1)

assert total_activity.registrations == registration_count + 5
assert total_activity.student_registrations == student_registration_count + 3


# CRON view tests
Expand Down
4 changes: 2 additions & 2 deletions portal/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def process_signup_form(request, data):

send_verification_email(request, teacher.user.user, data)

TotalActivity.objects.update(registrations=F("registrations") + 1)
TotalActivity.objects.update(teacher_registrations=F("teacher_registrations") + 1)

return render(request, "portal/email_verification_needed.html", {"usertype": "TEACHER"}, status=302)

Expand Down Expand Up @@ -195,7 +195,7 @@ def process_independent_student_signup_form(request, data):

send_verification_email(request, student.new_user, data, age=age)

TotalActivity.objects.update(registrations=F("registrations") + 1)
TotalActivity.objects.update(independent_registrations=F("independent_registrations") + 1)

return render(request, "portal/email_verification_needed.html", {"usertype": "INDEP_STUDENT"}, status=302)

Expand Down
2 changes: 1 addition & 1 deletion portal/views/teacher/teach.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def process_edit_class(request, access_code, onboarding_done, next_url):
klass=klass, name=name, password=password, login_id=hashed_login_id
)

TotalActivity.objects.update(registrations=F("registrations") + 1)
TotalActivity.objects.update(student_registrations=F("student_registrations") + 1)

login_url = generate_student_url(request, new_student, login_id)
students_info.append(
Expand Down

0 comments on commit 0db1814

Please sign in to comment.