|
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 |
|
6 from forms import ParticipantForm |
|
7 from models import Participant |
|
8 |
|
9 #view to handle uploaded file, showing content of file, and option of uploading a file |
|
10 def upload_file(request, template_name='index.html'): |
|
11 if request.method == 'POST': |
|
12 form = ParticipantForm(request.POST, request.FILES) |
|
13 if form.is_valid(): |
|
14 #handle_uploaded_file(request.FILES['file']) |
|
15 form.save() |
|
16 return render_to_response(template_name, {'form': form, 'value': False,}) |
|
17 else: |
|
18 return render_to_response(template_name, {'form': form, 'value': True,}) |
|
19 return render_to_response(template_name, |
|
20 {'form': ParticipantForm(), 'value': True}) |
|
21 |
|
22 def submission(request, template_name='submission.html'): |
|
23 """View to return the submitted videos |
|
24 """ |
|
25 context_participants = [] |
|
26 |
|
27 participants = Participant.objects.all() |
|
28 for participant in participants: |
|
29 context_participants.append({ |
|
30 'participant': participant, |
|
31 'file_name': str(participant.filename).split('/')[-1], |
|
32 }) |
|
33 |
|
34 context = { |
|
35 'participants': context_participants, |
|
36 } |
|
37 |
|
38 return render_to_response(template_name, context) |