author | Madhusudan.C.S <madhusudancs@gmail.com> |
Thu, 03 Sep 2009 00:17:30 +0530 | |
changeset 16 | a5bbfbe5feb1 |
parent 15 | 2dbb5e797989 |
child 17 | 08a47999f316 |
permissions | -rw-r--r-- |
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() |
|
15
2dbb5e797989
Fixed views.py to accommodate form validation.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
12
diff
changeset
|
23 |
return render_to_response(template_name, {'form': form, 'value': False,}) |
2dbb5e797989
Fixed views.py to accommodate form validation.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
12
diff
changeset
|
24 |
else: |
2dbb5e797989
Fixed views.py to accommodate form validation.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
12
diff
changeset
|
25 |
return render_to_response(template_name, {'form': form, 'value': True,}) |
12 | 26 |
c = Context() |
1 | 27 |
return render_to_response(template_name, |
12 | 28 |
{'form': ParticipantForm(), 'value': True,}) |