From 8cdec466f11c06b8f09668435b7f9b0ef061c06e Mon Sep 17 00:00:00 2001 From: Stefan Kairinos <118008817+SKairinos@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:26:13 +0000 Subject: [PATCH 1/2] fix: school.country is optional (#2228) --- .../migrations/0046_alter_school_country.py | 19 +++++++++++++++++++ cfl_common/common/models.py | 2 +- portal/forms/organisation.py | 7 +++++-- portal/views/organisation.py | 7 +++---- portal/views/teacher/dashboard.py | 5 +++-- 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 cfl_common/common/migrations/0046_alter_school_country.py diff --git a/cfl_common/common/migrations/0046_alter_school_country.py b/cfl_common/common/migrations/0046_alter_school_country.py new file mode 100644 index 000000000..c743c2cee --- /dev/null +++ b/cfl_common/common/migrations/0046_alter_school_country.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.20 on 2023-11-06 16:04 + +from django.db import migrations +import django_countries.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0045_otp'), + ] + + operations = [ + migrations.AlterField( + model_name='school', + name='country', + field=django_countries.fields.CountryField(blank=True, max_length=2, null=True), + ), + ] diff --git a/cfl_common/common/models.py b/cfl_common/common/models.py index 62e88e3ef..ebfa30f99 100644 --- a/cfl_common/common/models.py +++ b/cfl_common/common/models.py @@ -42,7 +42,7 @@ def get_queryset(self): class School(models.Model): name = models.CharField(max_length=200) postcode = models.CharField(max_length=10, null=True) - country = CountryField(blank_label="(select country)") + country = CountryField(blank_label="(select country)", null=True, blank=True) # TODO: Create an Address model to house address details county = models.CharField(max_length=50, blank=True, null=True) creation_time = models.DateTimeField(default=timezone.now, null=True) diff --git a/portal/forms/organisation.py b/portal/forms/organisation.py index efcb85fb3..fea2fc740 100644 --- a/portal/forms/organisation.py +++ b/portal/forms/organisation.py @@ -9,7 +9,6 @@ class OrganisationForm(forms.ModelForm): class Meta(object): - model = School fields = ["name", "postcode", "country"] widgets = { @@ -17,7 +16,11 @@ class Meta(object): "postcode": forms.TextInput(attrs={"autocomplete": "off", "placeholder": "Postcode / Zipcode"}), "country": CountrySelectWidget(layout="{widget}"), } - help_texts = {"name": "Name of school or club", "postcode": "Postcode / Zipcode", "country": "Country"} + help_texts = { + "name": "Name of school or club", + "postcode": "Postcode / Zipcode", + "country": "Country (optional)", + } def __init__(self, *args, **kwargs): self.user = kwargs.pop("user", None) diff --git a/portal/views/organisation.py b/portal/views/organisation.py index d369a2bce..79bbce9f1 100644 --- a/portal/views/organisation.py +++ b/portal/views/organisation.py @@ -1,9 +1,9 @@ import common.permissions as permissions -from common.models import School, Teacher, Class +from common.models import Class, School, Teacher from django.contrib import messages as messages from django.contrib.auth.decorators import login_required, user_passes_test from django.http import Http404, HttpResponseRedirect -from django.shortcuts import render, get_object_or_404 +from django.shortcuts import get_object_or_404, render from django.urls import reverse_lazy from portal.forms.organisation import OrganisationForm @@ -12,7 +12,6 @@ @login_required(login_url=reverse_lazy("teacher_login")) @user_passes_test(permissions.logged_in_as_teacher, login_url=reverse_lazy("teacher_login")) def organisation_create(request): - teacher = request.user.new_teacher create_form = OrganisationForm(user=request.user) @@ -23,7 +22,7 @@ def organisation_create(request): data = create_form.cleaned_data name = data.get("name", "") postcode = data.get("postcode", "").upper() - country = data.get("country", "") + country = data.get("country") school = School.objects.create(name=name, postcode=postcode, country=country) diff --git a/portal/views/teacher/dashboard.py b/portal/views/teacher/dashboard.py index d515da90a..b28b98217 100644 --- a/portal/views/teacher/dashboard.py +++ b/portal/views/teacher/dashboard.py @@ -13,7 +13,7 @@ ) from common.helpers.generators import get_random_username from common.models import Class, JoinReleaseStudent, SchoolTeacherInvitation, Student, Teacher -from common.permissions import logged_in_as_teacher, check_teacher_authorised +from common.permissions import check_teacher_authorised, logged_in_as_teacher from common.utils import using_two_factor from django.contrib import messages as messages from django.contrib.auth import logout @@ -44,6 +44,7 @@ RATELIMIT_METHOD, clear_ratelimit_cache_for_user, ) + from .teach import create_class @@ -259,7 +260,7 @@ def process_update_school_form(request, school, old_anchor): data = update_school_form.cleaned_data name = data.get("name", "") postcode = data.get("postcode", "") - country = data.get("country", "") + country = data.get("country") county = school.county school.name = name From 4267193007bedd26e9d3d0a123350a569246df8b Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 6 Nov 2023 16:29:04 +0000 Subject: [PATCH 2/2] 6.38.2 Automatically generated by python-semantic-release --- portal/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal/__init__.py b/portal/__init__.py index a4e66d390..ab1f2c1dc 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1 +1 @@ -__version__ = "6.38.1" +__version__ = "6.38.2"