def location_edit(request, location_id, response_format='html'): "Location edit page" location = get_object_or_404(Location, pk=location_id) if not request.user.get_profile().has_permission(location, mode="w"): return user_denied(request, message="You don't have write access to this Location", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = LocationForm( request.user.get_profile(), None, request.POST, instance=location) if form.is_valid(): location = form.save(request) return HttpResponseRedirect(reverse('infrastructure_location_view', args=[location.id])) else: return HttpResponseRedirect(reverse('infrastructure_location_view', args=[location.id])) else: form = LocationForm( request.user.get_profile(), None, instance=location) context = _get_default_context(request) context.update({'location': location, 'form': form}) return render_to_response('infrastructure/location_edit', context, context_instance=RequestContext(request), response_format=response_format)
def location_add(request, response_format='html'): "New location form" if request.POST: if not 'cancel' in request.POST: location = Location() form = LocationForm(request.user.get_profile(), None, request.POST, instance=location) if form.is_valid(): location = form.save() location.set_user_from_request(request) return HttpResponseRedirect( reverse('identities_location_view', args=[location.id])) else: return HttpResponseRedirect(reverse('identities_index')) else: form = LocationForm(request.user.get_profile(), None) context = _get_default_context(request) context.update({'form': form}) return render_to_response('identities/location_add', context, context_instance=RequestContext(request), response_format=response_format)
def location_edit(request, location_id, response_format='html'): "Location edit page" location = get_object_or_404(Location, pk=location_id) if not request.user.get_profile().has_permission(location, mode="w"): return user_denied( request, message="You don't have write access to this Location", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = LocationForm(request.user.get_profile(), None, request.POST, instance=location) if form.is_valid(): location = form.save(request) return HttpResponseRedirect( reverse('identities_location_view', args=[location.id])) else: return HttpResponseRedirect( reverse('identities_location_view', args=[location.id])) else: form = LocationForm(request.user.get_profile(), None, instance=location) context = _get_default_context(request) context.update({'location': location, 'form': form}) return render_to_response('identities/location_edit', context, context_instance=RequestContext(request), response_format=response_format)
def location_add(request, response_format='html'): "New location form" if request.POST: if not 'cancel' in request.POST: location = Location() form = LocationForm(request.user.get_profile(), None, request.POST, instance=location) if form.is_valid(): location = form.save() location.set_user_from_request(request) return HttpResponseRedirect(reverse('identities_location_view', args=[location.id])) else: return HttpResponseRedirect(reverse('identities_index')) else: form = LocationForm(request.user.get_profile(), None) context = _get_default_context(request) context.update({'form': form}) return render_to_response('identities/location_add', context, context_instance=RequestContext(request), response_format=response_format)