views.py 1017 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


9
def upload(request):
10
    if request.method == 'POST' and request.FILES['historico'] and request.FILES['matricula']:
11

Jomaro Rodrigues's avatar
Jomaro Rodrigues committed
12
13
        submission = Submission.objects.create(author=request.user,
                                               degree=request.user.educator.degree.first())
14
15
16
17
18
19
20
21
22
23
24

        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()

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

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

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