Example #1
0
def requirements_view(request):
    profile = request.user.profile

    if profile.position == Profile.CANDIDATE:
        term = Settings.objects.term()
        candidate = profile.candidate

        if request.method == "POST":
            form = CandidateForm(request.POST, request.FILES, instance=candidate)
            if form.is_valid():
                form.save()
                update_professor_interview_and_resume(candidate)

        else:
            form = CandidateForm()

        return render_profile_page(request, 'candidate_requirements.html', {'term': term, 'form': form})

    else:
        term = Settings.objects.signup_term()
        if request.method == "POST":
            member = ActiveMember(profile=profile, term=term)
            member.peer_teaching = PeerTeaching.objects.create(profile=profile, term=Settings.objects.term())
            member_form = MemberForm(request.POST, instance=member)
            tutoring_preferences_form = TutoringPreferencesForm(request.POST)

            valid_forms = [form.is_valid() for form in (member_form, tutoring_preferences_form)]
            if all(valid_forms):
                if member_form.cleaned_data['requirement_choice'] == ActiveMember.TUTORING:
                    member.peer_teaching.requirement_choice = PeerTeaching.TUTORING
                    member.peer_teaching.tutoring = Tutoring.with_weeks(profile=profile, term=term)
                    tutoring_preferences_form = TutoringPreferencesForm(request.POST, instance=member.peer_teaching.tutoring)
                    tutoring_preferences_form.save()

                member.peer_teaching.save()
                member_form.save()
                member_form = None
                tutoring_preferences_form = None

        else:
            try:
                member = ActiveMember.objects.get(profile=profile, term=term)
                member_form = None
                tutoring_preferences_form = None
            except ActiveMember.DoesNotExist:
                member = None
                member_form = MemberForm()
                tutoring_preferences_form = TutoringPreferencesForm()

        return render_profile_page(
            request, 'member_requirements.html', {
                'term': term, 'requirement': member.get_requirement_choice_display() if member else '',
                'member_form': member_form, 'tutoring_preferences_form': tutoring_preferences_form
            })
Example #2
0
def requirements_view(request):
    profile = request.user.profile

    if profile.position == Profile.CANDIDATE:
        term = Settings.objects.term()
        candidate = profile.candidate

        if request.method == "POST":
            form = CandidateForm(request.POST,
                                 request.FILES,
                                 instance=candidate)
            if form.is_valid():
                form.save()
                update_professor_interview_and_resume(candidate)

        else:
            form = CandidateForm()

        return render_profile_page(request, 'candidate_requirements.html', {
            'term': term,
            'form': form
        })

    else:
        term = Settings.objects.signup_term()
        if request.method == "POST":
            member = ActiveMember(profile=profile, term=term)
            member.peer_teaching = PeerTeaching.objects.create(
                profile=profile, term=Settings.objects.term())
            member_form = MemberForm(request.POST, instance=member)
            tutoring_preferences_form = TutoringPreferencesForm(request.POST)

            valid_forms = [
                form.is_valid()
                for form in (member_form, tutoring_preferences_form)
            ]
            if all(valid_forms):
                if member_form.cleaned_data[
                        'requirement_choice'] == ActiveMember.TUTORING:
                    member.peer_teaching.requirement_choice = PeerTeaching.TUTORING
                    member.peer_teaching.tutoring = Tutoring.with_weeks(
                        profile=profile, term=term)
                    tutoring_preferences_form = TutoringPreferencesForm(
                        request.POST, instance=member.peer_teaching.tutoring)
                    tutoring_preferences_form.save()

                member.peer_teaching.save()
                member_form.save()
                member_form = None
                tutoring_preferences_form = None

        else:
            try:
                member = ActiveMember.objects.get(profile=profile, term=term)
                member_form = None
                tutoring_preferences_form = None
            except ActiveMember.DoesNotExist:
                member = None
                member_form = MemberForm()
                tutoring_preferences_form = TutoringPreferencesForm()

        return render_profile_page(
            request, 'member_requirements.html', {
                'term':
                term,
                'requirement':
                member.get_requirement_choice_display() if member else '',
                'member_form':
                member_form,
                'tutoring_preferences_form':
                tutoring_preferences_form
            })
Example #3
0
def edit(request):
    user = request.user
    profile = user.profile
    first_time = hasattr(
        profile, 'candidate') and profile.candidate.peer_teaching is None

    if request.method != "POST":
        personal_dict = model_to_dict(user)
        personal_dict['middle_name'] = profile.middle_name
        user_personal_form = UserPersonalForm(instance=user,
                                              initial=personal_dict)

        profile_dict = model_to_dict(profile)
        if profile.graduation_term is not None:
            profile_dict.update({
                'graduation_quarter': profile.graduation_term.quarter,
                'graduation_year': profile.graduation_term.year
            })

        if not first_time:
            profile_form = ProfileForm(initial=profile_dict)
        else:
            profile_form = FirstProfileForm(initial=profile_dict)
            tutoring_form = TutoringPreferencesForm()
            shirt_form = ShirtForm()
            peer_teaching_form = PeerTeachingForm()

    else:
        user_personal_form = UserPersonalForm(request.POST, instance=user)

        if not first_time:
            profile_form = ProfileForm(request.POST,
                                       request.FILES,
                                       instance=profile)
            valid_forms = [
                form.is_valid() for form in (user_personal_form, profile_form)
            ]
        else:
            profile_form = FirstProfileForm(request.POST, instance=profile)
            tutoring_form = TutoringPreferencesForm(request.POST)
            shirt_form = ShirtForm(request.POST, instance=profile.candidate)
            peer_teaching_form = PeerTeachingForm(request.POST)
            valid_forms = [
                form.is_valid()
                for form in (user_personal_form, profile_form, tutoring_form,
                             shirt_form, peer_teaching_form)
            ]

        if all(valid_forms):
            term, created = Term.objects.get_or_create(
                quarter=profile_form.cleaned_data['graduation_quarter'],
                year=profile_form.cleaned_data['graduation_year'])

            user_personal_form.save()
            profile.middle_name = user_personal_form.cleaned_data[
                'middle_name']
            profile.graduation_term = term
            profile_form.save()

            if not first_time:
                if profile.position == Profile.CANDIDATE:
                    update_professor_interview_and_resume(profile.candidate)
                return redirect(profile_view)
            else:
                candidate = profile.candidate
                candidate.peer_teaching = PeerTeaching.objects.create(
                    profile=profile, term=Settings.objects.term())
                candidate.peer_teaching.tutoring = Tutoring.with_weeks(
                    profile=profile, term=Settings.objects.term())
                tutoring_form = TutoringPreferencesForm(
                    request.POST, instance=candidate.peer_teaching.tutoring)
                tutoring_form.save()

                # If the candidate did NOT select tutoring, then we will set the attributes
                # of their tutoring object to hidden/frozen so that their object does not
                # interfere with anything else.
                if peer_teaching_form.cleaned_data[
                        'requirement_choice'] != PeerTeaching.TUTORING:
                    candidate.peer_teaching.tutoring.frozen = True
                    candidate.peer_teaching.tutoring.hidden = True
                    candidate.peer_teaching.tutoring.save()

                peer_teaching_form = PeerTeachingForm(
                    request.POST, instance=candidate.peer_teaching)
                peer_teaching_form.save()

                shirt_form.save()
                return redirect(add)

    if not first_time:
        return render_profile_page(request, 'edit.html', {
            'user_personal_form': user_personal_form,
            'profile_form': profile_form
        })
    else:
        return render_profile_page(
            request, 'first_edit.html', {
                'user_personal_form': user_personal_form,
                'profile_form': profile_form,
                'tutoring_form': tutoring_form,
                'shirt_form': shirt_form,
                'peer_teaching_form': peer_teaching_form
            })
Example #4
0
def edit(request):
    user = request.user
    profile = user.profile
    first_time = hasattr(profile, 'candidate') and profile.candidate.peer_teaching is None

    if request.method != "POST":
        personal_dict = model_to_dict(user)
        personal_dict['middle_name'] = profile.middle_name
        user_personal_form = UserPersonalForm(instance=user, initial=personal_dict)

        profile_dict = model_to_dict(profile)
        if profile.graduation_term is not None:
            profile_dict.update({
                'graduation_quarter': profile.graduation_term.quarter,
                'graduation_year': profile.graduation_term.year
            })

        if not first_time:
            profile_form = ProfileForm(initial=profile_dict)
        else:
            profile_form = FirstProfileForm(initial=profile_dict)
            tutoring_form = TutoringPreferencesForm()
            shirt_form = ShirtForm()
            peer_teaching_form = PeerTeachingForm()
            
    else:
        user_personal_form = UserPersonalForm(request.POST, instance=user)

        if not first_time:
            profile_form = ProfileForm(request.POST, request.FILES, instance=profile)
            valid_forms = [form.is_valid() for form in (user_personal_form, profile_form)]
        else:
            profile_form = FirstProfileForm(request.POST, instance=profile)
            tutoring_form = TutoringPreferencesForm(request.POST)
            shirt_form = ShirtForm(request.POST, instance=profile.candidate)
            peer_teaching_form = PeerTeachingForm(request.POST)
            valid_forms = [form.is_valid() for form in (user_personal_form, profile_form, tutoring_form, shirt_form, peer_teaching_form)]

        if all(valid_forms):
            term, created = Term.objects.get_or_create(quarter=profile_form.cleaned_data['graduation_quarter'],
                                                       year=profile_form.cleaned_data['graduation_year'])

            user_personal_form.save()
            profile.middle_name = user_personal_form.cleaned_data['middle_name']
            profile.graduation_term = term
            profile_form.save()

            if not first_time:
                if profile.position == Profile.CANDIDATE:
                    update_professor_interview_and_resume(profile.candidate)
                return redirect(profile_view)
            else:
                candidate = profile.candidate
                candidate.peer_teaching = PeerTeaching.objects.create(profile=profile, term=Settings.objects.term())
                candidate.peer_teaching.tutoring = Tutoring.with_weeks(profile=profile, term=Settings.objects.term())
                tutoring_form = TutoringPreferencesForm(request.POST, instance=candidate.peer_teaching.tutoring)
                tutoring_form.save()
                
                # If the candidate did NOT select tutoring, then we will set the attributes
                # of their tutoring object to hidden/frozen so that their object does not
                # interfere with anything else.
                if peer_teaching_form.cleaned_data['requirement_choice'] != PeerTeaching.TUTORING:
                    candidate.peer_teaching.tutoring.frozen = True
                    candidate.peer_teaching.tutoring.hidden = True
                    candidate.peer_teaching.tutoring.save()

                peer_teaching_form = PeerTeachingForm(request.POST, instance=candidate.peer_teaching)
                peer_teaching_form.save()
                
                shirt_form.save()
                return redirect(add)

    if not first_time:
        return render_profile_page(request, 'edit.html',
                                   {'user_personal_form': user_personal_form, 'profile_form': profile_form})
    else:
        return render_profile_page(request, 'first_edit.html',
                                   {'user_personal_form': user_personal_form, 'profile_form': profile_form,
                                    'tutoring_form': tutoring_form, 'shirt_form': shirt_form, 'peer_teaching_form' : peer_teaching_form})
#!/usr/bin/env python
import sys

sys.path.insert(0, '..')

from tbpsite import settings
from django.core.management import setup_environ

setup_environ(settings)

from main.models import *
from tutoring.models import Tutoring

first_name = sys.argv[1] #raw_input("User's first name: ")
last_name = sys.argv[2] #raw_input("User's last name: ")

print first_name + " " + last_name

user = User.objects.get(first_name=first_name, last_name=last_name)
foo = Tutoring.with_weeks(user.profile, term=Settings.objects.term()) #with_weeks uses create, so we don't need to worry about saving

print "Tutoring object: " + str(foo) + " created for " + first_name + " " + last_name