upload/views.py
author Shantanu <shantanu@fossee.in>
Mon, 25 Jan 2010 02:13:07 +0530
changeset 16 b5bc2bff3055
parent 12 10d86ada90c2
child 17 46003dc47db1
permissions -rw-r--r--
renamed views function name to older one.
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
12
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
     5
from django.contrib.auth.decorators import login_required
1
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     6
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     7
from forms import ParticipantForm
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     8
from models import Participant
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
     9
16
b5bc2bff3055 renamed views function name to older one.
Shantanu <shantanu@fossee.in>
parents: 12
diff changeset
    10
def upload_file(request, template_name='index.html'):
1
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)		
5
a1fe7806d6a0 Added apache wsgi scripts.
Shantanu <shantanu@fossee.in>
parents: 1
diff changeset
    13
        if form.is_valid():            
1
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    14
            form.save()	   
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    15
            return render_to_response(template_name, {'form': form, 'value': False,})
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    16
        else:
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    17
            return render_to_response(template_name, {'form': form, 'value': True,})
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    18
    return render_to_response(template_name,
a370c5796d08 Initialized the registration application.
Shantanu <shantanu@fossee.in>
parents:
diff changeset
    19
			  {'form': ParticipantForm(), 'value': True})
12
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    20
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    21
#@login_required
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    22
def view_registrants(request, template_name='registrants.html'):
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    23
    """
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    24
    View to return list of registered participants
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    25
    """
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    26
    ##wow what a one liner
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    27
    poc = dict([line.strip().split('|') for line in open('upload/poc')])        
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    28
    if not request.user.is_authenticated():
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    29
        return HttpResponse("You can't view these details.")
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    30
    context_registrants = []
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    31
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    32
    registrations = Participant.objects.all()
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    33
    for registrant in registrations:
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    34
        if poc[request.user.username] == registrant.workshop:
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    35
            context_registrants.append({
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    36
                'registrant':registrant,
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    37
                })
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    38
    context = {
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    39
        'registrants':context_registrants,
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    40
        }
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    41
    return render_to_response(template_name, context)
10d86ada90c2 Added custom view for looking at registrants yAy.
Shantanu <shantanu@fossee.in>
parents: 5
diff changeset
    42