def service_add(request, response_format='html'): "Service add" if not request.user.get_profile().is_admin('maker.services'): return user_denied(request, message="You don't have administrator access to the Service Support module") if request.POST: if not 'cancel' in request.POST: service = Service() form = ServiceForm(request.user.get_profile(), request.POST, instance=service) if form.is_valid(): service = form.save() service.set_user_from_request(request) return HttpResponseRedirect(reverse('services_service_view', args=[service.id])) else: return HttpResponseRedirect(reverse('services')) else: form = ServiceForm(request.user.get_profile()) context = _get_default_context(request) context.update({'form': form}) return render_to_response('services/service_add', context, context_instance=RequestContext(request), response_format=response_format)
def service_edit(request, service_id, response_format='html'): "Service edit" service = get_object_or_404(Service, pk=service_id) if not request.user.get_profile().has_permission(service, mode='w') \ and not request.user.get_profile().is_admin('maker_services'): return user_denied(request, message="You don't have access to this Service") if request.POST: if not 'cancel' in request.POST: form = ServiceForm(request.user.get_profile(), request.POST, instance=service) if form.is_valid(): service = form.save() return HttpResponseRedirect(reverse('services_service_view', args=[service.id])) else: return HttpResponseRedirect(reverse('services_service_view', args=[service.id])) else: form = ServiceForm(request.user.get_profile(), instance=service) context = _get_default_context(request) context.update({'form': form, 'service': service}) return render_to_response('services/service_edit', context, context_instance=RequestContext(request), response_format=response_format)