# Path: tsuru_autoscale/action/forms.py
# class ActionForm(forms.Form):
#     name = forms.CharField()
#     url = forms.CharField()
#     method = forms.CharField()
#     body = forms.CharField(required=False)
#     headers = forms.CharField(required=False)
# 
# Path: tsuru_autoscale/action/client.py
# def host():
# def new(data, token):
# def list(token):
# def remove(name, token):
# def get(name, token):


from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from tsuru_autoscale.action.forms import ActionForm
from tsuru_autoscale.action import client
        token = request.GET.get("TSURU_TOKEN")
        client.new(form.cleaned_data, token)
        messages.success(request, u"Action saved.")
        url = "{}?TSURU_TOKEN={}".format(reverse('action-list'), token)
        return redirect(url)

    context = {"form": form}
    return render(request, "action/new.html", context)


def list(request):
    token = request.GET.get("TSURU_TOKEN")
    actions = client.list(token).json()
    context = {
        "list": actions,
    }
    return render(request, "action/list.html", context)


def get(request, name):
    token = request.GET.get("TSURU_TOKEN")
    action = client.get(name, token).json()
    context = {
        "item": action,
    }
    return render(request, "action/get.html", context)


def remove(request, name):
    token = request.GET.get("TSURU_TOKEN")

# Path: tsuru_autoscale/action/forms.py
# class ActionForm(forms.Form):
#     name = forms.CharField()
#     url = forms.CharField()
#     method = forms.CharField()
#     body = forms.CharField(required=False)
#     headers = forms.CharField(required=False)
# 
# Path: tsuru_autoscale/action/client.py
# def host():
# def new(data, token):
# def list(token):
# def remove(name, token):
# def get(name, token):


# Path: tsuru_autoscale/action/views.py
from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from tsuru_autoscale.action.forms import ActionForm
from tsuru_autoscale.action import client

        token = request.GET.get("TSURU_TOKEN")
        client.new(form.cleaned_data, token)
        messages.success(request, u"Action saved.")
        url = "{}?TSURU_TOKEN={}".format(reverse('action-list'), token)
        return redirect(url)

    context = {"form": form}
    return render(request, "action/new.html", context)


def list(request):
    token = request.GET.get("TSURU_TOKEN")
    actions = client.list(token).json()
    context = {
        "list": actions,
    }
    return render(request, "action/list.html", context)


def get(request, name):
    token = request.GET.get("TSURU_TOKEN")
    action = client.get(name, token).json()
    context = {
        "item": action,
    }
    return render(request, "action/get.html", context)


def remove(request, name):
    token = request.GET.get("TSURU_TOKEN")

    client.remove(name, token)