diff --git a/accounts/templates/account/guardian/home.html b/accounts/templates/account/guardian/home.html index e90beea4..db54660b 100644 --- a/accounts/templates/account/guardian/home.html +++ b/accounts/templates/account/guardian/home.html @@ -5,37 +5,16 @@ {% block contained_content %} -
-

Your Profile

-

Joined on {{ guardian.user.date_joined|naturalday|capfirst }}

- -
- {% csrf_token %} -
-
{% bootstrap_field user_form.first_name %}
-
{% bootstrap_field user_form.last_name %}
-
{% bootstrap_field form.phone %}
-
{% bootstrap_field form.zip %}
-
{% bootstrap_field form.birthday %}
-
{% bootstrap_field form.gender %}
-
{% bootstrap_field form.race_ethnicity %}
-
- {% buttons %} - - {% endbuttons %} -
-
-

Students

{% if students %} - +
- - + + @@ -44,9 +23,9 @@

Students

- - - + + + {% endfor %} @@ -57,6 +36,29 @@

Students

{% endif %} +
+

Your Profile

+

Joined on {{ guardian.user.date_joined|naturalday|capfirst }}

+ +
+ {% csrf_token %} +
+
{% bootstrap_field user_form.first_name %}
+
{% bootstrap_field user_form.last_name %}
+
{% bootstrap_field form.phone %}
+
{% bootstrap_field form.zip %}
+
{% bootstrap_field form.birthday %}
+
{% bootstrap_field form.gender %}
+
{% bootstrap_field form.race_ethnicity %}
+
+ {% buttons %} + + {% endbuttons %} + +
+ + +

Upcoming Classes

