Beispiel #1
0
def create_user(request):
    if request.method == "POST":
        user_create_form = UserCreationForm(request.POST)
        profile_form = ProfileForm(request.POST)
        if user_create_form.is_valid():
            user = user_create_form.save()
            if profile_form.is_valid():
                profile = Profile.objects.get(user=user)
                profile.language_pref_id = profile_form.cleaned_data["language"]
                profile.save()
            return HttpResponseRedirect("/login/")
    else:
        user_create_form = UserCreationForm()
        profile_form = ProfileForm()
    context = {"user_create_form": user_create_form, "user_profile_form": profile_form}
    return render_to_response("user_management/create.html", context, RequestContext(request))
Beispiel #2
0
def status(request):
    query = {}
    if request.user.is_authenticated():
        query["student"] = request.user
    else:
        query["anon_student"] = request.session.session_key

    if request.method == "POST":
        user_profile_form = ProfileForm(request.POST)
        if user_profile_form.is_valid():
            language_id = user_profile_form.cleaned_data["language"]
            changed = False
            if request.user.is_authenticated():
                profile = Profile.objects.get(user=request.user)
                changed = profile.language_pref_id != language_id
                profile.language_pref_id = language_id
                profile.save()
            else:
                changed = request.session.get("language_id") != language_id
                request.session["language_id"] = language_id
            # clear the session progress, if our language has changed
            if changed:
                SessionProgress.objects.filter(**query).delete()
    else:
        # FIXME - move the setting of the language to the cont
        if request.user.is_authenticated():
            profile = Profile.objects.get(user=request.user)
            language_id = profile.language_pref_id
        else:
            language_id = request.session.get("language_id", "")
        user_profile_form = ProfileForm(language=language_id)
    context = {}
    progress = Progress.objects.filter(**query).order_by("-correct")
    context["progress"] = progress
    context["user_profile_form"] = user_profile_form
    return render_to_response("minerva/statistics.html", context, RequestContext(request))