Beispiel #1
0
def SchemaView(request):

    fun = FunctionsBase()

    args = {}

    args['username'] = auth.get_user(request).username

    if not args['username']:
        args['user_is_staff'] = False
        return redirect("/auth/login/")
    else:
        if not auth.get_user(request).is_staff:
            return redirect("/")
        args['user_is_staff'] = auth.get_user(request).is_staff


    states = State.objects.all()

    for state in states:
        state.state_level = fun.getStateLevel(state)
        state.state_width = len(fun.getLeavesId(state))
        state.cell_rowspan = fun.getStateRowspan(state)


    full_depth = fun.getTreeDepth()
    formatted_states = []

    i = 1
    while i <= full_depth:
        formatted_states.append(i)
        formatted_states[i-1] = []
        for state in states:
            if state.state_level == i:
                formatted_states[i-1].append(state)
        i += 1


    for level in formatted_states:
        if len(level) == 1:
            level[0].position = 0
        else:
            i = 0
            while i < len(level):
                state = level[i]
                if (i==0):
                    if state.parent == level[i+1].parent:
                        state.position = 1
                    else:
                        state.position = 0
                elif (i==len(level)-1):
                    if state.parent == level[i-1].parent:
                        state.position = 3
                    else:
                        state.position = 0
                else:
                    if state.parent == level[i-1].parent:
                        if state.parent == level[i+1].parent:
                            state.position = 2
                        else:
                            state.position = 3
                    elif state.parent == level[i+1].parent:
                        state.position = 1
                    else:
                        state.position = 0

                i+=1













    args['states'] = formatted_states



    response = render_to_response('clicker_schema.html', args)
    return response