Ejemplo n.º 1
0
def edit_element(request, feature_id, package_id, template_name="grid/edit_element.html"):

    if not request.user.get_profile().can_edit_grid_element:
        return HttpResponseForbidden("permission denied")
    
    feature = get_object_or_404(Feature, pk=feature_id)
    grid_package = get_object_or_404(GridPackage, pk=package_id)    

    # Sanity check to make sure both the feature and grid_package are related to
    # the same grid!
    if feature.grid_id != grid_package.grid_id:
        raise Http404

    element, created = Element.objects.get_or_create(
                                    grid_package=grid_package,
                                    feature=feature
                                    )    
        
    form = ElementForm(request.POST or None, instance=element)

    if form.is_valid():
        element = form.save()        
        return HttpResponseRedirect(reverse('grid', kwargs={'slug': feature.grid.slug}))

    return render(request, template_name, { 
        'form': form,
        'feature':feature,
        'package':grid_package.package,
        'grid':feature.grid
        })        
Ejemplo n.º 2
0
def edit_element(request,
                 feature_id,
                 package_id,
                 template_name="grid/edit_element.html"):

    feature = get_object_or_404(Feature, pk=feature_id)
    grid_package = get_object_or_404(GridPackage, pk=package_id)

    # Sanity check to make sure both the feature and grid_package are related to
    # the same grid!
    if feature.grid_id != grid_package.grid_id:
        raise Http404

    element, created = Element.objects.get_or_create(grid_package=grid_package,
                                                     feature=feature)

    form = ElementForm(request.POST or None, instance=element)

    if form.is_valid():
        element = form.save()
        return HttpResponseRedirect(
            reverse('grid', kwargs={'slug': feature.grid.slug}))

    return render_to_response(template_name, {
        'form': form,
        'feature': feature,
        'package': grid_package.package,
        'grid': feature.grid
    },
                              context_instance=RequestContext(request))