Exemplo n.º 1
0
def lti(request):
    if not get_timeslot():
        return HttpResponse(
            'Login is not available. The system is currently closed.',
            status=403)
    config = getattr(settings, 'PYLTI_CONFIG', dict())
    consumers = config.get('consumers', dict())
    params = dict(request.POST.items())
    headers = request.META
    headers['X-Forwarded-Proto'] = headers['HTTP_X_FORWARDED_PROTO']
    try:
        verify_request_common(consumers, request.build_absolute_uri(),
                              request.method, headers, params)
    except LTIException as e:
        logger.error('LTI exception from canvas; {}'.format(e))
        return HttpResponse("Signature Validation failed!", status=403)

    data = request.POST
    try:
        username = data['lis_person_sourcedid']
        email = data['lis_person_contact_email_primary']
        studentnumber = data['custom_canvas_user_login_id']
        coursecode = data['context_label']
    except KeyError as e:
        logger.error('Invalid post data from canvas; {}; {}'.format(data, e))
        return HttpResponse("Missing data in POST", status=400)

    user = get_user(email, username)
    if user is None:
        user = User(email=email, username=username)
        user.save()
    try:
        meta = user.usermeta
    except UserMeta.DoesNotExist:
        meta = UserMeta(User=user)

    meta.Studentnumber = studentnumber
    if not meta.Overruled:
        if settings.COURSE_CODE_BEP in coursecode:
            meta.EnrolledBEP = True
        elif settings.COURSE_CODE_EXT in coursecode:
            meta.EnrolledBEP = True
            meta.EnrolledExt = True
        else:
            logger.warning(
                'Course code not matched on BEP or EXT for user {}. Code was: {}'
                .format(user, coursecode))

    meta.save()
    meta.TimeSlot.add(get_timeslot())
    meta.save()
    user.save()

    log = CanvasLogin()
    log.Subject = user
    log.save()

    return redirect("{}/login/".format(settings.DOMAIN))
Exemplo n.º 2
0
def osirisToMeta(request):
    write_errors = []
    try:
        data, log = read_osiris_xlsx()
    except:
        return render(
            request, 'base.html', {
                'Message':
                'Retrieving Osirisdata failed. Please upload a valid file.',
                'return': 'index:index',
            })

    if request.method == 'POST':
        count = 0
        form = ConfirmForm(request.POST)
        if form.is_valid():
            for p in data:
                try:
                    user = User.objects.get(email=p.email)
                except User.DoesNotExist:
                    write_errors.append('User {} skipped'.format(p.email))
                    continue
                try:
                    meta = user.usermeta
                except UserMeta.DoesNotExist:
                    meta = UserMeta()
                    user.usermeta = meta
                    meta.save()
                    user.save()
                if p.automotive:
                    meta.Study = 'Automotive'
                else:
                    meta.Study = 'Electrical Engineering'
                meta.Cohort = p.cohort
                meta.ECTS = p.ects
                meta.Studentnumber = p.idnumber
                meta.save()
                count += 1
            return render(
                request, 'base.html', {
                    'Message':
                    mark_safe('User meta updated for {} users. <br />'.format(
                        count) + print_list(write_errors)),
                    'return':
                    'osirisdata:list'
                })
    else:
        form = ConfirmForm()

    return render(
        request, 'osirisdata/osiris_to_meta_form.html', {
            'form': form,
            'formtitle': 'Confirm write to usermeta',
            'buttontext': 'Confirm'
        })
Exemplo n.º 3
0
def lti(request):
    config = getattr(settings, 'PYLTI_CONFIG', dict())
    consumers = config.get('consumers', dict())
    params = dict(request.POST.items())
    headers = request.META
    headers['X-Forwarded-Proto'] = headers['HTTP_X_FORWARDED_PROTO']
    try:
        verify_request_common(consumers, request.build_absolute_uri(),
                              request.method, headers, params)
    except LTIException:
        return HttpResponse("Signature Validation failed!", status=403)

    data = request.POST
    try:
        username = data['lis_person_sourcedid']
        email = data['lis_person_contact_email_primary']
        studentnumber = data['custom_canvas_user_login_id']
        coursecode = data['context_label']
    except KeyError:
        return HttpResponse("Missing data in POST", status=400)

    user = get_user(email, username)
    if user is None:
        user = User(email=email, username=username)
        user.save()
    try:
        meta = user.usermeta
    except UserMeta.DoesNotExist:
        meta = UserMeta(User=user)

    meta.Studentnumber = studentnumber
    if not meta.Overruled:
        if coursecode == '5XEC0':
            meta.EnrolledBEP = True
        elif coursecode == '5XED0':
            meta.EnrolledBEP = True
            meta.EnrolledExt = True

    meta.save()
    meta.TimeSlot.add(get_timeslot())
    meta.save()
    user.save()

    log = CanvasLogin()
    log.Subject = user
    log.save()

    return redirect("https://bep.ele.tue.nl/login")
Exemplo n.º 4
0
def osirisToMeta(request):
    if request.method == 'POST':
        form = ConfirmForm(request.POST)
        if form.is_valid():
            data = osirisData()
            for p in data.getalldata():
                try:
                    user = User.objects.get(email=p.email)
                except User.DoesNotExist:
                    continue
                try:
                    meta = user.usermeta
                except UserMeta.DoesNotExist:
                    meta = UserMeta()
                    user.usermeta = meta
                    meta.save()
                    user.save()
                if p.automotive:
                    meta.Study = 'Automotive'
                else:
                    meta.Study = 'Eletrical Engineering'
                meta.Cohort = p.cohort
                meta.ECTS = p.ects
                meta.Studentnumber = p.idnumber
                meta.save()
            return render(request, 'base.html', {
                'Message': 'usermeta updated!',
                'return': 'osirisdata:list'
            })
    else:
        form = ConfirmForm()

    return render(
        request, 'GenericForm.html', {
            'form': form,
            'formtitle': 'Confirm rewrite usermeta',
            'buttontext': 'Confirm'
        })
Exemplo n.º 5
0
    try:
        prof = User.objects.create_user('professor{}'.format(i),
                                        'professor{}@tue.nl'.format(i),
                                        'marketplace')
        prof.first_name = "professor"
        prof.last_name = str(i)
        prof.groups.add(type1staff)
        prof.save()
        profs.append(prof)
    except:
        print(str(i) + " not created")
    prof = User.objects.get(username='******'.format(i))
    try:
        mta = UserMeta()
        mta.Fullname = "Professor-" + str(i)
        mta.Studentnumber = 0
        mta.User = prof
        mta.save()
        print("usermeta prof" + str(i))
    except:
        print(str(i) + " prof usermeta not created")

print("creating {} phders".format(NUMPHDS))
for i in range(0, NUMPHDS):
    try:
        phd = User.objects.create_user('phd{}'.format(i),
                                       'phd{}@tue.nl'.format(i), 'marketplace')
        phd.first_name = "phd"
        phd.last_name = str(i)
        phd.groups.add(type2staff)
        phd.save()