upload/views.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 03 Sep 2009 18:37:48 +0530
changeset 18 07408d1ced76
parent 17 08a47999f316
child 20 272dced1685b
permissions -rw-r--r--
Added CSS and I accept terms and condition.

#can add features like: supporting files with specified extensions, making edit box of content better etc.
from django.http import HttpResponse
from django.template import Context, Template
from django.shortcuts import render_to_response

from forms import ParticipantForm
from models import Participant


#function to read the upoaded file and store it
def handle_uploaded_file(f):
    destination = open(f.name, 'wb+')
    for chunk in f.chunks():
        destination.write(chunk)
    destination.close()

#view to handle uploaded file, showing content of file, and option of uploading a file
def upload_file(request, template_name='index.html'):
    if request.method == 'POST':
        form = ParticipantForm(request.POST, request.FILES)		
        if form.is_valid():
            #handle_uploaded_file(request.FILES['file'])
            form.save()	   
            return render_to_response(template_name, {'form': form, 'value': False,})
        else:
            return render_to_response(template_name, {'form': form, 'value': True,})
    return render_to_response(template_name,
			  {'form': ParticipantForm(), 'value': True})
			  
def submission(request, template_name='submission.html'):
    """View to return the submitted videos
    """
    context = {
        'participants': Participant.objects.all()
        }

    return render_to_response(template_name, context)