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_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 get_context_data(self, **kwargs): context = super(WelcomeView, self).get_context_data(**kwargs) user = self.request.user mentor = kwargs.get('mentor') account = False role = getattr(user, 'role', False) context['role'] = role context['next_url'] = kwargs['next_url'] if mentor: account = mentor context['form'] = MentorForm(instance=account) if role == 'guardian': guardian = get_object_or_404(Guardian, user=user) account = guardian if not account.phone or not account.zip: context['form'] = GuardianForm(instance=account) else: context['add_student'] = True context['form'] = StudentForm( initial={'guardian': guardian.pk}) if account.user.first_name and account.get_students(): context['students'] = account.get_students().count() context['account'] = account return 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 update_account(self, request, account, next_url): if isinstance(account, Mentor): form = MentorForm(request.POST, instance=account) role = 'mentor' else: 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" else: next_url = 'account_home' if isinstance(account, Mentor) else 'welcome' return redirect(next_url) return render(request, self.template_name, { 'form': form, 'role': role, 'account': account, 'next_url': next_url })
def update_account(self, request, account, next_url): if isinstance(account, Mentor): form = MentorForm(request.POST, instance=account) role = 'mentor' else: 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" else: next_url = 'dojo' if isinstance(account, Mentor) else 'welcome' return redirect(next_url) return render(request, self.template_name, { 'form': form, 'role': role, 'account': account, 'next_url': next_url })
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)