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 })
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))
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))
def edit_element(request, feature_id, package_id, template_name="grid/edit_element.html"): feature = get_object_or_404(Feature, id=feature_id) grid_package = get_object_or_404(GridPackage, id=package_id) element = get_object_or_404(Element, feature=feature, grid_package=grid_package) 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))
def edit_element(request, feature_id, hack_id, template_name="grid/edit_element.html"): feature = get_object_or_404(Feature, pk=feature_id) grid_hack = get_object_or_404(GridHack, pk=hack_id) # Sanity check to make sure both the feature and grid_hack are related to # the same grid! if feature.grid_id != grid_hack.grid_id: raise Http404 element, created = Element.objects.get_or_create(grid_hack=grid_hack, 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, "hack": grid_hack.hack, "grid": feature.grid}, context_instance=RequestContext(request), )