author | Madhusudan.C.S <madhusudancs@gmail.com> |
Thu, 01 Oct 2009 14:17:44 +0530 | |
changeset 28 | 56a978b7352e |
parent 20 | 272dced1685b |
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 |
|
18
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
5 |
|
2 | 6 |
from forms import ParticipantForm |
18
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
7 |
from models import Participant |
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
8 |
|
1 | 9 |
|
10 |
#function to read the upoaded file and store it |
|
11 |
def handle_uploaded_file(f): |
|
12 |
destination = open(f.name, 'wb+') |
|
13 |
for chunk in f.chunks(): |
|
14 |
destination.write(chunk) |
|
15 |
destination.close() |
|
16 |
||
17 |
#view to handle uploaded file, showing content of file, and option of uploading a file |
|
12 | 18 |
def upload_file(request, template_name='index.html'): |
1 | 19 |
if request.method == 'POST': |
12 | 20 |
form = ParticipantForm(request.POST, request.FILES) |
1 | 21 |
if form.is_valid(): |
12 | 22 |
#handle_uploaded_file(request.FILES['file']) |
23 |
form.save() |
|
15
2dbb5e797989
Fixed views.py to accommodate form validation.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
12
diff
changeset
|
24 |
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
|
25 |
else: |
2dbb5e797989
Fixed views.py to accommodate form validation.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
12
diff
changeset
|
26 |
return render_to_response(template_name, {'form': form, 'value': True,}) |
1 | 27 |
return render_to_response(template_name, |
18
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
28 |
{'form': ParticipantForm(), 'value': True}) |
17 | 29 |
|
30 |
def submission(request, template_name='submission.html'): |
|
18
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
31 |
"""View to return the submitted videos |
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
32 |
""" |
20
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
33 |
context_participants = [] |
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
34 |
|
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
35 |
participants = Participant.objects.all() |
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
36 |
for participant in participants: |
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
37 |
context_participants.append({ |
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
38 |
'participant': participant, |
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
39 |
'file_name': str(participant.filename).split('/')[-1], |
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
40 |
}) |
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
41 |
|
18
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
42 |
context = { |
20
272dced1685b
Table to view uploads.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
43 |
'participants': context_participants, |
18
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
44 |
} |
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
45 |
|
07408d1ced76
Added CSS and I accept terms and condition.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
46 |
return render_to_response(template_name, context) |