Beispiel #1
0
def preparePcpt(request, exp_id):
    #expects POST data
    #gets stored as list! need [0]
    global validation
    global singlepagedebug
    global selectwelcome
    global selectcondition
    request.session.clear()
    request.session.create()
    request.session.update(request.POST)
    request.session['timestamps'] = {request.path:datetime.utcnow()}
    if request.session.get('cbox_validation') != None:
        #cbox value is redundant!!! May be anything.
        validation = True
    else:
        validation = False
    if request.session.get('cbox_singlepagedebug') != None:
        singlepagedebug = True
    else:
        singlepagedebug = False
    if request.session.get('selectwelcome') != None:
        selectwelcome = request.session.get('selectwelcome')[0]
    if request.session.get('selectcondition') != None:
        selectcondition = request.session.get('selectcondition')[0]
    selectlanguage = request.session.get('selectlanguage')[0]
    request.session['django_language'] = selectlanguage

    # HTML stringifies all chars. Cant obtain integers from session.
    ct_size = int(request.session['ct_size'][0])

    # might be used to overwrite a corrupt pcpt (not valid one).
    # is 'future', better not use it.
    # stick to manual garbage collection of pubs
    # valid_input = request.session['input_pcptid'][0]
    # pcpt_id = pcpt.initPcpt(ct_size, request.COOKIES['sessionid'], request.COOKIES['csrftoken'], selectcondition)
    (pcpt_id, ctlist) = pcpt.initPcpt(ct_size, request.session.session_key, request.COOKIES['csrftoken'], selectcondition)
    request.session['pub_pcpt_id'] = pcpt_id
    request.session['pub_ctlist'] = ctlist



    #DEBUG
    #first pcpt_id entry
    # request.session['all_rnd_orderings'] = pcpt.scale_order_ids
    # request.session['all_choice_tasks'] = pcpt.ctlistIDs

    #DEBUG Pubs
    # lastPubID = curr_exp.pub_set.count()
    # lastPub = curr_exp.pub_set.all()[lastPubID-1]
    # request.session['pub'] = model_to_dict(lastPub)
    # cts_string = ''
    # cts = lastPub.Choice_TasksAsPub.all()
    # for ct in cts:
    #     cts_string += str(ct.pk) + ', '
    # request.session['pub_cts'] = cts_string
    # rnds = lastPub.external_order_scale_set.all()
    # rnds_count = lastPub.external_order_scale_set.count()
    # rnds_string = ''
    # for rnd in rnds:
    #     rnds_string += str(rnd.pk) + ', '
    # request.session['pub_scales'] = rnds_string

    return getRedirectURL(request, 'preparePcpt',exp_id, pcpt_id)
Beispiel #2
0
def preparePcpt(request, exp_id):
    #expects POST data
    #gets stored as list! need [0]
    # global singlepagedebug
    # global selectwelcome
    # global selectcondition
    # request.session.clear()
    # request.session.flush()
    request.session.create()
    request.session.update(request.POST)
    request.session.update(request.GET)
    request.session.modified = True
    request.session['timestamps'] = {request.path:datetime.utcnow()}
    # request.session['timestamps'] = {createUniqueKey(request):datetime.utcnow()}
    # grabs from POST, not session. only explanation, not verified
    if request.session.get('cbox_validation') != None:
        request.session['validation'] = True
    else:
        request.session['validation'] = False
    try:
        del request.session['cbox_validation']
    except:
        pass

    if request.session.get('cbox_singlepagedebug') != None:
        request.session['singlepagedebug'] = True
    else:
        request.session['singlepagedebug'] = False
    try:
        del request.session['cbox_singlepagedebug']
    except:
        pass

    # if request.session.get('selectwelcome') != None:
    #     selectwelcome = request.session.get('selectwelcome')[0]
    if request.session.get('selectcondition') != None:
        selectcondition = request.session.get('selectcondition')[0]
    try:
        del request.session['selectcondition']
    except:
        pass

    if request.session.get('cbox_valid_pcpt') != None:
        request.session['valid_pcpt'] = True
        del request.session['cbox_valid_pcpt']
    else:
        request.session['valid_pcpt'] = False

    if request.session.get('cbox_testpcpt') != None:
        request.session['testpcpt'] = True
        del request.session['cbox_testpcpt']
    else:
        request.session['testpcpt'] = False

    if request.session.get('cbox_debugsaving') != None:
        debugsaving_activated = True
    else:
        debugsaving_activated = False

    # request.session['resolution'] = str(request.session.get('selectresolution')[0])
    request.session['resolution'] = str(request.session['selectresolution'][0])


    # if request.session.get('selectlanguage') != None:
    selectlanguage = request.session.get('selectlanguage')[0]
    request.session['django_language'] = selectlanguage
    #     translation.set_language()
    # else:
    #     selectlanguage = request.session.get('selectlanguage')[0]

    # HTML stringifies all chars. Cant obtain integers from session.
    ct_size = int(request.session['ct_size'][0])

    # might be used to overwrite a corrupt pcpt (not valid one).
    # is 'future', better not use it.
    # stick to manual garbage collection of pubs
    # valid_input = request.session['input_pcptid'][0]
    # pcpt_id = pcpt.initPcpt(ct_size, request.COOKIES['sessionid'], request.COOKIES['csrftoken'], selectcondition)
    (pcpt_id, ctlist, hloutlist, pub, scale_sequences) = pcpt.initPcpt(exp_id, ct_size, request.session.session_key, request.COOKIES['csrftoken'], selectcondition)
    request.session['pub_pcpt_id'] = pcpt_id
    request.session['pub_ctlist'] = ctlist
    request.session['pub_hloutlist'] = hloutlist
    request.session['pub'] = model_to_dict(pub)
    request.session['pub_scale_sequences'] = scale_sequences
    request.session['pub_condition'] = pub.def_group
    request.session['pub_condition_override'] = pub.override_group
    request.session['pub_ctlist_IDs'] = [ct.pk for ct in ctlist]
    request.session['pub_hloutlist_IDs'] = [hl.pk for hl in hloutlist]
    request.session['pub_scale_sequences_IDs'] = [rnd.pk for key, rnd in scale_sequences.iteritems()]



    #DEBUG
    #first pcpt_id entry
    # request.session['all_rnd_orderings'] = pcpt.scale_order_ids
    # request.session['all_choice_tasks'] = pcpt.ctlistIDs

    if debugsaving_activated:
        # pcpt.debugMakePCPT('increasing', pub, ctlist, scale_sequences)
        # pcpt.debugMakePCPT('baselinelow', pub, ctlist, scale_sequences)
        #pcpt.debugMakePCPT('baselinehigh', pub, ctlist, scale_sequences)
        # pcpt.debugMakePCPT('s27042013', pub, ctlist, scale_sequences)
        return render(request, 'eyevacs/thankyou.html')

    #DEBUG Pubs
    # lastPubID = curr_exp.pub_set.count()
    # lastPub = curr_exp.pub_set.all()[lastPubID-1]
    # request.session['pub'] = model_to_dict(lastPub)
    # cts_string = ''
    # cts = lastPub.Choice_TasksAsPub.all()
    # for ct in cts:
    #     cts_string += str(ct.pk) + ', '
    # request.session['pub_cts'] = cts_string
    # rnds = lastPub.external_order_scale_set.all()
    # rnds_count = lastPub.external_order_scale_set.count()
    # rnds_string = ''
    # for rnd in rnds:
    #     rnds_string += str(rnd.pk) + ', '
    # request.session['pub_scales'] = rnds_string

    return getRedirectURL(request, 'preparePcpt',exp_id, pcpt_id)