Example #1
0
def edit_answer_sign_up(request, slug, answer_id):
    sign_up = get_object_or_404(Signup, project__slug=slug)
    answer = get_object_or_404(sign_up.answers, id=answer_id)
    if not answer.can_edit(request.user):
        return http.HttpResponseForbidden(_("You can't edit this answer"))
    profile = answer.author
    if request.method == 'POST':
        form = SignupAnswerForm(request.POST, instance=answer)
        profile_form = ProfileEditForm(request.POST, instance=profile)
        profile_image_form = ProfileImageForm()
        if form.is_valid() and profile_form.is_valid():
            profile = profile_form.save(commit=False)
            answer = form.save(commit=False)
            if 'show_preview' not in request.POST:
                profile.save()
                answer.save()
                messages.success(request, _('Answer updated!'))
                return http.HttpResponseRedirect(answer.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        profile_form = ProfileEditForm(instance=profile)
        profile_image_form = ProfileImageForm()
        form = SignupAnswerForm(instance=answer)
    return render_to_response('signups/answer_sign_up.html', {
        'profile_image_form': profile_image_form,
        'profile_form': profile_form,
        'profile': profile,
        'form': form,
        'project': sign_up.project,
        'sign_up': sign_up,
        'answer': answer,
        'preview': ('show_preview' in request.POST),
    }, context_instance=RequestContext(request))
Example #2
0
def edit_answer_sign_up(request, slug, answer_id):
    sign_up = get_object_or_404(Signup, project__slug=slug)
    answer = get_object_or_404(sign_up.answers, id=answer_id)
    if not answer.can_edit(request.user):
        return http.HttpResponseForbidden(_("You can't edit this answer"))
    profile = answer.author
    if request.method == "POST":
        form = SignupAnswerForm(request.POST, instance=answer)
        profile_form = ProfileEditForm(request.POST, instance=profile)
        profile_image_form = ProfileImageForm()
        if form.is_valid() and profile_form.is_valid():
            profile = profile_form.save(commit=False)
            answer = form.save(commit=False)
            if "show_preview" not in request.POST:
                profile.save()
                answer.save()
                messages.success(request, _("Answer updated!"))
                return http.HttpResponseRedirect(answer.get_absolute_url())
        else:
            messages.error(request, _("Please correct errors below."))
    else:
        profile_form = ProfileEditForm(instance=profile)
        profile_image_form = ProfileImageForm()
        form = SignupAnswerForm(instance=answer)
    return render_to_response(
        "signups/answer_sign_up.html",
        {
            "profile_image_form": profile_image_form,
            "profile_form": profile_form,
            "profile": profile,
            "form": form,
            "project": sign_up.project,
            "sign_up": sign_up,
            "answer": answer,
            "preview": ("show_preview" in request.POST),
        },
        context_instance=RequestContext(request),
    )
Example #3
0
def answer_sign_up(request, slug):
    sign_up = get_object_or_404(Signup, project__slug=slug)
    project = sign_up.project
    profile = request.user.get_profile()
    is_organizing = project.organizers().filter(user=profile).exists()
    is_participating = project.participants().filter(user=profile).exists()
    if is_organizing or is_participating:
        messages.error(request,
            _("You already joined this %s.") % project.kind)
        return http.HttpResponseRedirect(sign_up.get_absolute_url())
    elif sign_up.status == Signup.CLOSED:
        msg = _("Sign-up is currently closed." \
                "You can clone the %s if is full.")
        messages.error(request, msg % project.kind)
        return http.HttpResponseRedirect(sign_up.get_absolute_url())
    else:
        answers = sign_up.answers.filter(deleted=False, accepted=False,
            author=profile)
        if answers.exists():
            messages.error(request,
                _("You already posted an answer to the signup questions."))
            return http.HttpResponseRedirect(answers[0].get_absolute_url())
    answer = None
    if request.method == 'POST':
        form = SignupAnswerForm(request.POST)
        profile_form = ProfileEditForm(request.POST, instance=profile)
        profile_image_form = ProfileImageForm()
        if form.is_valid() and profile_form.is_valid():
            profile = profile_form.save()
            answer = form.save(commit=False)
            answer.sign_up = sign_up
            answer.author = profile
            if 'show_preview' not in request.POST:
                profile.save()
                new_rel, created = Relationship.objects.get_or_create(
                    source=profile, target_project=project)
                new_rel.deleted = False
                new_rel.save()
                answer.save()
                if sign_up.status == Signup.NON_MODERATED:
                    answer.accept()
                    messages.success(request, _('You are now a participant!'))
                else:
                    messages.success(request, _('Answer submitted!'))
                return http.HttpResponseRedirect(answer.get_absolute_url())
        else:
            messages.error(request, _('Please correct errors below.'))
    else:
        profile_form = ProfileEditForm(instance=profile)
        profile_image_form = ProfileImageForm()
        form = SignupAnswerForm()
    return render_to_response('signups/answer_sign_up.html', {
        'profile_image_form': profile_image_form,
        'profile_form': profile_form,
        'profile': profile,
        'form': form,
        'project': project,
        'sign_up': sign_up,
        'answer': answer,
        'create': True,
        'preview': ('show_preview' in request.POST),
    }, context_instance=RequestContext(request))