Exemple #1
0
def register(request, type):
    if type not in ['subject', 'tester']:
        raise Exception('register: invalid type.')
    if request.method == 'POST':
        rform = RegistrationForm(request.POST)
        pform = UserProfileForm(request.POST)
        if rform.is_valid() and pform.is_valid():
            user = rform.save()
            if type == 'subject':
                group = Group.objects.get(name='Subjects')
            elif type == 'tester':
                group = Group.objects.get(name='Testers')
            user.groups.add(group)
            profile = pform.save(commit=False)
            profile.user = user
            profile.save()
            if type == 'tester':
                create_log_entry(profile, 'joined', [])
            return HttpResponseRedirect(reverse('home'))
    else:
        rform = RegistrationForm()
        pform = UserProfileForm()
    return render_to_response('testtool/registration/register.html', {
        'rform': rform,
        'pform': pform
    },
                              context_instance=RequestContext(request))
Exemple #2
0
def get_media(request, test_instance_id):
    checks = validate_request_and_ti(request, test_instance_id)
    ti = checks['ti']
    if not checks['success']:
        return media_signal(ti, 'error', checks['msg'])
    try:
        status = request.POST['status']
    except KeyError:
        return media_signal(ti, 'error', 'Must include "status" parameter.')
    # if all checks are successful, process the signal
    maxCount = ti.testcaseinstance_set.count()
    if ti.counter < 0:  # check bounds of counter
        return media_signal(ti, 'error',
                            'Error with test instance: counter < 0.')
    elif ti.counter > maxCount:
        return media_signal(ti, 'done')
    try:  # get the current test case
        tci_current = ti.testcaseinstance_set.get(
            play_order=max(1, ti.counter))
    except TestCaseInstance.DoesNotExist:
        return media_signal(ti, 'error', 'Could not find test case instance.')
    if status == 'media_done':
        tci_current.is_media_done = True
        tci_current.save()
    if status == 'test_case_done':  # inactive, but left in here to allow for tester to control when test case is played
        tci_current.is_media_done = True  # see Tally_desktop code (mainwindow.cpp > on_nextVideo_clicked() for comments)
        tci_current.is_done = True
        tci_current.save()
    if tci_current.is_done:  # if current test case is done, increment counter and return next video or done signal
        ti.counter += 1
        ti.save()
        if ti.counter > maxCount:
            return media_signal(ti, 'done')
        try:
            tci_next = ti.testcaseinstance_set.get(play_order=ti.counter)
        except TestCaseInstance.DoesNotExist:
            return media_signal(ti, 'error',
                                'Could not find test case instance.')
        return media_signal(ti, 'run', '', getMediaList(tci_next))
    elif ti.counter == 0:  # if this is the first request, return first video and increment counter
        ti.run_time = datetime.datetime.now(
        )  # set the run_time of the test instance to now
        ti.counter += 1
        ti.save()
        create_log_entry([], 'ran', ti)
        return media_signal(ti, 'run', '', getMediaList(tci_current))
    return media_signal(
        ti, 'wait'
    )  # otherwise, the subjects haven't finished scoring- return a wait signal
Exemple #3
0
def get_media(request, test_instance_id):
    checks = validate_request_and_ti(request,test_instance_id)
    ti = checks['ti']
    if not checks['success']:
        return media_signal(ti,'error',checks['msg'])
    try:
        status = request.POST['status']
    except KeyError:
        return media_signal(ti,'error','Must include "status" parameter.')
    # if all checks are successful, process the signal
    maxCount = ti.testcaseinstance_set.count()
    if ti.counter < 0:                  # check bounds of counter
        return media_signal(ti,'error','Error with test instance: counter < 0.')
    elif ti.counter > maxCount:
        return media_signal(ti,'done')
    try:                                # get the current test case
        tci_current = ti.testcaseinstance_set.get(play_order=max(1,ti.counter))
    except TestCaseInstance.DoesNotExist:
        return media_signal(ti,'error','Could not find test case instance.')
    if status == 'media_done':
        tci_current.is_media_done = True
        tci_current.save()
    if status == 'test_case_done':        # inactive, but left in here to allow for tester to control when test case is played
        tci_current.is_media_done = True  # see Tally_desktop code (mainwindow.cpp > on_nextVideo_clicked() for comments)
        tci_current.is_done = True
        tci_current.save()
    if tci_current.is_done:             # if current test case is done, increment counter and return next video or done signal
        ti.counter += 1
        ti.save()
        if ti.counter > maxCount:
            return media_signal(ti,'done')
        try:
            tci_next = ti.testcaseinstance_set.get(play_order=ti.counter)
        except TestCaseInstance.DoesNotExist:
            return media_signal(ti,'error','Could not find test case instance.')
        return media_signal(ti,'run','',getMediaList(tci_next))
    elif ti.counter==0:                 # if this is the first request, return first video and increment counter
        ti.run_time = datetime.datetime.now()       # set the run_time of the test instance to now
        ti.counter += 1
        ti.save()
        create_log_entry([],'ran',ti)
        return media_signal(ti,'run','',getMediaList(tci_current))
    return media_signal(ti,'wait')      # otherwise, the subjects haven't finished scoring- return a wait signal
Exemple #4
0
def register(request,type):
    if type not in ['subject','tester']:
        raise Exception('register: invalid type.')
    if request.method == 'POST':
        rform = RegistrationForm(request.POST)
        pform = UserProfileForm(request.POST)
        if rform.is_valid() and pform.is_valid():
            user = rform.save()
            if type=='subject':
                group = Group.objects.get(name='Subjects')
            elif type=='tester':
                group = Group.objects.get(name='Testers')
            user.groups.add(group)
            profile = pform.save(commit=False)
            profile.user = user
            profile.save()
            if type=='tester':
                create_log_entry(profile,'joined',[])
            return HttpResponseRedirect(reverse('home'))
    else:
        rform = RegistrationForm()
        pform = UserProfileForm()
    return render_to_response('testtool/registration/register.html',  {'rform': rform, 'pform': pform },
                              context_instance=RequestContext(request))