Exemplo n.º 1
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.º 2
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'
        })