Пример #1
0
def accept_sign_up(request, slug, comment_id, as_organizer=False):
    page = get_object_or_404(Page, project__slug=slug, slug='sign-up')
    project = page.project
    answer = page.comments.get(pk=comment_id)
    organizing = project.organizers().filter(user=answer.author.user).exists()
    participating = project.participants().filter(user=answer.author.user).exists()
    if answer.reply_to or organizing or participating or request.method != 'POST':
        return HttpResponseForbidden(_("You can't see this page"))
    participation = Participation(project=project, user=answer.author, organizing=as_organizer)
    participation.save()
    new_rel = Relationship(source=answer.author, target_project=project)
    try:
        new_rel.save()
    except IntegrityError:
        pass
    accept_content = detail_description_content = render_to_string(
            "content/accept_sign_up_comment.html",
            {'as_organizer': as_organizer})
    accept_comment = PageComment(content=accept_content, 
        author = request.user.get_profile(), page = page, reply_to = answer, 
        abs_reply_to = answer)
    accept_comment.save()
    if as_organizer:
        messages.success(request, _('Organizer added!'))
    else:
        messages.success(request, _('Participant added!'))
    return HttpResponseRedirect(answer.get_absolute_url())
Пример #2
0
def accept_sign_up(request, slug, comment_id):
    page = get_object_or_404(Page, project__slug=slug, slug='sign-up')
    project = page.project
    user = request.user.get_profile()
    answer = page.comments.get(pk=comment_id)
    if answer.reply_to or answer.author == project.created_by or request.method != 'POST':
        return HttpResponseForbidden()
    try:
        participation = answer.participation
        return HttpResponseForbidden()
    except Participation.DoesNotExist:
        pass
    try:
        participation = project.participants().get(user=answer.author)
        if participation.sign_up:
            participation.left_on = datetime.datetime.now()
            participation.save()
            raise Participation.DoesNotExist
        else:
            participation.sign_up = answer
    except Participation.DoesNotExist:
        participation = Participation(project= project, user=answer.author, sign_up=answer)
    participation.save()
    new_rel = Relationship(source=answer.author, target_project=project)
    try:
        new_rel.save()
    except IntegrityError:
        pass
    accept_content = detail_description_content = render_to_string(
            "content/accept_sign_up_comment.html",
            {})
    accept_comment = PageComment(content=accept_content, author=user,
        page=page, reply_to=answer, abs_reply_to=answer)
    accept_comment.save()
    messages.success(request, _('Participant added!'))
    return HttpResponseRedirect(answer.get_absolute_url())