upload/views.py
changeset 5 a1fe7806d6a0
parent 1 a370c5796d08
child 12 10d86ada90c2
equal deleted inserted replaced
4:6a2fdf0b4f7e 5:a1fe7806d6a0
     4 from django.shortcuts import render_to_response
     4 from django.shortcuts import render_to_response
     5 
     5 
     6 from forms import ParticipantForm
     6 from forms import ParticipantForm
     7 from models import Participant
     7 from models import Participant
     8 
     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'):
     9 def upload_file(request, template_name='index.html'):
    11     if request.method == 'POST':
    10     if request.method == 'POST':
    12         form = ParticipantForm(request.POST, request.FILES)		
    11         form = ParticipantForm(request.POST, request.FILES)		
    13         if form.is_valid():
    12         if form.is_valid():            
    14             #handle_uploaded_file(request.FILES['file'])
       
    15             form.save()	   
    13             form.save()	   
    16             return render_to_response(template_name, {'form': form, 'value': False,})
    14             return render_to_response(template_name, {'form': form, 'value': False,})
    17         else:
    15         else:
    18             return render_to_response(template_name, {'form': form, 'value': True,})
    16             return render_to_response(template_name, {'form': form, 'value': True,})
    19     return render_to_response(template_name,
    17     return render_to_response(template_name,
    20 			  {'form': ParticipantForm(), 'value': True})
    18 			  {'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)