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