def edit(request, host_name): """ Edit all the Service "__MACROS" for a given host """ c = {} c['errors'] = [] c['messages'] = [] c.update(csrf(request)) c['hostname'] = host_name c['host_name'] = host_name c['forms'] = myforms = [] try: c['myhost'] = Model.Host.objects.get_by_shortname(host_name) except KeyError as e: c['errors'].append(_("Host %s not found") % e) return render_to_response('edittemplate.html', c, context_instance=RequestContext(request)) # Get all services of that host that contain a service_description services = Model.Service.objects.filter(host_name=host_name, service_description__contains='') if request.method == 'GET': for service in services: myforms.append(forms.EditTemplateForm(service=service)) elif request.method == 'POST': # All the form fields have an id of HOST::SERVICE::ATTRIBUTE for service in services: form = forms.EditTemplateForm(service=service, data=request.POST) myforms.append(form) if form.is_valid(): try: if form.changed_data != []: form.save() c['messages'].append( _("'%s' successfully saved.") % service.get_description()) except Exception as e: c['errors'].append( _("Failed to save service %(service)s: %(exc)s") % { 'service': service.get_description(), 'exc': e }) else: c['errors'].append( _('invalid data in %s') % service.get_description()) c['forms'] = myforms return render_to_response('edittemplate.html', c, context_instance=RequestContext(request))
c['forms'] = myforms = [] try: c['myhost'] = Model.Host.objects.get_by_shortname(host_name) except KeyError, e: c['errors'].append("Host %s not found" % e) return render_to_response('edittemplate.html', c, context_instance=RequestContext(request)) # Get all services of that host that contain a service_description services = Model.Service.objects.filter(host_name=host_name, service_description__contains='') if request.method == 'GET': for service in services: myforms.append(forms.EditTemplateForm(service=service)) elif request.method == 'POST': # All the form fields have an id of HOST::SERVICE::ATTRIBUTE for service in services: form = forms.EditTemplateForm(service=service, data=request.POST) myforms.append(form) if form.is_valid(): try: if form.changed_data != []: form.save() c['messages'].append("'%s' successfully saved." % service.get_description()) except Exception, e: c['errors'].append("Failed to save service %s: %s" % (service.get_description(), e)) else: