sdi/views.py
author nishanth
Mon, 07 Jun 2010 15:50:01 +0530
branchanoop
changeset 70 58cafee2ee89
parent 67 b9690fbf78af
child 72 3673ed3ca27c
permissions -rw-r--r--
now only logged in users can logout
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
26
212fcba4459e changed the app to work with apache + added base.html, and did needed changes.
anoop
parents: 25
diff changeset
     2
from django.http import HttpResponse
65
0ca63c964237 now login is required for accessing stats and send_invi pages
nishanth
parents: 57
diff changeset
     3
from django.contrib.auth.decorators import login_required
7
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     4
67
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
     5
from django.contrib.auth import authenticate, login, logout
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
     6
7
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
     7
from sage_days.sdi.models import Registrant
67
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
     8
from sage_days.sdi.forms import RegisterForm, SearchForm, EmailForm, LoginForm
56
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
     9
from sage_days.sdi.events import send_reg_complete_mail, mail_invi
7
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
    10
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
    11
def register(request):
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
    12
    """ The user register page.
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
    13
    """
98f2b5c2abc9 added basic register view in views.py
nishanth
parents: 4
diff changeset
    14
9
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    15
    if request.method == "POST":
14
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    16
        form = RegisterForm(request.POST)
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    17
        if form.is_valid():
15
1c2d2e702aee completed the register view
nishanth
parents: 14
diff changeset
    18
            form.save()
53
b226923fbf64 added send_mail after registration
nishanth
parents: 48
diff changeset
    19
b226923fbf64 added send_mail after registration
nishanth
parents: 48
diff changeset
    20
            data = form.cleaned_data
b226923fbf64 added send_mail after registration
nishanth
parents: 48
diff changeset
    21
            first_name = data['first_name']
b226923fbf64 added send_mail after registration
nishanth
parents: 48
diff changeset
    22
            last_name = data['last_name']
b226923fbf64 added send_mail after registration
nishanth
parents: 48
diff changeset
    23
            email = data['email']
b226923fbf64 added send_mail after registration
nishanth
parents: 48
diff changeset
    24
            send_reg_complete_mail(email, first_name, last_name)
b226923fbf64 added send_mail after registration
nishanth
parents: 48
diff changeset
    25
26
212fcba4459e changed the app to work with apache + added base.html, and did needed changes.
anoop
parents: 25
diff changeset
    26
            return redirect("/sage_days/registration/complete")
14
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    27
        else:
ee492a4b9ebd updated register view
nishanth
parents: 9
diff changeset
    28
            return render_to_response("register.html", {"form":form})
9
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    29
    else:
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    30
        form = RegisterForm()
47f72774489e added the return statement for register view
nishanth
parents: 7
diff changeset
    31
        return render_to_response("register.html", {"form":form})
22
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    32
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    33
def reg_complete(request):
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    34
    """ Tell the registration is successful.
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    35
    """
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    36
1df4b0e0d45c added the registration complete page
nishanth
parents: 15
diff changeset
    37
    return render_to_response("reg_complete.html")
23
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    38
65
0ca63c964237 now login is required for accessing stats and send_invi pages
nishanth
parents: 57
diff changeset
    39
@login_required
23
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    40
def list_stats(request):
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    41
    """ List the statiscs of registered participants.
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    42
    """
2aae8293f3a7 added list statiscs page
nishanth
parents: 22
diff changeset
    43
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    44
    if request.method == "POST":
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    45
        form = SearchForm(request.POST)
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    46
        if form.is_valid():
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    47
            data = form.cleaned_data
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    48
            need_workshop = data['need_for_python_workshop']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    49
            db_query = "Registrant.objects.filter(need_for_python_workshop=%s)"%need_workshop
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    50
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    51
            topics_include, topics_exclude = data['topics_interested']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    52
            for number in topics_include:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    53
                db_query += '.filter(topics_interested__contains="%s")'%number
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    54
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    55
            for number in topics_exclude:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    56
                db_query += '.exclude(topics_interested__contains="%s")'%number
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    57
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    58
            start_python, stop_python = data['knowledge_of_python']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    59
            if start_python and stop_python:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    60
                db_query += '.filter(knowledge_of_python__gte="%s")'%start_python
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    61
                db_query += '.filter(knowledge_of_python__lte="%s")'%stop_python
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    62
            elif start_python:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    63
                db_query += '.filter(knowledge_of_python__exact="%s")'%start_python
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    64
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    65
            start_sage, stop_sage = data['knowledge_of_sage']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    66
            if start_sage and stop_sage:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    67
                db_query += '.filter(knowledge_of_sage__gte="%s")'%start_sage
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    68
                db_query += '.filter(knowledge_of_sage__lte="%s")'%stop_sage
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    69
            elif start_sage:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    70
                db_query += '.filter(knowledge_of_sage__exact="%s")'%start_sage
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    71
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    72
            start_likeliness, stop_likeliness = data['likeliness_of_attending']
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    73
            if start_likeliness and stop_likeliness:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    74
                db_query += '.filter(likeliness_of_attending__gte="%s")'%start_likeliness
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    75
                db_query += '.filter(likeliness_of_attending__lte="%s")'%stop_likeliness
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    76
            elif start_likeliness:
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    77
                db_query += '.filter(likeliness_of_attending__exact="%s")'%start_likeliness
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    78
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    79
            matches = eval(db_query)
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    80
            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
    81
        else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    82
            return render_to_response("list_stats.html", {"form":form})
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    83
    else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    84
        form = SearchForm()
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 23
diff changeset
    85
        return render_to_response("list_stats.html", {"form":form})
