Commit f8d3826e authored by Daniel W Bond's avatar Daniel W Bond

added studentcontextmixin to welcome views, and was able to remove a...

added studentcontextmixin to welcome views, and was able to remove a significant amount of duplicated code!
parent e0a4f7c6
......@@ -13,6 +13,7 @@ from ratelimit.decorators import ratelimit
# imports from your apps
from accounts.models import Confirmation, Major
from core.utils import create_email, no_nums, get_semester
from core.views import StudentContextMixin
from housing.models import Room
from .forms import (WelcomeNameForm, WelcomeMajorForm,
WelcomePrivacyForm, WelcomeSocialForm)
......@@ -75,7 +76,7 @@ class WelcomeName(LoginRequiredMixin, FormView):
return reverse('welcomePrivacy')
class WelcomePrivacy(LoginRequiredMixin, FormView):
class WelcomePrivacy(LoginRequiredMixin, StudentContextMixin, FormView):
"""Student adds off-or-on campus status, and if on-campus, housing and privacy."""
form_class = WelcomePrivacyForm
......@@ -108,15 +109,6 @@ class WelcomePrivacy(LoginRequiredMixin, FormView):
return form
def get_context_data(self, **kwargs):
context = super(WelcomePrivacy, self).get_context_data(**kwargs)
me = self.request.user.student
context['student'] = me
return context
@ratelimit(key='user', rate='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True)
def post(self, request, *args, **kwargs):
......@@ -165,7 +157,7 @@ class WelcomePrivacy(LoginRequiredMixin, FormView):
return reverse('welcomeMajor')
class WelcomeMajor(LoginRequiredMixin, FormView):
class WelcomeMajor(LoginRequiredMixin, StudentContextMixin, FormView):
"""Student adds major and graduation year."""
template_name = 'welcome_major.html'
......@@ -189,15 +181,6 @@ class WelcomeMajor(LoginRequiredMixin, FormView):
return initial
def get_context_data(self, **kwargs):
context = super(WelcomeMajor, self).get_context_data(**kwargs)
me = self.request.user.student
context['student'] = me
return context
@ratelimit(key='user', rate='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True)
def post(self, request, *args, **kwargs):
......@@ -236,7 +219,7 @@ class WelcomeMajor(LoginRequiredMixin, FormView):
return reverse('welcomeSocial')
class WelcomeSocial(LoginRequiredMixin, FormView):
class WelcomeSocial(LoginRequiredMixin, StudentContextMixin, FormView):
"""Student connects social media accounts. Redirects to settings page when done."""
form_class = WelcomeSocialForm
......@@ -252,15 +235,6 @@ class WelcomeSocial(LoginRequiredMixin, FormView):
else:
return super(WelcomeSocial, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(WelcomeSocial, self).get_context_data(**kwargs)
me = self.request.user.student
context['student'] = me
return context
@ratelimit(key='user', rate='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True)
def post(self, request, *args, **kwargs):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment