Example #1
0
def create_profile(request):
    "Create a profile if none exists."
    try:
        profile = request.user.get_profile()
    except ObjectDoesNotExist:
        profile = None

    if profile is not None:
        # a profile already exists, redirect to a read-only view
        return view_profile(request)

    ProfileForm = _get_profile_form()
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            syllabus = usermodel_models.Syllabus.objects.get(
                tag=form.cleaned_data['syllabus'])
            profile = models.UserProfile(
                user=request.user,
                syllabus=syllabus,
                first_language=form.cleaned_data['first_language'],
                second_languages=form.cleaned_data['second_languages'],
            )
            profile.save()
            add_syllabus.add_per_user_models(request.user.username)
            return HttpResponseRedirect(reverse('tutor_dashboard'))
    else:
        form = ProfileForm()

    return render_to_response('user_profile/create_profile.html',
                              {'form': form},
                              context_instance=RequestContext(request))
Example #2
0
def create_profile(request):
    "Create a profile if none exists."
    try:
        profile = request.user.get_profile()
    except ObjectDoesNotExist:
        profile = None
    
    if profile is not None:
        # a profile already exists, redirect to a read-only view
        return view_profile(request)

    ProfileForm = _get_profile_form()
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            syllabus = usermodel_models.Syllabus.objects.get(
                    tag=form.cleaned_data['syllabus'])
            profile = models.UserProfile(
                    user=request.user,
                    syllabus=syllabus,
                    first_language=form.cleaned_data['first_language'],
                    second_languages=form.cleaned_data['second_languages'],
                )
            profile.save()
            add_syllabus.add_per_user_models(request.user.username)
            return HttpResponseRedirect(reverse('tutor_dashboard'))
    else:
        form = ProfileForm()
    
    return render_to_response('user_profile/create_profile.html',
            {'form': form}, context_instance=RequestContext(request))
Example #3
0
def view_profile(request):
    "View an existing profile."
    context = {}
    context['profile'] = request.user.get_profile()
    context['syllabi'] = [s.tag for s in \
            usermodel_models.Syllabus.objects.all()]

    if request.method == 'POST':
        syllabus = usermodel_models.Syllabus.objects.get(
                tag=request.POST['syllabus'])
        profile = request.user.get_profile()
        if syllabus != profile.syllabus:
            profile.syllabus = syllabus
            profile.save()
            add_syllabus.add_per_user_models(request.user.username)
            context['feedback'] = 'Your profile has been updated.'

    return render_to_response('user_profile/view_profile.html',
            context, context_instance=RequestContext(request))
Example #4
0
def view_profile(request):
    "View an existing profile."
    context = {}
    context['profile'] = request.user.get_profile()
    context['syllabi'] = [s.tag for s in \
            usermodel_models.Syllabus.objects.all()]

    if request.method == 'POST':
        syllabus = usermodel_models.Syllabus.objects.get(
            tag=request.POST['syllabus'])
        profile = request.user.get_profile()
        if syllabus != profile.syllabus:
            profile.syllabus = syllabus
            profile.save()
            add_syllabus.add_per_user_models(request.user.username)
            context['feedback'] = 'Your profile has been updated.'

    return render_to_response('user_profile/view_profile.html',
                              context,
                              context_instance=RequestContext(request))