def new_app(request, type): data = {} if request.method == 'POST': data['msg'] = "Post" post_params = {} for key in request.POST: if key.startswith("filehidden"): fkey = key[11:] if (request.FILES.get(fkey, None)): post_file = request.FILES[fkey] file_content = "" for chunk in post_file.chunks(): file_content += chunk.decode("utf8") post_params[fkey] = convert(file_content) else: post_params[fkey] = request.POST[key] else: post_params[key] = request.POST[key] template = Template.objects.get(pk=post_params['template_id']) content = template.content % post_params data['content'] = content mc = MarathonClient('http://{}:{}'.format(settings.MARATHON['host'], settings.MARATHON['port'])) try: if (type == "app"): mc.create_app_by_json(content) elif (type == "group"): mc.create_group(content) data['result'] = "Success" except Exception as e: data['result'] = str(e) if (type == "app"): data['type'] = "Application" templates = Template.objects.filter( type="marathon-app").order_by('name').all() elif (type == "group"): data['type'] = "Group" templates = Template.objects.filter( type="marathon-group").order_by('name').all() for template in templates: template.params = template.param_set.order_by('id') data['templates'] = templates return render(request, 'marathon_mgmt/new_app.html', data)
def new_app(request, type): data = {} if request.method == 'POST': data['msg'] = "Post" post_params = {} for key in request.POST: if key.startswith("filehidden"): fkey = key[11:] if(request.FILES.get(fkey, None)): post_file = request.FILES[fkey] file_content="" for chunk in post_file.chunks(): file_content += chunk.decode("utf8") post_params[fkey] = convert(file_content) else: post_params[fkey] = request.POST[key] else: post_params[key] = request.POST[key] template = Template.objects.get(pk=post_params['template_id']) content = template.content%post_params data['content'] = content mc = MarathonClient('http://{}:{}'.format(settings.MARATHON['host'], settings.MARATHON['port'])) try: if(type == "app"): mc.create_app_by_json(content) elif(type == "group"): mc.create_group(content) data['result'] = "Success" except Exception as e: data['result'] = str(e) if(type == "app"): data['type'] = "Application" templates = Template.objects.filter(type="marathon-app").order_by('name').all() elif(type == "group"): data['type'] = "Group" templates = Template.objects.filter(type="marathon-group").order_by('name').all() for template in templates: template.params = template.param_set.order_by('id') data['templates'] = templates return render(request, 'marathon_mgmt/new_app.html', data)