Skip to content

Commit

Permalink
Use update
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Sep 6, 2023
1 parent ca52645 commit aebf67f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 78 deletions.
130 changes: 65 additions & 65 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions cfl_common/common/migrations/0042_totalactivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
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")),
("registrations", models.PositiveIntegerField(default=0)),
],
options={"verbose_name_plural": "Total activity"},
),
]
9 changes: 3 additions & 6 deletions portal/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import F
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect, render
from django.urls import reverse, reverse_lazy
Expand Down Expand Up @@ -154,9 +155,7 @@ def process_signup_form(request, data):

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

total_activity = TotalActivity.objects.get(id=1)
total_activity.registrations += 1
total_activity.save()
TotalActivity.objects.update(registrations=F("registrations") + 1)

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

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

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

total_activity = TotalActivity.objects.get(id=1)
total_activity.registrations += 1
total_activity.save()
TotalActivity.objects.update(registrations=F("registrations") + 1)

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

Expand Down
5 changes: 2 additions & 3 deletions portal/views/teacher/teach.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.contrib.staticfiles.storage import staticfiles_storage
from django.db.models import F
from django.forms.formsets import formset_factory
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
Expand Down Expand Up @@ -124,9 +125,7 @@ def process_edit_class(request, access_code, onboarding_done, next_url):
klass=klass, name=name, password=password, login_id=hashed_login_id
)

total_activity = TotalActivity.objects.get(id=1)
total_activity.registrations += 1
total_activity.save()
TotalActivity.objects.update(registrations=F("registrations") + 1)

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

0 comments on commit aebf67f

Please sign in to comment.