Ejemplo n.º 1
0
def corkboard_detail(request, slug, template_name="loupe/corkboard_detail.html"):
    """
    Displays the corkboard and all it's associated images
    to the user

    expects a slug and expects the user has access to the parent project
    """

    corkboard = get_object_or_404(Corkboard, slug=slug)
    if not request.user.is_staff:
        if request.user != 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'))
        
    images = Image.objects.filter(corkboard=corkboard)

    form = ImageForm()
    
    if request.method == "POST":
        form = ImageForm(request.user, request.POST, request.FILES)
        if form.is_valid():
            image = form.save(commit=False)
            image.user = request.user
            image.corkboard = corkboard
            image.save()
            request.user.message_set.create(message=_("Successfully uploaded image '%s'") % image.title)
    
    return render_to_response(template_name, {
        "corkboard": corkboard,
        "form": form,
        "images": images,
    }, context_instance=RequestContext(request))
def corkboard_detail(request, slug, template_name="loupe/corkboard_detail.html"):
    """
    Displays the corkboard and all it's associated images
    to the user

    expects a slug and expects the user has access to the parent project
    """

    if not request.user.is_staff:
        corkboard = get_object_or_404(Corkboard, slug=slug, project__members=request.user)
    else:
        corkboard = get_object_or_404(Corkboard, slug=slug)

    images = Image.objects.filter(corkboard=corkboard)

    form = ImageForm()

    if request.method == "POST":
        form = ImageForm(request.user, request.POST, request.FILES)
        if form.is_valid():
            image = form.save(commit=False)
            image.user = request.user
            image.corkboard = corkboard
            image.save()
            if notification:
                notification.send_now(
                    corkboard.project.members.all(),
                    "corkboard_new_image",
                    {
                        "user": request.user,
                        "corkboard": corkboard,
                        "image_url": image.get_absolute_url,
                        "corkboard_url": corkboard.get_absolute_url,
                    },
                )

            request.user.message_set.create(message=_("Successfully uploaded image '%s'") % image.title)

    return render_to_response(
        template_name,
        {"corkboard": corkboard, "form": form, "images": images},
        context_instance=RequestContext(request),
    )
Ejemplo n.º 3
0
def corkboard_detail(request,
                     slug,
                     template_name="loupe/corkboard_detail.html"):
    """
    Displays the corkboard and all it's associated images
    to the user

    expects a slug and expects the user has access to the parent project
    """

    if not request.user.is_staff:
        corkboard = get_object_or_404(Corkboard,
                                      slug=slug,
                                      project__members=request.user)
    else:
        corkboard = get_object_or_404(Corkboard, slug=slug)

    images = Image.objects.filter(corkboard=corkboard)

    form = ImageForm()

    if request.method == "POST":
        form = ImageForm(request.user, request.POST, request.FILES)
        if form.is_valid():
            image = form.save(commit=False)
            image.user = request.user
            image.corkboard = corkboard
            image.save()
            if notification:
                notification.send_now(
                    corkboard.project.members.all(), "corkboard_new_image", {
                        "user": request.user,
                        "corkboard": corkboard,
                        "image_url": image.get_absolute_url,
                        "corkboard_url": corkboard.get_absolute_url
                    })

            request.user.message_set.create(
                message=_("Successfully uploaded image '%s'") % image.title)

    return render_to_response(template_name, {
        "corkboard": corkboard,
        "form": form,
        "images": images,
    },
                              context_instance=RequestContext(request))