view def edit_app_browser request app_name print request POST browsers

 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
#view:
def edit_app_browser(request, app_name):
print request.POST
browsers = Browser.objects.all()
app = Application.objects.get_or_create(name=app_name)[0]
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["app_name"] = app_name
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 render_to_response("edit_app_browsers.html", stuff)
# template:
{% for sb in supported_browsers %}
<form action="." method="post" id="add_form">
"{{ app_name }}" application supports "{{ sb }}" web browser.
<input type="submit" name="{{ sb }}" value="Remove">
{{ sb }} web browser support.
</form>
<p>
{% endfor %}
{% for nsb in not_supported_browsers %}
<form action="." method="post" id="add_form">
"{{ app_name }}" application does not support "{{ nsb }}" web browser.
<input type="submit" name="{{ nsb }}" value="Add">
{{ nsb }} web browser support.
</form>
<p>
{% endfor %}