reg/views.py
author nishanth
Mon, 12 Apr 2010 12:08:19 +0530
changeset 12 f57b0a7f24d9
parent 11 334550460bd7
child 13 05248e27104a
permissions -rw-r--r--
added closing and opening of feedback.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
     1
from django.contrib.auth.models import User
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
     2
from django.contrib.auth import authenticate, login, logout
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
     3
from django.contrib.auth.decorators import login_required
2
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
     4
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
     5
from django.shortcuts import render_to_response, redirect
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
     6
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
     7
from workshop.reg.models import Event
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
     8
from workshop.reg import forms as reg_forms
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
     9
from workshop.reg import events as reg_events
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    10
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    11
from workshop.feedback.models import Feedback
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    12
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    13
from django.http import HttpResponse
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    14
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    15
def homepage(request):
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    16
    """ see if the user is active.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    17
    If not, only show the re send activation email link.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    18
    else show all the options in homepage.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    19
    """
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    20
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    21
    user = request.user
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    22
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    23
    events = Event.objects.all()[:10]
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    24
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    25
    return render_to_response('index.html', {'events':events})
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    26
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    27
def user_login(request):
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    28
    """ get the user object from e-mail and then check for password.
2
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
    29
    """
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
    30
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    31
    user = request.user
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    32
    if user.is_authenticated():
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    33
        return redirect('/reg')
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    34
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    35
    if request.method == "POST":
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    36
        form = reg_forms.LoginForm(request.POST)
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    37
        if form.is_valid():
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    38
            email = form.cleaned_data['email']
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    39
            password = form.cleaned_data['password']
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    40
            username = User.objects.get(email__iexact=email).username
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    41
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    42
            user = authenticate(username=username, password=password)
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    43
            login(request, user)
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    44
            return redirect('/reg')
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    45
        else:
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    46
            return render_to_response('login.html', {'form':form})
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    47
    else:
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    48
        form = reg_forms.LoginForm()
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    49
        return render_to_response('login.html', {'form':form})
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    50
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    51
def user_logout(request):
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    52
    """ simply logout the user and redirect to homepage.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    53
    """
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    54
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    55
    logout(request)
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    56
    return redirect('/reg')
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    57
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    58
def user_register(request):
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    59
    """ take the credentials like name, college and gender here itself.
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    60
    """
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    61
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    62
    if request.method == "POST":
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    63
        form = reg_forms.RegisterForm(request.POST)
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    64
        if form.is_valid():
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    65
            data = form.cleaned_data
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    66
            reg_events.create_user(email=data['email'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    67
                                   password=data['password'],
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    68
                                   firstname=data['first_name'],
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    69
                                   lastname=data['last_name'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    70
                                   gender=data['gender'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    71
                                   profession=data['profession'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    72
                                   affiliated_to=data['affiliated_to'], 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    73
                                   interests=data['interests']
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    74
                                  )
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    75
            return render_to_response('account_created.html')
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    76
        else:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    77
            return render_to_response('register.html', {'form':form})
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    78
    else:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    79
        form = reg_forms.RegisterForm()
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    80
        return render_to_response('register.html', {'form':form})
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    81
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    82
def create_event(request):
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    83
    """ see if the user is a staff and only then let him do it.
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    84
    """
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    85
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    86
    user = request.user
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    87
    if user.is_authenticated() and user.is_staff:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    88
        if request.method ==  "POST":
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    89
            form = reg_forms.EventCreateForm(request.POST)
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    90
            if form.is_valid():
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    91
                data = form.cleaned_data
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    92
                new_event = reg_events.create_event(title=data['title'],
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    93
                                                    description=data['description'],
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    94
                                                    start_date=data['start_date'],
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    95
                                                    stop_date=data['stop_date'],
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    96
                                                    created_by=user,
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    97
                                                   )
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    98
                event_url = "/reg/event/view/%s"%(new_event.key)
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
    99
                return redirect(event_url)
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   100
            else:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   101
                return render_to_response('event_create.html', {'form':form})
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   102
        else:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   103
            form = reg_forms.EventCreateForm()
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   104
            return render_to_response('event_create.html', {'form':form})
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   105
    else:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   106
        return redirect('/reg')
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   107
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   108
def view_event(request, key):
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   109
    """ get the event by its key and display it.
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   110
    """
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   111
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   112
    user = request.user
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   113
    user_ip = request.META['REMOTE_ADDR']
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   114
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   115
    try:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   116
        event = Event.objects.get(key__iexact=key)
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   117
    except Event.DoesNotExist:
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   118
        return redirect("/reg")
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   119
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   120
    is_guest = False if user.is_authenticated() else True
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   121
    is_attendee = True if user in event.attendees.all() else False
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   122
    is_org = True if user in event.organizers.all() else False
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   123
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   124
    can_submit_feedback = False
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   125
    if not event.feedback_status == "0":
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   126
        try:
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   127
            event.feedback.get(user_ip__iexact=user_ip, day=event.feedback_status)
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   128
        except Feedback.DoesNotExist:
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   129
            can_submit_feedback = True 
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   130
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   131
    context = {'is_guest': is_guest,
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   132
               'event': event,
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   133
               'is_attendee': is_attendee,
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   134
               'is_org': is_org,
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   135
               'can_submit_feedback': can_submit_feedback,
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   136
              }
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   137
    return render_to_response('view_event.html', context)
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   138
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   139
def reset_password(request):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   140
    """ check for the existance of e-mail.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   141
    Then call the event.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   142
    """
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   143
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   144
    user = request.user
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   145
    if user.is_authenticated():
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   146
        return redirect('/reg')
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   147
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   148
    if request.method == "POST":
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   149
        form = reg_forms.PasswordResetForm(request.POST)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   150
        if form.is_valid():
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   151
            email = form.cleaned_data['email']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   152
            user = User.objects.get(email__iexact=email)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   153
            new_password = reg_events.reset_password(user)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   154
            return render_to_response('password_reset.html', {'new_password':new_password})
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   155
        else:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   156
            return render_to_response('password_reset.html', {'form':form})
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   157
    else:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   158
        form = reg_forms.PasswordResetForm()
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   159
        return render_to_response('password_reset.html', {'form':form})
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   160
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   161
def change_password(request):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   162
    """ check for the password and then set the new password.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   163
    """
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   164
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   165
    user = request.user
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   166
    if not user.is_authenticated():
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   167
        return redirect('/reg')
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   168
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   169
    if request.method == "POST":
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   170
        data = request.POST.copy()
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   171
        data.__setitem__('username', user.username)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   172
        form = reg_forms.PasswordChangeForm(data)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   173
        if form.is_valid():
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   174
            new_password = form.cleaned_data['new_password']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   175
            reg_events.change_password(user, new_password)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   176
            return render_to_response('password_change.html', {'password_changed': True})
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   177
        else:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   178
            return render_to_response('password_change.html', {'form':form})
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   179
    else:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   180
        form = reg_forms.PasswordChangeForm()
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   181
        return render_to_response('password_change.html', {'form':form})
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   182
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   183
def open_feedback(request, event_key):
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   184
    """ see if the event exists.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   185
    then see if feedback is closed.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   186
    then give option for opening the feedback.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   187
    Any feedback can be opened on any day.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   188
    """
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   189
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   190
    user = request.user
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   191
    try:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   192
        event = Event.objects.get(key__iexact=event_key)
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   193
    except Event.DoesNotExist:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   194
        return redirect("/reg")
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   195
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   196
    is_org = True if user in event.organizers.all() else False
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   197
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   198
    if is_org and event.feedback_status == '0':
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   199
        #days = event.stop_date.day() - event.start_date.day() + 1
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   200
        days = 2
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   201
        if request.method == "POST":
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   202
            day = request.POST['day']
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   203
            event.feedback_status = day
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   204
            event.save()
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   205
            return render_to_response('open_feedback.html', {'success': True, 'day':day, 'event':event})
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   206
        else:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   207
            return render_to_response('open_feedback.html', {'event': event, 'days': range(1,days+1)})
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   208
    else:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   209
        return redirect('/reg')
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   210
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   211
def close_feedback(request, event_key):
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   212
    """ check if the user is org.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   213
    and then check if the feedback is open already.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   214
    """
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   215
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   216
    user = request.user
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   217
    try:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   218
        event = Event.objects.get(key__iexact=event_key)
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   219
    except Event.DoesNotExist:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   220
        return redirect("/reg")
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   221
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   222
    is_org = True if user in event.organizers.all() else False
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   223
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   224
    if is_org:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   225
        day = event.feedback_status
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   226
        event.feedback_status = '0'
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   227
        event.save()
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   228
        return render_to_response('close_feedback.html', {'event': event, 'day':day})
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   229
    else:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   230
        return redirect('/reg')
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   231