def process_update_school_form(request, school, old_anchor): update_school_form = OrganisationForm(request.POST, user=request.user, current_school=school) if update_school_form.is_valid(): data = update_school_form.cleaned_data name = data.get("name", "") postcode = data.get("postcode", "") country = data.get("country", "") school.name = name school.postcode = postcode school.country = country error, country, town, lat, lng = lookup_coord(postcode, country) school.town = town school.latitude = lat school.longitude = lng school.save() anchor = "#" messages.success( request, "You have updated the details for your school or club successfully.", ) else: anchor = old_anchor return anchor
def organisation_create(request): increment_count = False limits = getattr(request, 'limits', {'ip': [0]}) captcha_limit = 5 using_captcha = (limits['ip'][0] > captcha_limit) should_use_captcha = (limits['ip'][0] >= captcha_limit) OrganisationJoinFormWithCaptcha = partial(create_form_subclass_with_recaptcha(OrganisationJoinForm, recaptcha_client), request) InputOrganisationJoinForm = compute_input_join_form(OrganisationJoinFormWithCaptcha, OrganisationJoinForm, using_captcha) OutputOrganisationJoinForm = compute_output_join_form(OrganisationJoinFormWithCaptcha, OrganisationJoinForm, should_use_captcha) teacher = request.user.new_teacher create_form = OrganisationForm(user=request.user) join_form = OutputOrganisationJoinForm() if request.method == 'POST': if 'create_organisation' in request.POST: create_form = OrganisationForm(request.POST, user=request.user) if create_form.is_valid(): data = create_form.cleaned_data name = data.get('name', '') postcode = data.get('postcode', '').upper() country = data.get('country', '') error, town, lat, lng = '', '0', '0', '0' # lookup_coord(postcode, country) school = School.objects.create( name=name, postcode=postcode, town=town, latitude=lat, longitude=lng, country=country ) teacher.school = school teacher.is_admin = True teacher.save() messages.success(request, "The school or club '" + teacher.school.name + "' has been successfully added.") return HttpResponseRedirect(reverse_lazy('onboarding-classes')) elif 'join_organisation' in request.POST: increment_count = True process_join_form(request, teacher, InputOrganisationJoinForm, OutputOrganisationJoinForm) else: return process_revoke_request(request, teacher) res = render(request, 'portal/teach/onboarding_school.html', { 'create_form': create_form, 'join_form': join_form, 'teacher': teacher, }) res.count = increment_count return res
def organisation_create(request): teacher = request.user.new_teacher create_form = OrganisationForm(user=request.user) join_form = OrganisationJoinForm() if request.method == "POST": if "create_organisation" in request.POST: create_form = OrganisationForm(request.POST, user=request.user) if create_form.is_valid(): data = create_form.cleaned_data name = data.get("name", "") postcode = data.get("postcode", "").upper() country = data.get("country", "") error, town, lat, lng = ( "", "0", "0", "0", ) # lookup_coord(postcode, country) school = School.objects.create( name=name, postcode=postcode, town=town, latitude=lat, longitude=lng, country=country, ) teacher.school = school teacher.is_admin = True teacher.save() messages.success( request, "The school or club '" + teacher.school.name + "' has been successfully added.", ) return HttpResponseRedirect(reverse_lazy("onboarding-classes")) elif "join_organisation" in request.POST: process_join_form( request, teacher, OrganisationJoinForm, OrganisationJoinForm ) else: return process_revoke_request(request, teacher) res = render( request, "portal/teach/onboarding_school.html", {"create_form": create_form, "join_form": join_form, "teacher": teacher}, ) return res
def process_update_school_form(request, school, old_anchor): update_school_form = OrganisationForm( request.POST, user=request.user, current_school=school ) if update_school_form.is_valid(): data = update_school_form.cleaned_data name = data.get("name", "") postcode = data.get("postcode", "") country = data.get("country", "") school.name = name school.postcode = postcode school.country = country error, country, town, lat, lng = lookup_coord(postcode, country) school.town = town school.latitude = lat school.longitude = lng school.save() anchor = "#" messages.success( request, "You have updated the details for your school or club successfully.", ) else: anchor = old_anchor return anchor
def organisation_create(request): increment_count = False teacher = request.user.new_teacher create_form = OrganisationForm(user=request.user) join_form = OrganisationJoinForm() if request.method == 'POST': if 'create_organisation' in request.POST: create_form = OrganisationForm(request.POST, user=request.user) if create_form.is_valid(): data = create_form.cleaned_data name = data.get('name', '') postcode = data.get('postcode', '').upper() country = data.get('country', '') error, town, lat, lng = '', '0', '0', '0' # lookup_coord(postcode, country) school = School.objects.create(name=name, postcode=postcode, town=town, latitude=lat, longitude=lng, country=country) teacher.school = school teacher.is_admin = True teacher.save() messages.success( request, "The school or club '" + teacher.school.name + "' has been successfully added.") return HttpResponseRedirect(reverse_lazy('onboarding-classes')) elif 'join_organisation' in request.POST: increment_count = True process_join_form(request, teacher, OrganisationJoinForm, OrganisationJoinForm) else: return process_revoke_request(request, teacher) res = render(request, 'portal/teach/onboarding_school.html', { 'create_form': create_form, 'join_form': join_form, 'teacher': teacher, }) res.count = increment_count return res
def organisation_teacher_view(request, is_admin): teacher = request.user.userprofile.teacher school = teacher.school coworkers = Teacher.objects.filter(school=school).order_by( 'user__user__last_name', 'user__user__first_name') join_requests = Teacher.objects.filter( pending_join_request=school).order_by('user__user__last_name', 'user__user__first_name') form = OrganisationForm(user=request.user, current_school=school) form.fields['name'].initial = school.name form.fields['postcode'].initial = school.postcode form.fields['country'].initial = school.country if request.method == 'POST' and is_admin: form = OrganisationForm(request.POST, user=request.user, current_school=school) if form.is_valid(): data = form.cleaned_data name = data.get('name', '') postcode = data.get('postcode', '') country = data.get('country', '') school.name = name school.postcode = postcode school.country = country error, country, town, lat, lng = lookup_coord(postcode, country) school.town = town school.latitude = lat school.longitude = lng school.save() messages.success( request, 'You have updated the details for your school or club successfully.' ) return render( request, 'portal/teach/organisation_manage.html', { 'teacher': teacher, 'is_admin': is_admin, 'coworkers': coworkers, 'join_requests': join_requests, 'form': form, })
def organisation_teacher_view(request, is_admin): teacher = request.user.userprofile.teacher school = teacher.school coworkers = Teacher.objects.filter(school=school).order_by('user__user__last_name', 'user__user__first_name') join_requests = Teacher.objects.filter(pending_join_request=school).order_by('user__user__last_name', 'user__user__first_name') form = OrganisationForm(user=request.user, current_school=school) form.fields['name'].initial = school.name form.fields['postcode'].initial = school.postcode form.fields['country'].initial = school.country if request.method == 'POST' and is_admin: form = OrganisationForm(request.POST, user=request.user, current_school=school) if form.is_valid(): data = form.cleaned_data name = data.get('name', '') postcode = data.get('postcode', '') country = data.get('country', '') school.name = name school.postcode = postcode school.country = country error, country, town, lat, lng = lookup_coord(postcode, country) school.town = town school.latitude = lat school.longitude = lng school.save() messages.success(request, 'You have updated the details for your school or club successfully.') return render(request, 'portal/teach/organisation_manage.html', { 'teacher': teacher, 'is_admin': is_admin, 'coworkers': coworkers, 'join_requests': join_requests, 'form': form, })
def process_update_school_form(request, school): update_school_form = OrganisationForm(request.POST, user=request.user, current_school=school) if update_school_form.is_valid(): data = update_school_form.cleaned_data name = data.get('name', '') postcode = data.get('postcode', '') country = data.get('country', '') school.name = name school.postcode = postcode school.country = country error, country, town, lat, lng = lookup_coord(postcode, country) school.town = town school.latitude = lat school.longitude = lng school.save() messages.success( request, 'You have updated the details for your school or club successfully.' )
def organisation_create(request): increment_count = False teacher = request.user.new_teacher create_form = OrganisationForm(user=request.user) join_form = OrganisationJoinForm() if request.method == "POST": if "create_organisation" in request.POST: create_form = OrganisationForm(request.POST, user=request.user) if create_form.is_valid(): data = create_form.cleaned_data name = data.get("name", "") postcode = data.get("postcode", "").upper() country = data.get("country", "") error, town, lat, lng = ( "", "0", "0", "0", ) # lookup_coord(postcode, country) school = School.objects.create( name=name, postcode=postcode, town=town, latitude=lat, longitude=lng, country=country, ) teacher.school = school teacher.is_admin = True teacher.save() messages.success( request, "The school or club '" + teacher.school.name + "' has been successfully added.", ) return HttpResponseRedirect(reverse_lazy("onboarding-classes")) elif "join_organisation" in request.POST: increment_count = True process_join_form( request, teacher, OrganisationJoinForm, OrganisationJoinForm ) else: return process_revoke_request(request, teacher) res = render( request, "portal/teach/onboarding_school.html", {"create_form": create_form, "join_form": join_form, "teacher": teacher}, ) res.count = increment_count return res
def organisation_create(request): increment_count = False limits = getattr(request, 'limits', { 'ip': [0] }) captcha_limit = 5 using_captcha = (limits['ip'][0] > captcha_limit) should_use_captcha = (limits['ip'][0] >= captcha_limit) OrganisationJoinFormWithCaptcha = partial(create_form_subclass_with_recaptcha(OrganisationJoinForm, recaptcha_client), request) InputOrganisationJoinForm = OrganisationJoinFormWithCaptcha if using_captcha else OrganisationJoinForm OutputOrganisationJoinForm = OrganisationJoinFormWithCaptcha if should_use_captcha else OrganisationJoinForm teacher = request.user.userprofile.teacher create_form = OrganisationForm(user=request.user) join_form = OutputOrganisationJoinForm() if request.method == 'POST': if 'create_organisation' in request.POST: create_form = OrganisationForm(request.POST, user=request.user) if create_form.is_valid(): data = create_form.cleaned_data name = data.get('name', '') postcode = data.get('postcode', '') country = data.get('country', '') error, town, lat, lng = '', '0', '0', '0' #lookup_coord(postcode, country) school = School.objects.create( name=name, postcode=postcode, town = town, latitude = lat, longitude = lng, country=country) teacher.school = school teacher.is_admin = True teacher.save() messages.success(request, "The school or club '" + teacher.school.name + "' has been successfully added.") return HttpResponseRedirect(reverse_lazy('teacher_home')) elif 'join_organisation' in request.POST: increment_count = True join_form = InputOrganisationJoinForm(request.POST) if join_form.is_valid(): school = get_object_or_404(School, id=join_form.cleaned_data['chosen_org']) teacher.pending_join_request = school teacher.save() emailMessage = emailMessages.joinRequestPendingEmail(request, teacher.user.user.email) for admin in Teacher.objects.filter(school=school, is_admin=True): send_email(NOTIFICATION_EMAIL, [admin.user.user.email], emailMessage['subject'], emailMessage['message']) emailMessage = emailMessages.joinRequestSentEmail(request, school.name) send_email(NOTIFICATION_EMAIL, [teacher.user.user.email], emailMessage['subject'], emailMessage['message']) messages.success(request, 'Your request to join the school or club has been sent successfully.') else: join_form = OutputOrganisationJoinForm(request.POST) elif 'revoke_join_request' in request.POST: teacher.pending_join_request = None teacher.save() messages.success(request, 'Your request to join the school or club has been revoked successfully.') res = render(request, 'portal/teach/organisation_create.html', { 'create_form': create_form, 'join_form': join_form, 'teacher': teacher, }) res.count = increment_count return res
def organisation_create(request): increment_count = False limits = getattr(request, 'limits', {'ip': [0]}) captcha_limit = 5 using_captcha = (limits['ip'][0] > captcha_limit) should_use_captcha = (limits['ip'][0] >= captcha_limit) OrganisationJoinFormWithCaptcha = partial( create_form_subclass_with_recaptcha(OrganisationJoinForm, recaptcha_client), request) InputOrganisationJoinForm = OrganisationJoinFormWithCaptcha if using_captcha else OrganisationJoinForm OutputOrganisationJoinForm = OrganisationJoinFormWithCaptcha if should_use_captcha else OrganisationJoinForm teacher = request.user.userprofile.teacher create_form = OrganisationForm(user=request.user) join_form = OutputOrganisationJoinForm() if request.method == 'POST': if 'create_organisation' in request.POST: create_form = OrganisationForm(request.POST, user=request.user) if create_form.is_valid(): data = create_form.cleaned_data name = data.get('name', '') postcode = data.get('postcode', '') country = data.get('country', '') error, town, lat, lng = '', '0', '0', '0' #lookup_coord(postcode, country) school = School.objects.create(name=name, postcode=postcode, town=town, latitude=lat, longitude=lng, country=country) teacher.school = school teacher.is_admin = True teacher.save() messages.success( request, "The school or club '" + teacher.school.name + "' has been successfully added.") return HttpResponseRedirect(reverse_lazy('teacher_home')) elif 'join_organisation' in request.POST: increment_count = True join_form = InputOrganisationJoinForm(request.POST) if join_form.is_valid(): school = get_object_or_404( School, id=join_form.cleaned_data['chosen_org']) teacher.pending_join_request = school teacher.save() emailMessage = emailMessages.joinRequestPendingEmail( request, teacher.user.user.email) for admin in Teacher.objects.filter(school=school, is_admin=True): send_email(NOTIFICATION_EMAIL, [admin.user.user.email], emailMessage['subject'], emailMessage['message']) emailMessage = emailMessages.joinRequestSentEmail( request, school.name) send_email(NOTIFICATION_EMAIL, [teacher.user.user.email], emailMessage['subject'], emailMessage['message']) messages.success( request, 'Your request to join the school or club has been sent successfully.' ) else: join_form = OutputOrganisationJoinForm(request.POST) elif 'revoke_join_request' in request.POST: teacher.pending_join_request = None teacher.save() messages.success( request, 'Your request to join the school or club has been revoked successfully.' ) res = render(request, 'portal/teach/organisation_create.html', { 'create_form': create_form, 'join_form': join_form, 'teacher': teacher, }) res.count = increment_count return res