26
212fcba4459e changed the app to work with apache + added base.html, and did needed changes.
anoop
parents: 25
diff changeset
    86
65
0ca63c964237 now login is required for accessing stats and send_invi pages
nishanth
parents: 57
diff changeset
    87
@login_required
56
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    88
def send_invi(request):
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    89
    """ Take a list of csv email addresses and send mails to them.
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    90
    """
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    91
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    92
    if request.method == "POST":
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    93
        form = EmailForm(request.POST)
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    94
        if form.is_valid():
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    95
            to_emails = form.cleaned_data['emails']
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    96
            mail_invi(to_emails)
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    97
            return render_to_response("send_invi.html", {"emails":to_emails})
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    98
        else:
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
    99
            return render_to_response("send_invi.html", {"form":form})
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
   100
    else:
57
03150449a049 fixed a bug
nishanth
parents: 56
diff changeset
   101
        form = EmailForm()
56
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
   102
        return render_to_response("send_invi.html", {"form":form})
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
   103
67
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   104
def admin_login(request):
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   105
    """ basic login.
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   106
    """
56
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
   107
67
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   108
    if request.method == "POST":
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   109
        form = LoginForm(request.POST)
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   110
        if form.is_valid():
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   111
            data = form.cleaned_data()
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   112
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   113
            username = data['username']
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   114
            password = data['password']
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   115
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   116
            user = authenticate(username=username, password=password)
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   117
            login(request, user)
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   118
            return redirect("/registration/stats")
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   119
        else:
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   120
            return render_to_response("login.html", {"form":form})
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   121
    else:
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   122
        form = LoginForm()
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   123
        return render_to_response("login.html", {"form":form})
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   124
70
58cafee2ee89 now only logged in users can logout
nishanth
parents: 67
diff changeset
   125
@login_required
67
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   126
def admin_logout(request):
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   127
    """ simply logout.
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   128
    """
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   129
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   130
    logout(request)
b9690fbf78af created views for login and logout
nishanth
parents: 65
diff changeset
   131
    return render_to_response("logout.html")
56
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 53
diff changeset
   132
26
212fcba4459e changed the app to work with apache + added base.html, and did needed changes.
anoop
parents: 25
diff changeset
   133
def homepage(request):
212fcba4459e changed the app to work with apache + added base.html, and did needed changes.
anoop
parents: 25
diff changeset
   134
        return render_to_response("index.html")
212fcba4459e changed the app to work with apache + added base.html, and did needed changes.
anoop
parents: 25
diff changeset
   135
31
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   136
def schedule(request):
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   137
	return render_to_response("schedule.html")
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   138
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   139
def organizers(request):
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   140
	return render_to_response("organizers.html")
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   141
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   142
def venue(request):
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   143
	return render_to_response("venue.html")
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   144
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   145
def contact(request):
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   146
	return render_to_response("contact.html")
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   147
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   148
def about(request):
ec540dfbfe78 added more pages.
anoop
parents: 26
diff changeset
   149
	return render_to_response("about.html")
48
a3e6f9470549 made some changes to links and added accomodation page.
anoop
parents: 31
diff changeset
   150
	
a3e6f9470549 made some changes to links and added accomodation page.
anoop
parents: 31
diff changeset
   151
def accomodation(request):
a3e6f9470549 made some changes to links and added accomodation page.
anoop
parents: 31
diff changeset
   152
	return render_to_response("accomodation.html")