def service_record_edit(request, service_record_id, response_format='html'): "ServiceRecord edit page" service_record = get_object_or_404(ItemServicing, pk=service_record_id) if not request.user.get_profile().has_permission(service_record, mode="w"): return user_denied(request, message="You don't have write access to this ServiceRecord", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = ServiceRecordForm(request.user.get_profile(), None, request.POST, instance=service_record) if form.is_valid(): service_record = form.save(request) return HttpResponseRedirect(reverse('infrastructure_service_record_view', args=[service_record.id])) else: return HttpResponseRedirect(reverse('infrastructure_service_record_view', args=[service_record.id])) else: form = ServiceRecordForm(request.user.get_profile(), None, instance=service_record) context = _get_default_context(request) context.update({'service_record': service_record, 'form': form }) return render_to_response('infrastructure/service_record_edit', context, context_instance=RequestContext(request), response_format=response_format)
def service_record_add(request, response_format='html'): "New service_record form" if not request.user.get_profile().is_admin('maker.infrastructure'): return user_denied(request, message="You don't have administrator access to the Infrastructure module") service_record = ItemServicing() if request.POST: if not 'cancel' in request.POST: form = ServiceRecordForm(request.user.get_profile(), service_record, request.POST) if form.is_valid(): record = form.save(request) return HttpResponseRedirect(reverse('infrastructure_service_record_view', args=[record.id])) else: return HttpResponseRedirect(reverse('infrastructure_service_record_index')) else: form = ServiceRecordForm(request.user.get_profile(), service_record) context = _get_default_context(request) context.update({'service_record': service_record, 'form': form}) return render_to_response('infrastructure/service_record_add', context, context_instance=RequestContext(request), response_format=response_format)