upload/views.py
author Shantanu <shantanu@fossee.in>
Wed, 20 Jan 2010 14:19:50 +0530
changeset 1 a370c5796d08
child 5 a1fe7806d6a0
permissions -rw-r--r--
Initialized the registration application.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     1
#can add features like: supporting files with specified extensions, making edit box of content better etc.
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     2
from django.http import HttpResponse
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     3
from django.template import Context, Template
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     4
from django.shortcuts import render_to_response
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     5
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     6
from forms import ParticipantForm
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     7
from models import Participant
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     8
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     9
#view to handle uploaded file, showing content of file, and option of uploading a file
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    10
def upload_file(request, template_name='index.html'):
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    11
    if request.method == 'POST':
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    12
        form = ParticipantForm(request.POST, request.FILES)		
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    13
        if form.is_valid():
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    14
            #handle_uploaded_file(request.FILES['file'])
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    15
            form.save()	   
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    16
            return render_to_response(template_name, {'form': form, 'value': False,})
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    17
        else:
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    18
            return render_to_response(template_name, {'form': form, 'value': True,})
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    19
    return render_to_response(template_name,
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    20
			  {'form': ParticipantForm(), 'value': True})
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    21
			  
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    22
def submission(request, template_name='submission.html'):
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    23
    """View to return the submitted videos
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    24
    """
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    25
    context_participants = []
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    26
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    27
    participants = Participant.objects.all()
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    28
    for participant in participants:
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    29
      context_participants.append({
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    30
          'participant': participant,
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    31
          'file_name': str(participant.filename).split('/')[-1],
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    32
          })
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    33
      
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    34
    context = {
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    35
        'participants': context_participants,
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    36
        }
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    37
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    38
    return render_to_response(template_name, context)