diff --git a/accounts/views.py b/accounts/views.py index 138da6d7..87a5c215 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -41,17 +41,24 @@ class LoginView(MetadataMixin, AllAuthLoginView): @method_decorator(login_required, name="dispatch") -class AccountHomeView(MetadataMixin, TemplateView): +class GuardianAccountHomeView(MetadataMixin, TemplateView): + template_name = "account/guardian/home.html" title = "My Account | We All Code" def dispatch(self, *args, **kwargs): - if not self.request.user.role: + guardian = get_object_or_404(Guardian, user=self.request.user) + students = Student.objects.filter( + is_active=True, + guardian=guardian, + ).exists() + + if students == False: if "next" in self.request.GET: return redirect(f"{reverse('welcome')}?next={self.request.GET['next']}") else: - messages.warning( + messages.error( self.request, - "Tell us a little about yourself before going on account.", + "Please add at least one student to your account.", ) return redirect("welcome") @@ -67,62 +74,11 @@ def get_context_data(self, **kwargs): context["user"] = self.request.user - if self.request.user.role == "mentor": - return {**context, **self.get_context_data_for_mentor()} - - if self.request.user.role == "guardian": - return {**context, **self.get_context_data_for_guardian()} - - return context - - def get_context_data_for_mentor(self): - mentor = get_object_or_404(Mentor, user=self.request.user) - - orders = MentorOrder.objects.select_related().filter( - is_active=True, - mentor=mentor, + guardian = get_object_or_404( + Guardian, + user=self.request.user, ) - upcoming_sessions = orders.filter(is_active=True, session__start_date__gte=timezone.now()).order_by( - "session__start_date" - ) - - past_sessions = orders.filter(is_active=True, session__start_date__lte=timezone.now()).order_by( - "session__start_date" - ) - - meeting_orders = MeetingOrder.objects.select_related().filter(mentor=mentor) - - upcoming_meetings = meeting_orders.filter( - is_active=True, - meeting__is_public=True, - meeting__end_date__gte=timezone.now(), - ).order_by("meeting__start_date") - - account_complete = False - - if ( - mentor.first_name - and mentor.last_name - and mentor.avatar - and mentor.background_check - and past_sessions.count() > 0 - ): - account_complete = True - - return { - "mentor": mentor, - "orders": orders, - "upcoming_sessions": upcoming_sessions, - "past_sessions": past_sessions, - "meeting_orders": meeting_orders, - "upcoming_meetings": upcoming_meetings, - "account_complete": account_complete, - } - - def get_context_data_for_guardian(self): - guardian = get_object_or_404(Guardian, user=self.request.user) - students = Student.objects.filter( is_active=True, guardian=guardian, @@ -142,30 +98,20 @@ def get_context_data_for_guardian(self): session__start_date__lte=timezone.now(), ).order_by("session__start_date") - return { - "guardian": guardian, - "students": students, - "student_orders": student_orders, - "upcoming_orders": upcoming_orders, - "past_orders": past_orders, + context = { + **context, + **{ + "guardian": guardian, + "students": students, + "student_orders": student_orders, + "upcoming_orders": upcoming_orders, + "past_orders": past_orders, + }, } - def get(self, *args, **kwargs): - if self.request.user.role == "mentor": - return self.get_for_mentor(**kwargs) - - if self.request.user.role == "guardian": - return self.get_for_guardian(**kwargs) - - def get_for_mentor(self, **kwargs): - context = self.get_context_data(**kwargs) - - context["form"] = MentorForm(instance=context["mentor"]) - context["user_form"] = CDCModelForm(instance=context["mentor"].user) - - return render(self.request, "account/mentor/home.html", context) + return context - def get_for_guardian(self, **kwargs): + def get(self, *args, **kwargs): context = self.get_context_data(**kwargs) context["form"] = GuardianForm(instance=context["guardian"]) @@ -174,20 +120,19 @@ def get_for_guardian(self, **kwargs): return render(self.request, "account/guardian/home.html", context) def post(self, *args, **kwargs): - if self.request.user.role == "mentor": - return self.post_for_mentor(**kwargs) - - if self.request.user.role == "guardian": - return self.post_for_guardian(**kwargs) - - def post_for_mentor(self, **kwargs): context = self.get_context_data(**kwargs) - mentor = context["mentor"] + guardian = context["guardian"] - form = MentorForm(self.request.POST, self.request.FILES, instance=mentor) + form = GuardianForm( + self.request.POST, + instance=guardian, + ) - user_form = CDCModelForm(self.request.POST, self.request.FILES, instance=mentor.user) + user_form = CDCModelForm( + self.request.POST, + instance=guardian.user, + ) if form.is_valid() and user_form.is_valid(): form.save() @@ -202,16 +147,105 @@ def post_for_mentor(self, **kwargs): context["form"] = form context["user_form"] = user_form + return render(self.request, "account/guardian/home.html", context) + + +@method_decorator(login_required, name="dispatch") +class MentorAccountHomeView(MetadataMixin, TemplateView): + template_name = "account/mentor/home.html" + title = "My Account | We All Code" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + if "highlight" in self.request.GET: + context["highlight"] = self.request.GET["highlight"] + else: + context["highlight"] = False + + context["user"] = self.request.user + + mentor = get_object_or_404( + Mentor, + user=self.request.user, + ) + + orders = MentorOrder.objects.select_related().filter( + is_active=True, + mentor=mentor, + ) + + upcoming_sessions = orders.filter( + is_active=True, + session__start_date__gte=timezone.now(), + ).order_by("session__start_date") + + past_sessions = orders.filter( + is_active=True, + session__start_date__lte=timezone.now(), + ).order_by("session__start_date") + + meeting_orders = MeetingOrder.objects.select_related().filter( + mentor=mentor, + ) + + upcoming_meetings = meeting_orders.filter( + is_active=True, + meeting__is_public=True, + meeting__end_date__gte=timezone.now(), + ).order_by( + "meeting__start_date", + ) + + account_complete = False + + if ( + mentor.first_name + and mentor.last_name + and mentor.avatar + and mentor.background_check + and past_sessions.count() > 0 + ): + account_complete = True + + context = { + **context, + **{ + "mentor": mentor, + "orders": orders, + "upcoming_sessions": upcoming_sessions, + "past_sessions": past_sessions, + "meeting_orders": meeting_orders, + "upcoming_meetings": upcoming_meetings, + "account_complete": account_complete, + }, + } + return context + + def get(self, *args, **kwargs): + context = self.get_context_data(**kwargs) + + context["form"] = MentorForm(instance=context["mentor"]) + context["user_form"] = CDCModelForm(instance=context["mentor"].user) + return render(self.request, "account/mentor/home.html", context) - def post_for_guardian(self, **kwargs): + def post(self, *args, **kwargs): context = self.get_context_data(**kwargs) - guardian = context["guardian"] + mentor = context["mentor"] - form = GuardianForm(self.request.POST, instance=guardian) + form = MentorForm( + self.request.POST, + self.request.FILES, + instance=mentor, + ) - user_form = CDCModelForm(self.request.POST, instance=guardian.user) + user_form = CDCModelForm( + self.request.POST, + self.request.FILES, + instance=mentor.user, + ) if form.is_valid() and user_form.is_valid(): form.save() @@ -226,4 +260,28 @@ def post_for_guardian(self, **kwargs): context["form"] = form context["user_form"] = user_form - return render(self.request, "account/guardian/home.html", context) + return render(self.request, "account/mentor/home.html", context) + + +@method_decorator(login_required, name="dispatch") +class AccountHomeView(MetadataMixin, TemplateView): + title = "My Account | We All Code" + + def dispatch(self, *args, **kwargs): + if not self.request.user.role: + if "next" in self.request.GET: + return redirect(f"{reverse('welcome')}?next={self.request.GET['next']}") + else: + messages.warning( + self.request, + "Tell us a little about yourself before going on account.", + ) + return redirect("welcome") + + if self.request.user.role == "guardian": + return GuardianAccountHomeView.as_view()(self.request) + + if self.request.user.role == "mentor": + return MentorAccountHomeView.as_view()(self.request) + + return super().dispatch(*args, **kwargs) diff --git a/coderdojochi/forms.py b/coderdojochi/forms.py index 6a798094..af52239f 100644 --- a/coderdojochi/forms.py +++ b/coderdojochi/forms.py @@ -3,12 +3,14 @@ from django import forms from django.contrib.auth import get_user_model from django.core.files.images import get_image_dimensions -from django.forms import FileField, Form, ModelForm, ValidationError +from django.forms import BooleanField, FileField, Form, ModelForm, ValidationError +from django.forms.utils import flatatt from django.urls import reverse_lazy from django.utils import dateformat, timezone from django.utils.html import format_html from django.utils.safestring import mark_safe from django.utils.text import format_lazy +from django.utils.translation import gettext as _ import html5.forms.widgets as html5_widgets from captcha.fields import ReCaptchaField @@ -17,6 +19,51 @@ from coderdojochi.models import CDCUser, Donation, Guardian, Mentor, RaceEthnicity, Session, Student +# Custom Checkbox START +class PrettyCheckboxWidget(forms.widgets.CheckboxInput): + def render(self, name, value, attrs=None, renderer=None): + final_attrs = self.build_attrs( + self.attrs, + { + "type": "checkbox", + "name": self.id_for_label(name), + "id": f"id_{name}", + }, + ) + + if self.check_test(value): + final_attrs["checked"] = "checked" + + if not (value is True or value is False or value is None or value == ""): + final_attrs["value"] = force_text(value) + + if "_label" in final_attrs: + label = _(final_attrs.pop("_label")) + else: + label = "" + + return format_html( + '
', + final_attrs["id"], + flatatt(final_attrs), + label, + ) + + +class PrettyCheckboxField(BooleanField): + widget = PrettyCheckboxWidget + + def __init__(self, *args, **kwargs): + if kwargs["label"]: + kwargs["widget"].attrs["_label"] = kwargs["label"] + kwargs["label"] = "" + + # print(kwargs) + super(PrettyCheckboxField, self).__init__(*args, **kwargs) + + +# Custom Checkbox END + class CDCForm(Form): # strip leading or trailing whitespace @@ -81,17 +128,30 @@ def _clean_fields(self): class Meta: model = CDCUser - fields = ("first_name", "last_name") + fields = ( + "first_name", + "last_name", + ) class SignupForm(forms.Form): - first_name = forms.CharField(max_length=30) - last_name = forms.CharField(max_length=30) + first_name = forms.CharField( + max_length=30, + ) + last_name = forms.CharField( + max_length=30, + ) captcha = ReCaptchaField( label="", widget=ReCaptchaV3, ) - field_order = ["first_name", "last_name", "email", "password1", "password2"] + field_order = [ + "first_name", + "last_name", + "email", + "password1", + "password2", + ] class Meta: model = get_user_model() @@ -104,36 +164,88 @@ def signup(self, request, user): class MentorForm(CDCModelForm): bio = forms.CharField( - widget=forms.Textarea(attrs={"placeholder": "Short Bio", "class": "form-control", "rows": 4}), + widget=forms.Textarea( + attrs={ + "placeholder": "Short Bio", + "class": "form-control", + "rows": 4, + }, + ), label="Short Bio", required=False, ) gender = forms.CharField( - widget=forms.TextInput(attrs={"placeholder": "", "class": "form-control"}), label="Gender", required=True + widget=forms.TextInput( + attrs={ + "placeholder": "", + "class": "form-control", + }, + ), + label="Gender", + required=True, ) race_ethnicity = forms.ModelMultipleChoiceField( - widget=forms.SelectMultiple, queryset=RaceEthnicity.objects.filter(is_visible=True), required=True + widget=forms.SelectMultiple, + queryset=RaceEthnicity.objects.filter(is_visible=True), + required=True, ) - birthday = forms.CharField(widget=html5_widgets.DateInput(attrs={"class": "form-control"}), required=True) + birthday = forms.CharField( + widget=html5_widgets.DateInput( + attrs={ + "class": "form-control", + }, + ), + required=True, + ) work_place = forms.CharField( - widget=forms.TextInput(attrs={"placeholder": "", "class": "form-control"}), label="Work Place", required=False + widget=forms.TextInput( + attrs={ + "placeholder": "", + "class": "form-control", + }, + ), + label="Work Place", + required=False, ) phone = forms.CharField( - widget=forms.TextInput(attrs={"placeholder": "", "class": "form-control"}), label="Phone", required=False + widget=forms.TextInput( + attrs={ + "placeholder": "", + "class": "form-control", + }, + ), + label="Phone", + required=False, ) home_address = forms.CharField( - widget=forms.TextInput(attrs={"placeholder": "", "class": "form-control"}), label="Home Address", required=False + widget=forms.TextInput( + attrs={ + "placeholder": "", + "class": "form-control", + }, + ), + label="Home Address", + required=False, ) class Meta: model = Mentor - fields = ("bio", "avatar", "gender", "race_ethnicity", "birthday", "phone", "home_address", "work_place") + fields = ( + "bio", + "avatar", + "gender", + "race_ethnicity", + "birthday", + "phone", + "home_address", + "work_place", + ) def clean_avatar(self): avatar = self.cleaned_data["avatar"] @@ -173,26 +285,67 @@ def clean_avatar(self): class GuardianForm(CDCModelForm): phone = forms.CharField( - widget=forms.TextInput(attrs={"placeholder": "Phone Number", "class": "form-control"}), label="Phone Number" + required=True, + label="Parent's Phone Number", + widget=forms.TextInput( + attrs={ + "placeholder": "773-867-5309", + "class": "form-control", + }, + ), ) zip = forms.CharField( - widget=forms.TextInput(attrs={"placeholder": "Zip Code", "class": "form-control"}), label="Zip Code" + required=True, + label="Parent's Zip Code", + widget=forms.TextInput( + attrs={ + "placeholder": "60601", + "class": "form-control", + }, + ), ) gender = forms.CharField( - widget=forms.TextInput(attrs={"placeholder": "", "class": "form-control"}), label="Gender", required=True + required=True, + label="Parent's Gender", + widget=forms.TextInput( + attrs={ + "placeholder": "Female", + "class": "form-control", + }, + ), ) race_ethnicity = forms.ModelMultipleChoiceField( - widget=forms.SelectMultiple, queryset=RaceEthnicity.objects.filter(is_visible=True), required=True + required=True, + label="Parent's Race/Ethnicity", + widget=forms.CheckboxSelectMultiple, + queryset=RaceEthnicity.objects.filter(is_visible=True), ) - birthday = forms.CharField(widget=html5_widgets.DateInput(attrs={"class": "form-control"}), required=True) + # Limit parent birthday between 18-100 years from today, with the hopes they don't try to enter their kid's birthday here. + birthday = forms.CharField( + required=True, + label="Parent's Birthday", + widget=html5_widgets.DateInput( + attrs={ + "class": "form-control", + "min": dateformat.format(timezone.now() - relativedelta(years=100), "Y-m-d"), + "max": dateformat.format(timezone.now() - relativedelta(years=18), "Y-m-d"), + }, + ), + ) class Meta: model = Guardian - fields = ("phone", "zip", "gender", "race_ethnicity", "birthday") + fields = ( + "phone", + "zip", + "gender", + "race_ethnicity", + "birthday", + ) class StudentForm(CDCModelForm): @@ -210,141 +363,171 @@ class StudentForm(CDCModelForm): ] first_name = forms.CharField( + required=True, + label="Student's First Name", widget=forms.TextInput( attrs={ "placeholder": "Jane", "class": "form-control", }, ), - label="First Name", ) last_name = forms.CharField( + required=True, + label="Student's Last Name", widget=forms.TextInput( attrs={ "placeholder": "Doe", "class": "form-control", }, ), - label="Last Name", ) gender = forms.CharField( + required=True, + label="Student's Gender", widget=forms.TextInput( attrs={ "placeholder": "", "class": "form-control", }, ), - label="Gender", ) school_name = forms.CharField( + required=True, + label="Student's School Name", widget=forms.TextInput( attrs={ "class": "form-control", }, ), - label="School Name", - required=False, ) school_type = forms.ChoiceField( + required=True, + label="Student's School Type", widget=forms.RadioSelect, choices=SCHOOL_TYPE_CHOICES, - required=False, ) race_ethnicity = forms.ModelMultipleChoiceField( + required=True, + label="Student's Race/Ethnicity", widget=forms.CheckboxSelectMultiple, queryset=RaceEthnicity.objects.filter(is_visible=True), - required=False, ) birthday = forms.CharField( + required=True, + label="Student's Birthday", widget=html5_widgets.DateInput( attrs={ "class": "form-control", "min": dateformat.format(timezone.now() - relativedelta(years=19), "Y-m-d"), "max": dateformat.format(timezone.now() - relativedelta(years=5), "Y-m-d"), - } + }, ), ) medications = forms.CharField( + required=False, + label="Medications", + help_text="List any medications currently being taken.", widget=forms.Textarea( attrs={ - "placeholder": "List any medications currently being taken.", - "class": "form-control hidden", - "rows": 5, - } - ), - label=format_html( - "{0} {1}", - "Medications", - mark_safe('expand'), + "class": "form-control", + "rows": 2, + }, ), - required=False, ) medical_conditions = forms.CharField( + required=False, + label="Medical Conditions", + help_text="Let us know of any learning difficulties so we may adapt to your student.", widget=forms.Textarea( attrs={ - "placeholder": "List any medical conditions.", - "class": "form-control hidden", - "rows": 5, + "class": "form-control", + "rows": 2, }, ), - label=format_html( - "{0} {1}", - "Medical Conditions", - mark_safe('expand'), - ), - required=False, ) - photo_release = forms.BooleanField( - widget=forms.CheckboxInput( - attrs={ - "required": "required", - }, - ), + photo_release = PrettyCheckboxField( + required=True, label=( "I hereby give permission to We All Code to use the " "student's image and/or likeness in promotional materials." ), + widget=PrettyCheckboxWidget( + attrs={ + "required": "required", + }, + ), ) - consent = forms.BooleanField( - widget=forms.CheckboxInput( + consent = PrettyCheckboxField( + required=True, + label=mark_safe( + 'I hereby give consent for the student signed up above to participate in We All Code as per the terms.' + ), + widget=PrettyCheckboxWidget( attrs={ "required": "required", }, ), - label=format_lazy( - "I hereby give consent for the student signed up above to participate in We All Code as per the " - 'terms.', - reverse_lazy("weallcode-privacy"), - ), ) class Meta: model = Student - exclude = ("guardian", "created_at", "updated_at", "is_active") + exclude = ( + "guardian", + "created_at", + "updated_at", + "is_active", + ) class ContactForm(CDCForm): - name = forms.CharField(max_length=100, label="Your name") - email = forms.EmailField(max_length=200, label="Your email address") - message = forms.CharField(widget=forms.Textarea, label="Your message") - human = forms.CharField(max_length=100, label=False, required=False) + name = forms.CharField( + max_length=100, + label="Your name", + ) + email = forms.EmailField( + max_length=200, + label="Your email address", + ) + message = forms.CharField( + widget=forms.Textarea, + label="Your message", + ) + human = forms.CharField( + max_length=100, + label=False, + required=False, + ) class DonationForm(ModelForm): - session = forms.ModelChoiceField(queryset=Session.objects.all(), widget=forms.HiddenInput(), required=True) - user = forms.ModelChoiceField(queryset=CDCUser.objects.all(), required=True) - amount = forms.CharField(label="Amount (dollars)") + session = forms.ModelChoiceField( + queryset=Session.objects.all(), + widget=forms.HiddenInput(), + required=True, + ) + user = forms.ModelChoiceField( + queryset=CDCUser.objects.all(), + required=True, + ) + amount = forms.CharField( + label="Amount (dollars)", + ) class Meta: model = Donation - fields = ["session", "user", "amount"] + fields = [ + "session", + "user", + "amount", + ] diff --git a/coderdojochi/templates/welcome.html b/coderdojochi/templates/welcome.html index cc7d4c9f..58a2569e 100644 --- a/coderdojochi/templates/welcome.html +++ b/coderdojochi/templates/welcome.html @@ -11,21 +11,27 @@ {% block body_class %}page-welcome{% endblock %} {% block contained_content %} -
+ +
{% if role %} {% if role == 'guardian' %} {% if not add_student %} -

Tell us a little more about yourself...

-

- Before you sign up your student(s), let's start with some contact information.
- We will never share this information with anyone. -

+

Parent Information

+

Let's start with some parent information. We will never share this information with anyone.

{% else %} {% if students %}

{{ students }} Student{{ students|pluralize }} Registered

Register another student

{% else %} -

Register your first student now

+

Student Information

{% endif %} {% endif %} {% endif %} @@ -38,14 +44,12 @@

Tell us a little more...

{% if form %} {% if add_student %} -

Please complete all fields below

+

Please complete all fields below.

{% endif %}
{% csrf_token %} -
-
{% bootstrap_form form %}
-
+ {{ form }} {% endif %} diff --git a/coderdojochi/views/welcome.py b/coderdojochi/views/welcome.py index ebbd732b..eeeda3d6 100644 --- a/coderdojochi/views/welcome.py +++ b/coderdojochi/views/welcome.py @@ -22,9 +22,13 @@ class WelcomeView(TemplateView): def dispatch(self, request, *args, **kwargs): next_url = request.GET.get("next") kwargs["next_url"] = next_url + # Check for redirect condition on mentor, otherwise pass as kwarg if getattr(request.user, "role", False) == "mentor" and request.method == "GET": - mentor = get_object_or_404(Mentor, user=request.user) + mentor = get_object_or_404( + Mentor, + user=request.user, + ) if mentor.first_name: if next_url: @@ -33,10 +37,12 @@ def dispatch(self, request, *args, **kwargs): return redirect("account_home") kwargs["mentor"] = mentor + return super().dispatch(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + user = self.request.user mentor = kwargs.get("mentor") account = False @@ -49,8 +55,12 @@ def get_context_data(self, **kwargs): account = mentor context["form"] = MentorForm(instance=account) if role == "guardian": - guardian = get_object_or_404(Guardian, user=user) + guardian = get_object_or_404( + Guardian, + user=user, + ) account = guardian + if not account.phone or not account.zip: context["form"] = GuardianForm(instance=account) else: @@ -71,7 +81,10 @@ def post(self, request, *args, **kwargs): if role: if role == "mentor": - account = get_object_or_404(Mentor, user=user) + account = get_object_or_404( + Mentor, + user=user, + ) return self.update_account(request, account, next_url) account = get_object_or_404(Guardian, user=user) @@ -84,14 +97,22 @@ def post(self, request, *args, **kwargs): def update_account(self, request, account, next_url): if isinstance(account, Mentor): - form = MentorForm(request.POST, instance=account) + form = MentorForm( + request.POST, + instance=account, + ) role = "mentor" else: - form = GuardianForm(request.POST, instance=account) + form = GuardianForm( + request.POST, + instance=account, + ) role = "guardian" + if form.is_valid(): form.save() messages.success(request, "Profile information saved.") + if next_url: if "enroll" in request.GET: next_url = f"{next_url}?enroll=True" @@ -100,30 +121,47 @@ def update_account(self, request, account, next_url): next_url = "account_home" else: next_url = "welcome" + return redirect(next_url) return render( - request, self.template_name, {"form": form, "role": role, "account": account, "next_url": next_url} + request, + self.template_name, + { + "form": form, + "role": role, + "account": account, + "next_url": next_url, + }, ) def add_student(self, request, account, next_url): form = StudentForm(request.POST) + if form.is_valid(): new_student = form.save(commit=False) new_student.guardian = account new_student.save() messages.success(request, "Student Registered.") + if next_url: if "enroll" in request.GET: next_url = f"{next_url}?enroll=True&student={new_student.id}" else: - next_url = "welcome" + next_url = "weallcode-programs" + return redirect(next_url) return render( request, self.template_name, - {"form": form, "role": "guardian", "account": account, "next_url": next_url, "add_student": True}, + { + "form": form, + "role": "guardian", + "account": account, + "next_url": next_url, + "add_student": True, + }, ) def create_new_user(self, request, user, next_url): @@ -141,7 +179,11 @@ def create_new_user(self, request, user, next_url): user.role = role user.save() - merge_global_data = {"user": user.username, "first_name": user.first_name, "last_name": user.last_name} + merge_global_data = { + "user": user.username, + "first_name": user.first_name, + "last_name": user.last_name, + } if next_url: next_url = f"?next={next_url}" @@ -150,7 +192,16 @@ def create_new_user(self, request, user, next_url): if role == "mentor": # check for next upcoming meeting - next_meeting = Meeting.objects.filter(is_active=True, is_public=True).order_by("start_date").first() + next_meeting = ( + Meeting.objects.filter( + is_active=True, + is_public=True, + ) + .order_by( + "start_date", + ) + .first() + ) if next_meeting: merge_global_data["next_intro_meeting_url"] = f"{settings.SITE_URL}{next_meeting.get_absolute_url()}" @@ -170,7 +221,15 @@ def create_new_user(self, request, user, next_url): ) else: # check for next upcoming class - next_class = Session.objects.filter(is_active=True).order_by("start_date").first() + next_class = ( + Session.objects.filter( + is_active=True, + ) + .order_by( + "start_date", + ) + .first() + ) if next_class: merge_global_data["next_class_url"] = f"{settings.SITE_URL}{next_class.get_absolute_url()}" diff --git a/weallcode/templates/weallcode/_messages.html b/weallcode/templates/weallcode/_messages.html index cb83d4e1..2607200d 100644 --- a/weallcode/templates/weallcode/_messages.html +++ b/weallcode/templates/weallcode/_messages.html @@ -5,7 +5,7 @@ {% else %}warning{% endif %}" role="alert"> {% if message.tags %} {% if message.tags == 'error' %} - Oh snap! + {% elif message.tags == 'warning' %} Warning! {% elif message.tags == 'success' %}
Name
{{ student.full_name }} Edit InfoEdit Info