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 ...@@ -13,6 +13,7 @@ from ratelimit.decorators import ratelimit
# imports from your apps # imports from your apps
from accounts.models import Confirmation, Major from accounts.models import Confirmation, Major
from core.utils import create_email, no_nums, get_semester from core.utils import create_email, no_nums, get_semester
from core.views import StudentContextMixin
from housing.models import Room from housing.models import Room
from .forms import (WelcomeNameForm, WelcomeMajorForm, from .forms import (WelcomeNameForm, WelcomeMajorForm,
WelcomePrivacyForm, WelcomeSocialForm) WelcomePrivacyForm, WelcomeSocialForm)
...@@ -75,7 +76,7 @@ class WelcomeName(LoginRequiredMixin, FormView): ...@@ -75,7 +76,7 @@ class WelcomeName(LoginRequiredMixin, FormView):
return reverse('welcomePrivacy') 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.""" """Student adds off-or-on campus status, and if on-campus, housing and privacy."""
form_class = WelcomePrivacyForm form_class = WelcomePrivacyForm
...@@ -108,15 +109,6 @@ class WelcomePrivacy(LoginRequiredMixin, FormView): ...@@ -108,15 +109,6 @@ class WelcomePrivacy(LoginRequiredMixin, FormView):
return form 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='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True) @ratelimit(key='user', rate='10/d', method='POST', block=True)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
...@@ -165,7 +157,7 @@ class WelcomePrivacy(LoginRequiredMixin, FormView): ...@@ -165,7 +157,7 @@ class WelcomePrivacy(LoginRequiredMixin, FormView):
return reverse('welcomeMajor') return reverse('welcomeMajor')
class WelcomeMajor(LoginRequiredMixin, FormView): class WelcomeMajor(LoginRequiredMixin, StudentContextMixin, FormView):
"""Student adds major and graduation year.""" """Student adds major and graduation year."""
template_name = 'welcome_major.html' template_name = 'welcome_major.html'
...@@ -189,15 +181,6 @@ class WelcomeMajor(LoginRequiredMixin, FormView): ...@@ -189,15 +181,6 @@ class WelcomeMajor(LoginRequiredMixin, FormView):
return initial 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='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True) @ratelimit(key='user', rate='10/d', method='POST', block=True)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
...@@ -236,7 +219,7 @@ class WelcomeMajor(LoginRequiredMixin, FormView): ...@@ -236,7 +219,7 @@ class WelcomeMajor(LoginRequiredMixin, FormView):
return reverse('welcomeSocial') return reverse('welcomeSocial')
class WelcomeSocial(LoginRequiredMixin, FormView): class WelcomeSocial(LoginRequiredMixin, StudentContextMixin, FormView):
"""Student connects social media accounts. Redirects to settings page when done.""" """Student connects social media accounts. Redirects to settings page when done."""
form_class = WelcomeSocialForm form_class = WelcomeSocialForm
...@@ -252,15 +235,6 @@ class WelcomeSocial(LoginRequiredMixin, FormView): ...@@ -252,15 +235,6 @@ class WelcomeSocial(LoginRequiredMixin, FormView):
else: else:
return super(WelcomeSocial, self).get(request, *args, **kwargs) 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='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True) @ratelimit(key='user', rate='10/d', method='POST', block=True)
def post(self, request, *args, **kwargs): 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