def post_for_guardian(self, **kwargs): context = self.get_context_data(**kwargs) guardian = context['guardian'] form = GuardianForm( self.request.POST, instance=guardian ) user_form = CDCModelForm( self.request.POST, instance=guardian.user ) if form.is_valid() and user_form.is_valid(): form.save() user_form.save() messages.success( self.request, 'Profile information saved.' ) return redirect('account_home') else: messages.error( self.request, 'There was an error. Please try again.' ) context['form'] = form context['user_form'] = user_form return render(self.request, 'account/home_guardian.html', context)
def post_for_mentor(self, **kwargs): context = self.get_context_data(**kwargs) mentor = context['mentor'] form = MentorForm(self.request.POST, self.request.FILES, instance=mentor) user_form = CDCModelForm(self.request.POST, self.request.FILES, instance=mentor.user) if (form.is_valid() and user_form.is_valid()): form.save() user_form.save() messages.success(self.request, 'Profile information saved.') return redirect('account_home') else: messages.error(self.request, 'There was an error. Please try again.') context['form'] = form context['user_form'] = user_form return render(self.request, 'account/mentor/home.html', context)
def post(self, request, *args, **kwargs): mentor = get_object_or_404(Mentor, user=request.user) form = MentorForm( request.POST, request.FILES, instance=mentor ) user_form = CDCModelForm( request.POST, request.FILES, instance=mentor.user ) if ( form.is_valid() and user_form.is_valid() ): form.save() user_form.save() messages.success( request, 'Profile information saved.' ) return redirect('account_home') else: messages.error( request, 'There was an error. Please try again.' )
def get_for_guardian(self, **kwargs): context = self.get_context_data(**kwargs) context['form'] = GuardianForm(instance=context['guardian']) context['user_form'] = CDCModelForm(instance=context['guardian'].user) return render(self.request, 'account/guardian/home.html', context)
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)
def post(self, request, *args, **kwargs): mentor = get_object_or_404(Mentor, user=request.user) form = MentorForm(request.POST, request.FILES, instance=mentor) user_form = CDCModelForm(request.POST, request.FILES, instance=mentor.user) if (form.is_valid() and user_form.is_valid()): form.save() user_form.save() messages.success(request, 'Profile information saved.') return redirect('account_home') else: messages.error(request, 'There was an error. Please try again.')
def post_for_mentor(self, **kwargs): context = self.get_context_data(**kwargs) mentor = context['mentor'] form = MentorForm( self.request.POST, self.request.FILES, instance=mentor ) user_form = CDCModelForm( self.request.POST, self.request.FILES, instance=mentor.user ) if ( form.is_valid() and user_form.is_valid() ): form.save() user_form.save() messages.success( self.request, 'Profile information saved.' ) return redirect('account_home') else: messages.error( self.request, 'There was an error. Please try again.' ) context['form'] = form context['user_form'] = user_form return render(self.request, 'account/home_mentor.html', context)
def dojo_guardian(request, template_name='guardian/dojo.html'): highlight = ( request.GET['highlight'] if 'highlight' in request.GET else False ) context = { 'user': request.user, 'highlight': highlight, } guardian = get_object_or_404( Guardian, user=request.user ) students = Student.objects.filter( is_active=True, guardian=guardian, ) student_orders = Order.objects.filter( student__in=students, ) upcoming_orders = student_orders.filter( is_active=True, session__end_date__gte=timezone.now(), ).order_by('session__start_date') past_orders = student_orders.filter( is_active=True, session__end_date__lte=timezone.now(), ).order_by('session__start_date') if request.method == 'POST': form = GuardianForm( request.POST, instance=guardian ) user_form = CDCModelForm( request.POST, instance=guardian.user ) if form.is_valid() and user_form.is_valid(): form.save() user_form.save() messages.success( request, 'Profile information saved.' ) return redirect('dojo') else: messages.error( request, 'There was an error. Please try again.' ) else: form = GuardianForm(instance=guardian) user_form = CDCModelForm(instance=guardian.user) context['students'] = students context['upcoming_orders'] = upcoming_orders context['past_orders'] = past_orders context['guardian'] = guardian context['form'] = form context['user_form'] = user_form return render(request, template_name, context)
def dojo_mentor(request, template_name='mentor/dojo.html'): highlight = ( request.GET['highlight'] if 'highlight' in request.GET else False ) context = { 'user': request.user, 'highlight': highlight, } mentor = get_object_or_404(Mentor, user=request.user) orders = MentorOrder.objects.select_related().filter( is_active=True, mentor=mentor, ) upcoming_sessions = orders.filter( is_active=True, session__end_date__gte=timezone.now() ).order_by('session__start_date') past_sessions = orders.filter( is_active=True, session__end_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') context['account_complete'] = False if ( mentor.user.first_name and mentor.user.last_name and mentor.avatar and mentor.background_check and past_sessions.count() > 0 ): context['account_complete'] = True if request.method == 'POST': form = MentorForm( request.POST, request.FILES, instance=mentor ) user_form = CDCModelForm( request.POST, request.FILES, instance=mentor.user ) if ( form.is_valid() and user_form.is_valid() ): form.save() user_form.save() messages.success( request, 'Profile information saved.' ) return redirect('dojo') else: messages.error( request, 'There was an error. Please try again.' ) else: form = MentorForm(instance=mentor) user_form = CDCModelForm(instance=mentor.user) context['mentor'] = mentor context['upcoming_sessions'] = upcoming_sessions context['upcoming_meetings'] = upcoming_meetings context['past_sessions'] = past_sessions context['mentor'] = mentor context['form'] = form context['user_form'] = user_form return render(request, template_name, context)