Esempio n. 1
0
    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)
Esempio n. 2
0
    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.'
            )
Esempio n. 3
0
    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.')
Esempio n. 4
0
    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)
Esempio n. 5
0
    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
        })
Esempio n. 6
0
    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
        })
Esempio n. 7
0
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)