Exemplo n.º 1
0
def ui_state(request):
    """
    gets or sets interface state. only states of the current user are listed
    """
    c = RequestContext(request)
    out = createBaseResponseObject()
    
    if request.POST:
        oid = request.POST.get('oid', None)
        state_name = request.POST.get('state_name', None)
        description = request.POST.get('description', None)
        state = request.POST.get('state', None)
        
        try:
            obj = InterfaceState.objects.get(oid=oid, user=request.user)
            if description:
                obj.description = description
            if name:
                obj.state_name = state_name
                
            obj.state = state
            obj.save()
            out['results'].append(instanceDict(obj))   
        except:
            obj = InterfaceState(state_name = state_name, user=request.user, state=state, 
                                  description=description, oid=oid)
            try:
                obj.save()
                out['results'].append(instanceDict(obj))                    
            except Exception, e:
                out['errors'].append(str(e))
                out['status'] = 0
Exemplo n.º 2
0
def ui_states(request):
    """
    get all ui_states for the current user
    """
    out = createBaseResponseObject()
    qset = InterfaceState.objects.filter(user=request.user)
    for o in qset:
        out['results'].append(instanceDict(o))
    
    return HttpResponse(json.dumps(out, cls=DjangoJSONEncoder))
Exemplo n.º 3
0
def ui_stage(request, state_id):
    state = InterfaceState.objects.get(pk=state_id)
    c = RequestContext(request)
    return render_to_response("ui/stage.html", { 'state': json.dumps(instanceDict(state), cls=DjangoJSONEncoder) }, context_instance = c)
Exemplo n.º 4
0
                obj.save()
                out['results'].append(instanceDict(obj))                    
            except Exception, e:
                out['errors'].append(str(e))
                out['status'] = 0
            
    else:

        oid = request.GET.get('oid', None)
        if not oid:
            out['errors'].append("You must query a state oid")
            out['status'] = 0
        else:
            try:
                obj = InterfaceState.objects.get(oid=oid, user=request.user)
                out['results'].append(instanceDict(obj))
            except Exception, e:
                out['errors'].append(str(e))
                out['status'] = 0

    return HttpResponse(json.dumps(out, cls=DjangoJSONEncoder))
    
@login_required(login_url="/login/")    
def ui_states(request):
    """
    get all ui_states for the current user
    """
    out = createBaseResponseObject()
    qset = InterfaceState.objects.filter(user=request.user)
    for o in qset:
        out['results'].append(instanceDict(o))