Esempio n. 1
0
def add_sls(request):
    _error = ""
    _success = ""
    if request.POST:
        _name = request.POST.get("name", "")
        _content = request.POST.get("content", "")
        _businesses = request.POST.getlist("business", [])
        _informations = request.POST.get("informations", "")
        _enabled = request.POST.get("enabled", "")
        if _enabled == 'true':
            _enabled = True
        else:
            _enabled = False
        if 1:
            _h = Highstate(name=_name,
                           content=_content,
                           informations=_informations,
                           enabled=_enabled)
            _h.save()
            for _b in _businesses:
                _b_object = Businesses.objects.get(name=_b.strip())
                _h.business.add(_b_object)
            _success = "add sls " + _name + " ok!"

        else:
            _error = "name already exists or too long!"

        high = HighState()
        high.add_sls(_name, _content)
    return highstate(request, success=_success, error=_error)
Esempio n. 2
0
def modify_sls(request):
    _success = False
    _error = False
    if request.method == "POST":
        _id = request.POST.get("id")
        _name = request.POST.get("name")
        _businesses = request.POST.getlist("business")
        _content = request.POST.get("content")
        _informations = request.POST.get("informations")
        _enabled = request.POST.get("enabled")
        if _enabled is not None:
            _enabled = True
        else:
            _enabled = False
        #try:
        if 1:
            _highstate = Highstate.objects.get(id=_id)
            _name_before = _highstate.name
            _highstate.name = _name
            _highstate.content = _content
            _highstate.enabled = _enabled
            _highstate.informations = _informations
            _highstate.save()
            for _b in _businesses:
                _b_object = Businesses.objects.get(name=_b.strip())
                _highstate.business.add(_b_object)
            _success = "Modify SLS " + _name + " OK"
        #except Exception as e:
        else:
            _error = "Modify SLS " + _name + " failed"

        high = HighState()
        high.add_sls(_name, _content)

    return highstate(request, success=_success, error=_error)
Esempio n. 3
0
def del_sls(request):
    _success = False
    _error = False
    _ids = request.POST.getlist("id")
    try:
        _filter = Highstate.objects.filter(id__in=_ids)

        high = HighState()
        for sls_name in _filter:
            high.del_sls(sls_name.name)

        _filter.delete()
        _success = "Delete opearation success!"
    except Exception as e:
        _error = "Delete error!"

    return highstate(request, success=_success, error=_error)