source: django_apps/foobar/views.py@ 406

Last change on this file since 406 was 302, checked in by Rick van der Zwet, 14 years ago

Some awefull hack to get a 2x2 single value table displayed for easy editing...

File size: 1.5 KB
Line 
1from django.core import serializers
2from django.http import HttpResponse
3from django.template import RequestContext
4
5from django.shortcuts import render_to_response, get_object_or_404
6from foobar.models import Service, Role, Alert
7
8from django.forms import ModelForm
9from django.forms.models import modelformset_factory
10
11
12
13# Create your views here.
14def index(request):
15 if request.POST.has_key('roles'):
16 for role in request.POST['roles'].split(','):
17 for service in request.POST['services'].split(','):
18 alert = Alert.objects.get(role__name=role,service__name=service)
19 if request.POST.has_key('%s-%s' % (role, service)):
20 alert.enable = True
21 else:
22 alert.enable = False
23 alert.save()
24
25 service_list = Service.objects.all()
26 role_list = Role.objects.all()
27 alert_list = Alert.objects.all()
28 AlertFormSet = modelformset_factory(Alert, extra=0)
29 formset = AlertFormSet(queryset=Alert.objects.all())
30 data = { 'data' : {},
31 'roles' : ','.join(map(str,Role.objects.all())),
32 'services' : ','.join(map(str,Service.objects.all()))}
33 for role in role_list:
34 data['data'][role] = {}
35 for service in service_list:
36 data['data'][role][service] = Alert.objects.get(role=role,service=service).enable
37
38 return render_to_response('foobar/index.html', { 'service_list' : service_list, 'role_list' : role_list, 'alert_list' : alert_list, 'formset' : formset, 'data' : data }, context_instance=RequestContext(request))
Note: See TracBrowser for help on using the repository browser.