views.py 990 Bytes
Newer Older
Bruno Meyer's avatar
Bruno Meyer committed
1
2
3
from django.shortcuts import render, redirect
from django.core.files.storage import FileSystemStorage

4
from django.contrib import messages
Bruno Meyer's avatar
Bruno Meyer committed
5

6
from uploads.models import Submission
Bruno Meyer's avatar
Bruno Meyer committed
7
8


Odair M.'s avatar
Odair M. committed
9
@login_required 
10
def upload(request):
11
    if request.method == 'POST' and request.FILES['historico'] and request.FILES['matricula']:
12
13

        submission = Submission.objects.create(author=request.user)
Odair M.'s avatar
Odair M. committed
14
        submission.degree = request.user.degree
15
16
17
18
19
20
21
22
23
24
25

        fs = FileSystemStorage(location=submission.path())

        fs.save('historico.xls', request.FILES['historico'])
        fs.save('matricula.xls', request.FILES['matricula'])

        submission.historico.name = submission.path() + '/historico.xls'
        submission.matricula.name = submission.path() + '/matricula.xls'

        submission.save()

26
        messages.success(request, 'Sua submissão foi realizada com sucesso, por favor aguarde o processamento')
Bruno Meyer's avatar
Bruno Meyer committed
27

28
        return redirect('dashboard')
Bruno Meyer's avatar
Bruno Meyer committed
29

30
    return render(request, 'uploads/upload.html')