@login_required
def add_question(request):
    context = {}

    settings = Settings.get_by_user(request.user)
    initial = {}

    if settings.group:
        initial["groups"] = [settings.group.id]

    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.added_by = request.user
            question.save()

            revision = QuestionRevision(
                question=question, user=request.user,
                text=form.cleaned_data["body"], active=True)
            revision.save()
            return HttpResponseRedirect("/question/%s" % question.id)
    else:
        form = QuestionForm(initial=initial)

    context["form"] = form


    return r2r(request, "add_question", context)
dataset/ETHPy150Open dropbox/questions/questions/views.py/add_question/original