Beispiel #1
0
def IndexView(request):
    if request.is_ajax():
        try:
            comment_usr = auth.get_user(request)
            is_global = request.POST.get('is_global', '')
            comment = request.POST.get('note_body', '')
            if is_global == "true":
                try:
                    note = GlobalUserNotes.objects.get(user=comment_usr)
                    note.delete()
                    GlobalUserNotes.objects.create(user=comment_usr, note_body=comment)
                except:
                    GlobalUserNotes.objects.create(user=comment_usr, note_body=comment)
                return HttpResponse("1")
            else:
                state_id = request.POST.get('state_id', '')
                try:
                    note = StateUserNotes.objects.get(state=State.objects.get(id=state_id), user=comment_usr)
                    note.delete()
                    StateUserNotes.objects.create(state=State.objects.get(id=state_id), user=comment_usr, note_body=comment)
                except:
                    StateUserNotes.objects.create(state=State.objects.get(id=state_id), user=comment_usr, note_body=comment)
                return HttpResponse("1")
        except:
            return HttpResponse("-1")

    beginState = -1
    fun = FunctionsBase()
    args = {}


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

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

    states = State.objects.order_by("path").values()

    for state in states:
        state['depth'] = len(state['path'])/3 - 1

    i = 0
    for state in states:
        if i==0:
            state['pre_tags'] = "<ul class='Container'><li class='Node IsRoot ExpandClosed'>".encode("utf8")
            state['post_tags'] = fun.printPostTags(state, states[i+1])
        if i==len(states)-1:
            state['pre_tags'] = fun.printPreTagsForLast(state, states[i-1])
            state['post_tags'] = fun.printPostTagsForLast(state)
        if i!=len(states)-1 and i!=0:
            state['pre_tags'] = fun.printPreTags(state, states[i-1], states[i+1])
            state['post_tags'] = fun.printPostTags(state, states[i+1])
        if type(state['parent_id']) == NoneType:
            beginState = state['id']
        i+=1

    args['states'] = states
    args['tips'] = Tip.objects.all().values()
    args['checkbox_inputs'] = CheckboxInput.objects.all().values()
    args['text_inputs'] = TextInput.objects.all().values()
    args['radio_inputs'] = RadioInput.objects.all().values()
    args['radio_input_variants'] = RadioInputVariant.objects.all().values()
    args['state_usernotes'] = StateUserNotes.objects.filter(user = auth.get_user(request)).values()
    response = render_to_response('clicker_content.html', args)
    response.set_cookie("fist_step_id", beginState)
    return response