1
|
1 |
#can add features like: supporting files with specified extensions, making edit box of content better etc.
|
|
2 |
from django.http import HttpResponse
|
|
3 |
from django.template import Context, Template
|
|
4 |
from django.shortcuts import render_to_response
|
|
5 |
from form import FileForm, Uploaded_fileForm
|
2
|
6 |
from forms import ParticipantForm
|
1
|
7 |
import tarfile
|
|
8 |
|
|
9 |
#function to read the upoaded file and store it
|
|
10 |
def handle_uploaded_file(f):
|
|
11 |
destination = open(f.name, 'wb+')
|
|
12 |
for chunk in f.chunks():
|
|
13 |
destination.write(chunk)
|
|
14 |
destination.close()
|
|
15 |
|
|
16 |
#view to handle uploaded file, showing content of file, and option of uploading a file
|
12
|
17 |
def upload_file(request, template_name='index.html'):
|
1
|
18 |
if request.method == 'POST':
|
12
|
19 |
form = ParticipantForm(request.POST, request.FILES)
|
1
|
20 |
if form.is_valid():
|
12
|
21 |
#handle_uploaded_file(request.FILES['file'])
|
|
22 |
form.save()
|
|
23 |
return render_to_response(template_name, {'form': ParticipantForm(), 'value': False,})
|
|
24 |
c = Context()
|
1
|
25 |
return render_to_response(template_name,
|
12
|
26 |
{'form': ParticipantForm(), 'value': True,})
|