示例#1
0
def add_grid_package(request, grid_slug, template_name="grid/add_grid_package.html"):
    """Add an existing package to this grid."""

    if not request.user.get_profile().can_add_grid_package:
        return HttpResponseForbidden("permission denied")

    grid = get_object_or_404(Grid, slug=grid_slug)
    grid_package = GridPackage()
    form = GridPackageForm(request.POST or None, instance=grid_package)    

    if form.is_valid(): 
        package = get_object_or_404(Package, id=request.POST['package'])    
        try:
            GridPackage.objects.get(grid=grid, package=package)
            message = "Sorry, but '%s' is already in this grid." % package.title
            messages.add_message(request, messages.ERROR, message)            
        except GridPackage.DoesNotExist:
            grid_package = GridPackage(
                        grid=grid, 
                        package=package
                    )
            grid_package.save()
            redirect = request.POST.get('redirect','')
            if redirect:
                return HttpResponseRedirect(redirect)
            
            return HttpResponseRedirect(reverse('grid', kwargs={'slug':grid.slug}))
    


    return render(request, template_name, { 
        'form': form,
        'grid': grid
        })
示例#2
0
def add_grid_package(request,
                     grid_slug,
                     template_name="grid/add_grid_package.html"):

    grid = get_object_or_404(Grid, slug=grid_slug)
    grid_package = GridPackage()
    form = GridPackageForm(request.POST or None, instance=grid_package)
    message = ''

    if form.is_valid():
        package = get_object_or_404(Package, id=request.POST['package'])
        try:
            GridPackage.objects.get(grid=grid, package=package)
            message = "Sorry, but '%s' is already in this grid." % package.title
        except GridPackage.DoesNotExist:
            package = GridPackage(grid=grid, package=package)
            package.save()
            redirect = request.POST.get('redirect', '')
            if redirect:
                return HttpResponseRedirect(redirect)

            return HttpResponseRedirect(
                reverse('grid', kwargs={'slug': grid.slug}))

    return render_to_response(template_name, {
        'form': form,
        'grid': grid,
        'message': message
    },
                              context_instance=RequestContext(request))
示例#3
0
def add_grid_package(request, grid_slug, template_name="grid/add_grid_package.html"):
    """Add an existing package to this grid."""

    grid = get_object_or_404(Grid, slug=grid_slug)
    grid_package = GridPackage()
    form = GridPackageForm(request.POST or None, instance=grid_package)    
    message = ''

    if form.is_valid(): 
        package = get_object_or_404(Package, id=request.POST['package'])    
        try:
            GridPackage.objects.get(grid=grid, package=package)
            message = "Sorry, but '%s' is already in this grid." % package.title
        except GridPackage.DoesNotExist:
            grid_package = GridPackage(
                        grid=grid, 
                        package=package
                    )
            grid_package.save()
            redirect = request.POST.get('redirect','')
            if redirect:
                return HttpResponseRedirect(redirect)
            
            return HttpResponseRedirect(reverse('grid', kwargs={'slug':grid.slug}))
    


    return render_to_response(template_name, { 
        'form': form,
        'grid': grid,
        'message': message
        },
        context_instance=RequestContext(request))
示例#4
0
def add_grid_package(request, grid_slug, template_name="grid/add_grid_package.html"):
    """Add an existing package to this grid."""

    if not request.user.get_profile().can_add_grid_package:
        return HttpResponseForbidden("permission denied")

    grid = get_object_or_404(Grid, slug=grid_slug)
    grid_package = GridPackage()
    form = GridPackageForm(request.POST or None, instance=grid_package)    

    if form.is_valid(): 
        package = get_object_or_404(Package, id=request.POST['package'])    
        try:
            GridPackage.objects.get(grid=grid, package=package)
            message = "Sorry, but '%s' is already in this grid." % package.title
            messages.add_message(request, messages.ERROR, message)            
        except GridPackage.DoesNotExist:
            grid_package = GridPackage(
                        grid=grid, 
                        package=package
                    )
            grid_package.save()
            redirect = request.POST.get('redirect','')
            if redirect:
                return HttpResponseRedirect(redirect)
            
            return HttpResponseRedirect(reverse('grid', kwargs={'slug':grid.slug}))
    


    return render(request, template_name, { 
        'form': form,
        'grid': grid
        })