sdi/views.py
author nishanth
Sat, 29 May 2010 19:35:49 +0530
changeset 25 30baf3c635c5
parent 24 f79be1dd4a22
child 26 212fcba4459e
permissions -rw-r--r--
added list statiscs page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
1c2d2e702aee completed the register view
nishanth
parents: 14
diff changeset
     1
from django.shortcuts import render_to_response, redirect
7
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     2
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     3
from sage_days.sdi.models import Registrant
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
     4
from sage_days.sdi.forms import RegisterForm, SearchForm
7
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     5
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     6
def register(request):
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     7
    """ The user register page.
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     8
    """
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     9
9
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    10
    if request.method == "POST":
14
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    11
        form = RegisterForm(request.POST)
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    12
        if form.is_valid():
15
1c2d2e702aee completed the register view
nishanth
parents: 14
diff changeset
    13
            form.save()
1c2d2e702aee completed the register view
nishanth
parents: 14
diff changeset
    14
            return redirect("/registration/complete")
14
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    15
        else:
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    16
            return render_to_response("register.html", {"form":form})
9
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    17
    else:
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    18
        form = RegisterForm()
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    19
        return render_to_response("register.html", {"form":form})
22
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    20
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    21
def reg_complete(request):
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    22
    """ Tell the registration is successful.
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    23
    """
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    24
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    25
    return render_to_response("reg_complete.html")
23
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    26
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    27
def list_stats(request):
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    28
    """ List the statiscs of registered participants.
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    29
    """
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    30
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    31
    if request.method == "POST":
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    32
        form = SearchForm(request.POST)
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    33
        if form.is_valid():
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    34
            data = form.cleaned_data
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    35
            need_workshop = data['need_for_python_workshop']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    36
            db_query = "Registrant.objects.filter(need_for_python_workshop=%s)"%need_workshop
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    37
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    38
            topics_include, topics_exclude = data['topics_interested']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    39
            for number in topics_include:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    40
                db_query += '.filter(topics_interested__contains="%s")'%number
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    41
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    42
            for number in topics_exclude:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    43
                db_query += '.exclude(topics_interested__contains="%s")'%number
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    44
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    45
            start_python, stop_python = data['knowledge_of_python']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    46
            if start_python and stop_python:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    47
                db_query += '.filter(knowledge_of_python__gte="%s")'%start_python
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    48
                db_query += '.filter(knowledge_of_python__lte="%s")'%stop_python
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    49
            elif start_python:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    50
                db_query += '.filter(knowledge_of_python__exact="%s")'%start_python
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    51
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    52
            start_sage, stop_sage = data['knowledge_of_sage']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    53
            if start_sage and stop_sage:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    54
                db_query += '.filter(knowledge_of_sage__gte="%s")'%start_sage
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    55
                db_query += '.filter(knowledge_of_sage__lte="%s")'%stop_sage
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    56
            elif start_sage:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    57
                db_query += '.filter(knowledge_of_sage__exact="%s")'%start_sage
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    58
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    59
            start_likeliness, stop_likeliness = data['likeliness_of_attending']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    60
            if start_likeliness and stop_likeliness:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    61
                db_query += '.filter(likeliness_of_attending__gte="%s")'%start_likeliness
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    62
                db_query += '.filter(likeliness_of_attending__lte="%s")'%stop_likeliness
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    63
            elif start_likeliness:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    64
                db_query += '.filter(likeliness_of_attending__exact="%s")'%start_likeliness
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    65
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    66
            matches = eval(db_query)
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    67
            return render_to_response("list_stats.html", {"form":form, 'matches':matches})
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    68
        else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    69
            return render_to_response("list_stats.html", {"form":form})
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    70
    else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    71
        form = SearchForm()
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    72
        return render_to_response("list_stats.html", {"form":form})