def edit_app request app_name app Application objects get_or_create na

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def edit_app(request, app_name):
app = Application.objects.get_or_create(name=app_name)[0]
stuff = {}
stuff['app_name'] = app_name
stuff.update( edit_app_type(request, app) )
stuff.update( edit_app_brws(request, app) )
return render_to_response("edit_application.html", stuff)
def edit_app_type(request, app):
types = [ t[1] for t in Application.TYPE_CHOICES ]
if request.POST:
for type in types:
if request.POST.has_key(type):
app.type = type
app.save()
if request.POST.has_key('change'):
app.type = ""
app.save()
has_type = bool(app.type)
stuff = {}
stuff['app_type'] = app.type
stuff['has_type'] = has_type
stuff['types'] = types
return stuff
def edit_app_brws(request, app):
browsers = Browser.objects.all()
if request.POST:
for b in browsers:
if request.POST.get(unicode(b)) == 'Add':
app.browsers.add(b)
if request.POST.get(unicode(b)) == 'Remove':
app.browsers.remove(b)
stuff = {}
stuff['supported_browsers'] = [ b for b in app.browsers.all() ]
stuff['not_supported_browsers'] = [ b for b in browsers if b not in app.browsers.all() ]
return stuff