def image_detail(request, id, template_name="loupe/image_detail.html"):
    """
    Displays the image to be discussed by the project members

    expects an id for the image and the user has access to the parent project
    """
    if not request.user.is_staff:
        image = get_object_or_404(Image, pk=id, corkboard__project__members=request.user)
    else:
        image = get_object_or_404(Image, pk=id)

    notes = Note.objects.filter(image=image)
    notes_count = notes.count()
    form = NoteForm()

    if request.method == "POST":
        form = NoteForm(request.user, request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.user = request.user
            note.image = image
            note.save()
            if notification:
                notification.send_now(
                    image.corkboard.project.members.all(),
                    "corkboard_new_image_note",
                    {"user": request.user, "image_url": image.get_absolute_url, "image": image},
                )
            request.user.message_set.create(message=_("Successfully attached note to image '%s'") % image.title)

    return render_to_response(
        template_name,
        {"image": image, "notes": notes, "notes_count": notes_count, "form": form},
        context_instance=RequestContext(request),
    )
Ejemplo n.º 2
0
def image_detail(request, id, template_name="loupe/image_detail.html"):
    """
    Displays the image to be discussed by the project members

    expects an id for the image and the user has access to the parent project
    """

    image = get_object_or_404(Image, pk=id)
    if not request.user.is_staff:
        if request.user != image.corkboard.project.members:
            request.user.message_set.create(message=_("You are trying to access a project you don't have permission to view!"))
            return HttpResponseRedirect(reverse('dashboard'))
    notes = Note.objects.filter(image=image)
    notes_count = notes.count()
    form = NoteForm()

    if request.method == "POST":
        form = NoteForm(request.user, request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.user = request.user
            note.image = image
            note.save()
            request.user.message_set.create(message=_("Successfully attached note to image '%s'") % image.title)
                
    return render_to_response(template_name, {
        "image": image,
        "notes": notes,
        "notes_count": notes_count,
        "form": form,
    }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def image_detail(request, id, template_name="loupe/image_detail.html"):
    """
    Displays the image to be discussed by the project members

    expects an id for the image and the user has access to the parent project
    """
    if not request.user.is_staff:
        image = get_object_or_404(Image,
                                  pk=id,
                                  corkboard__project__members=request.user)
    else:
        image = get_object_or_404(Image, pk=id)

    notes = Note.objects.filter(image=image)
    notes_count = notes.count()
    form = NoteForm()

    if request.method == "POST":
        form = NoteForm(request.user, request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.user = request.user
            note.image = image
            note.save()
            if notification:
                notification.send_now(
                    image.corkboard.project.members.all(),
                    "corkboard_new_image_note", {
                        "user": request.user,
                        "image_url": image.get_absolute_url,
                        "image": image
                    })
            request.user.message_set.create(
                message=_("Successfully attached note to image '%s'") %
                image.title)

    return render_to_response(template_name, {
        "image": image,
        "notes": notes,
        "notes_count": notes_count,
        "form": form,
    },
                              context_instance=RequestContext(request))