Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: school.country is optional #2228

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cfl_common/common/migrations/0046_alter_school_country.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 1 addition & 1 deletion cfl_common/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions portal/forms/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@

class OrganisationForm(forms.ModelForm):
class Meta(object):

model = School
fields = ["name", "postcode", "country"]
widgets = {
"name": forms.TextInput(attrs={"autocomplete": "off", "placeholder": "Name of school or club"}),
"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)
Expand Down
7 changes: 3 additions & 4 deletions portal/views/organisation.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions portal/views/teacher/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,6 +44,7 @@
RATELIMIT_METHOD,
clear_ratelimit_cache_for_user,
)

from .teach import create_class


Expand Down Expand Up @@ -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
Expand Down