reg/views.py
author nishanth
Fri, 23 Apr 2010 16:35:42 +0530
changeset 98 1af134a1e53d
parent 80 cb36fc4f29df
child 99 cc2ed87ee896
permissions -rwxr-xr-x
now an email will be sent to user after he resets his password.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
     1
from datetime import datetime
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
     2
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
     3
from django.http import Http404
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
     4
from django.utils.datastructures import MultiValueDictKeyError
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
     5
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
     6
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
     7
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
     8
from django.contrib.auth.decorators import login_required
2
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
     9
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    10
from django.shortcuts import render_to_response, redirect
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    11
62
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 58
diff changeset
    12
from ws_app.reg.models import Event, Profile
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 58
diff changeset
    13
from ws_app.reg import forms as reg_forms
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 58
diff changeset
    14
from ws_app.reg import events as reg_events
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    15
62
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 58
diff changeset
    16
from ws_app.feedback.models import Feedback, FeedLog
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    17
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    18
def homepage(request):
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    19
    """ see if the user is active.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    20
    If not, only show the re send activation email link.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    21
    else show all the options in homepage.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    22
    """
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    23
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    24
    user = request.user
47
e1895d2ede97 now registered workshops appear on home page .
nishanth
parents: 46
diff changeset
    25
    if user.is_authenticated() and user.is_active:
e1895d2ede97 now registered workshops appear on home page .
nishanth
parents: 46
diff changeset
    26
        registered_events = user.event_attendees.all()
e1895d2ede97 now registered workshops appear on home page .
nishanth
parents: 46
diff changeset
    27
    else:
e1895d2ede97 now registered workshops appear on home page .
nishanth
parents: 46
diff changeset
    28
        registered_events = None
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    29
47
e1895d2ede97 now registered workshops appear on home page .
nishanth
parents: 46
diff changeset
    30
    return render_to_response('index.html', {'user':user, 'registered_events':registered_events})
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    31
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    32
def user_login(request):
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    33
    """ get the user object from e-mail and then check for password.
2
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
    34
    """
c11afa8623f7 incorporated gen_key .
nishanth
parents: 0
diff changeset
    35
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    36
    user = request.user
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    37
    if user.is_authenticated():
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
    38
        return redirect("/workshop/registration")
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    39
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    40
    if request.method == "POST":
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    41
        form = reg_forms.LoginForm(request.POST)
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    42
        if form.is_valid():
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    43
            email = form.cleaned_data['email']
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    44
            password = form.cleaned_data['password']
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    45
            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
    46
50
fd37bbece439 now a user can login even if he is not active. he gets account inactive message on homepage. we have to make changes to other views suitably .
nishanth
parents: 49
diff changeset
    47
            new_user = authenticate(username=username, password=password)
fd37bbece439 now a user can login even if he is not active. he gets account inactive message on homepage. we have to make changes to other views suitably .
nishanth
parents: 49
diff changeset
    48
            login(request, new_user)
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
    49
            return redirect("/workshop/registration")
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    50
        else:
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
    51
            return render_to_response('login.html', {'user':user, 'form':form})
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents: 2
diff changeset
    52
    else:
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    53
        form = reg_forms.LoginForm()
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
    54
        return render_to_response('login.html', {'user':user, 'form':form})
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    55
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    56
def user_logout(request):
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    57
    """ simply logout the user and redirect to homepage.
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    58
    """
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    59
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    60
    logout(request)
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
    61
    return redirect("/workshop/registration")
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    62
45
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    63
def user_register(request, event_key):
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    64
    """ 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
    65
    """
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    66
45
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    67
    if event_key:
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    68
        try:
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    69
            event = Event.objects.get(key=event_key)
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    70
        except Event.DoesNotExist:
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    71
            raise Http404
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    72
46
ff5f34e42aec registration for workshop is now integrated with man registartion.
nishanth
parents: 45
diff changeset
    73
        if not event.registration_is_open:
ff5f34e42aec registration for workshop is now integrated with man registartion.
nishanth
parents: 45
diff changeset
    74
            raise Http404
ff5f34e42aec registration for workshop is now integrated with man registartion.
nishanth
parents: 45
diff changeset
    75
    else:
ff5f34e42aec registration for workshop is now integrated with man registartion.
nishanth
parents: 45
diff changeset
    76
        event = None
45
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    77
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    78
    if request.method == "POST":
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(request.POST)
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    80
        if form.is_valid():
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    81
            data = form.cleaned_data
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    82
            new_user = reg_events.create_user(email=data['email'],
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    83
                                              password=data['password'],
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    84
                                              first_name=data['first_name'],
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    85
                                              last_name=data['last_name'], 
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    86
                                              gender=data['gender'], 
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    87
                                              profession=data['profession'], 
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    88
                                              affiliated_to=data['affiliated_to'], 
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    89
                                              interests=data['interests']
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
    90
                                             )
45
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    91
46
ff5f34e42aec registration for workshop is now integrated with man registartion.
nishanth
parents: 45
diff changeset
    92
            if event:
45
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    93
                event.attendees.add(new_user)
b66d405eb8c7 now after registration, user is also added to corresponding workshop .
nishanth
parents: 44
diff changeset
    94
                event.save()
58
a26c82f593f0 implemented send activation. have to test it and do the same for change password.
nishanth
parents: 57
diff changeset
    95
            reg_events.send_activation(new_user)
80
cb36fc4f29df changed url in few other locations.
nishanth
parents: 77
diff changeset
    96
            return redirect('/workshop/registration/account_created')
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    97
        else:
46
ff5f34e42aec registration for workshop is now integrated with man registartion.
nishanth
parents: 45
diff changeset
    98
            return render_to_response('register.html', {'form':form, 'event':event})
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
    99
    else:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 5
diff changeset
   100
        form = reg_forms.RegisterForm()
46
ff5f34e42aec registration for workshop is now integrated with man registartion.
nishanth
parents: 45
diff changeset
   101
        return render_to_response('register.html', {'form':form, 'event':event})
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   102
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   103
def account_created(request):
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   104
    """ simply display a page.
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   105
    """
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   106
    
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   107
    user = request.user
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   108
    return render_to_response('account_created.html', {'user':user})
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   109
23
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   110
def account_activate(request, activation_key):
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   111
    """ see if the key exists.
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   112
    see if the corresponding user is inactive.
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   113
    """
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   114
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   115
    user = request.user
58
a26c82f593f0 implemented send activation. have to test it and do the same for change password.
nishanth
parents: 57
diff changeset
   116
    if user.is_authenticated() and user.is_active:
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
   117
        return redirect("/workshop/registration")
23
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   118
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   119
    try:
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   120
        profile = Profile.objects.get(activation_key__iexact=activation_key)
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   121
    except Profile.DoesNotExist:
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   122
        raise Http404
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   123
48
9a52ca561c1d fixed a bug in activate user and made a change in activated template .
nishanth
parents: 47
diff changeset
   124
    new_user = profile.user
9a52ca561c1d fixed a bug in activate user and made a change in activated template .
nishanth
parents: 47
diff changeset
   125
    reg_events.activate_user(new_user)
23
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   126
    return render_to_response('account_activated.html', {'user':user})
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   127
    
21
a0f4aba61275 renamed send_activation to resend_activation .
nishanth
parents: 20
diff changeset
   128
def resend_activation(request):
23
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   129
    """ resend only if user is registered and is inactive.
42e2a810e1c8 modified seed_db and view_event template .
nishanth
parents: 21
diff changeset
   130
    """
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   131
49
4c1d3fe9fef1 fixed a small bug.
nishanth
parents: 48
diff changeset
   132
    user = request.user
50
fd37bbece439 now a user can login even if he is not active. he gets account inactive message on homepage. we have to make changes to other views suitably .
nishanth
parents: 49
diff changeset
   133
    if not user.is_authenticated():
fd37bbece439 now a user can login even if he is not active. he gets account inactive message on homepage. we have to make changes to other views suitably .
nishanth
parents: 49
diff changeset
   134
        raise Http404
fd37bbece439 now a user can login even if he is not active. he gets account inactive message on homepage. we have to make changes to other views suitably .
nishanth
parents: 49
diff changeset
   135
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   136
    try:
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   137
        email = request.GET['email']
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   138
    except MultiValueDictKeyError:
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   139
        raise Http404
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   140
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   141
    try:
49
4c1d3fe9fef1 fixed a small bug.
nishanth
parents: 48
diff changeset
   142
        new_user = User.objects.get(email__iexact=email)
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   143
    except User.DoesNotExist:
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   144
        raise Http404
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   145
49
4c1d3fe9fef1 fixed a small bug.
nishanth
parents: 48
diff changeset
   146
    if new_user.is_active:
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
   147
        return redirect("/workshop/registration")
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   148
    
49
4c1d3fe9fef1 fixed a small bug.
nishanth
parents: 48
diff changeset
   149
    profile = new_user.get_profile()
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   150
    activation_key = profile.activation_key
49
4c1d3fe9fef1 fixed a small bug.
nishanth
parents: 48
diff changeset
   151
    reg_events.send_activation(new_user)
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   152
    
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   153
    return render_to_response('sent_activationkey.html', {'user':user})
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   154
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   155
def create_event(request):
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   156
    """ 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
   157
    """
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   158
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   159
    user = request.user
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   160
    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
   161
        if request.method ==  "POST":
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   162
            form = reg_forms.EventCreateForm(request.POST)
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   163
            if form.is_valid():
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   164
                data = form.cleaned_data
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   165
                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
   166
                                                    description=data['description'],
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   167
                                                    start_date=data['start_date'],
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   168
                                                    stop_date=data['stop_date'],
43
757d1da69255 added venue field in event model and corresponding forms and views.
nishanth
parents: 37
diff changeset
   169
                                                    venue=data['venue'],
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   170
                                                    created_by=user,
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   171
                                                   )
77
121a7aa78469 changed the urls to map to new url configuration.
nishanth
parents: 76
diff changeset
   172
                event_url = "/workshop/registration/event/view/%s"%(new_event.key)
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   173
                return redirect(event_url)
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   174
            else:
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   175
                return render_to_response('event_create.html', {'user':user, 'form':form})
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   176
        else:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   177
            form = reg_forms.EventCreateForm()
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   178
            return render_to_response('event_create.html', {'user':user, 'form':form})
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   179
    else:
51
08da9bd64fca changed redirect to 404 in one place and updated 404 page.
nishanth
parents: 50
diff changeset
   180
        raise Http404
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   181
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   182
def view_event(request, key):
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   183
    """ 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
   184
    """
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   185
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   186
    user = request.user
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   187
    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
   188
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   189
    try:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 6
diff changeset
   190
        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
   191
    except Event.DoesNotExist:
77
121a7aa78469 changed the urls to map to new url configuration.
nishanth
parents: 76
diff changeset
   192
        return redirect("/workshop/registration")
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   193
57
d321a507fc26 updated view_event page .
nishanth
parents: 55
diff changeset
   194
    is_attendee = True if user.is_active and user in event.attendees.all() else False
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   195
    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
   196
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   197
    can_submit_feedback = False
57
d321a507fc26 updated view_event page .
nishanth
parents: 55
diff changeset
   198
    if not event.feedback_status == "0" and user.is_authenticated():
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   199
        try:
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 54
diff changeset
   200
            FeedLog.objects.get(user=user,event=event,day=event.feedback_status)
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 54
diff changeset
   201
        except FeedLog.DoesNotExist:
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   202
            can_submit_feedback = True 
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   203
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   204
    context = {'user': user,
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   205
               'event': event,
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   206
               'is_attendee': is_attendee,
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   207
               'is_org': is_org,
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
   208
               'can_submit_feedback': can_submit_feedback,
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   209
              }
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 9
diff changeset
   210
    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
   211
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   212
def reset_password(request):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   213
    """ check for the existance of e-mail.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   214
    Then call the event.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   215
    """
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   216
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   217
    user = request.user
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   218
    if user.is_authenticated():
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
   219
        return redirect("/workshop/registration")
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   220
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   221
    if request.method == "POST":
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   222
        form = reg_forms.PasswordResetForm(request.POST)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   223
        if form.is_valid():
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   224
            email = form.cleaned_data['email']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   225
            user = User.objects.get(email__iexact=email)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   226
            new_password = reg_events.reset_password(user)
98
1af134a1e53d now an email will be sent to user after he resets his password.
nishanth
parents: 80
diff changeset
   227
            reg_events.mail_password(user, new_password)
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   228
            return render_to_response('password_reset.html', {'user':user, 'new_password':new_password})
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   229
        else:
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   230
            return render_to_response('password_reset.html', {'user':user, 'form':form})
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   231
    else:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   232
        form = reg_forms.PasswordResetForm()
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   233
        return render_to_response('password_reset.html', {'user':user, 'form':form})
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   234
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   235
def change_password(request):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   236
    """ check for the password and then set the new password.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   237
    """
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   238
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   239
    user = request.user
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   240
    if not user.is_authenticated():
52
0cd75815847d changed redirect to 404 in change password view
nishanth
parents: 51
diff changeset
   241
        raise Http404
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   242
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   243
    if request.method == "POST":
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   244
        data = request.POST.copy()
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   245
        data.__setitem__('username', user.username)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   246
        form = reg_forms.PasswordChangeForm(data)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   247
        if form.is_valid():
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   248
            new_password = form.cleaned_data['new_password']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   249
            reg_events.change_password(user, new_password)
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   250
            return render_to_response('password_change.html', {'user':user, 'password_changed': True})
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   251
        else:
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   252
            return render_to_response('password_change.html', {'user':user, 'form':form})
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   253
    else:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   254
        form = reg_forms.PasswordChangeForm()
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   255
        return render_to_response('password_change.html', {'user':user, 'form':form})
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   256
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   257
def open_feedback(request, event_key):
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   258
    """ see if the event exists.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   259
    then see if feedback is closed.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   260
    then give option for opening the feedback.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   261
    Any feedback can be opened on any day.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   262
    """
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   263
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   264
    user = request.user
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   265
    try:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   266
        event = Event.objects.get(key__iexact=event_key)
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   267
    except Event.DoesNotExist:
33
6a68ef9597f9 now opening feedback code is a lil more better .
nishanth
parents: 32
diff changeset
   268
        raise Http404
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   269
44
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   270
    if user in event.organizers.all() and user.is_staff:
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   271
        if event.feedback_status == '0':
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   272
            no_of_days = (event.stop_date - event.start_date).days + 1
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   273
            if request.method == "POST":
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   274
                day = request.POST['day']
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   275
                event.feedback_status = day
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   276
                event.save()
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   277
                return render_to_response('open_feedback.html', {'user':user, 'success': True, 'day':day, 'event':event})
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   278
            else:
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   279
                return render_to_response('open_feedback.html', {'user':user, 'event': event, 'days': range(1,no_of_days+1)})
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   280
        else:
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 43
diff changeset
   281
            day = event.feedback_status
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   282
            return render_to_response('open_feedback.html', {'user':user, 'success': True, 'day':day, 'event':event})
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   283
    else:
27
ea6aef4b379d instead of redirecting I am now raising http 404 .
nishanth
parents: 25
diff changeset
   284
        raise Http404
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   285
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   286
def close_feedback(request, event_key):
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   287
    """ check if the user is org.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   288
    and then check if the feedback is open already.
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   289
    """
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   290
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   291
    user = request.user
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   292
    try:
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   293
        event = Event.objects.get(key__iexact=event_key)
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   294
    except Event.DoesNotExist:
32
00a016cf226e now opening feedback code is a lil better .
nishanth
parents: 31
diff changeset
   295
        raise Http404
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   296
32
00a016cf226e now opening feedback code is a lil better .
nishanth
parents: 31
diff changeset
   297
    if user in event.organizers.all() and user.is_staff:
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   298
        day = event.feedback_status
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   299
        event.feedback_status = '0'
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   300
        event.save()
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   301
        return render_to_response('close_feedback.html', {'user':user, 'event': event, 'day':day})
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   302
    else:
32
00a016cf226e now opening feedback code is a lil better .
nishanth
parents: 31
diff changeset
   303
        raise Http404
12
f57b0a7f24d9 added closing and opening of feedback.
nishanth
parents: 11
diff changeset
   304
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   305
def open_registration(request, event_key):
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   306
    """ simply check for is_org and then set the registration_is_open flag.
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   307
    """
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   308
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   309
    user = request.user
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   310
    try:
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   311
        event = Event.objects.get(key__iexact=event_key)
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   312
    except Event.DoesNotExist:
77
121a7aa78469 changed the urls to map to new url configuration.
nishanth
parents: 76
diff changeset
   313
        return redirect("/workshop/registration")
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   314
31
d0a2f881d4b5 now opening registration code is a lil better .
nishanth
parents: 30
diff changeset
   315
    if user in event.organizers.all() and user.is_staff:
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   316
        event.registration_is_open = True
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   317
        event.save()
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   318
        return render_to_response('reg_open.html', {'user':user, 'event': event})
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   319
    else:
31
d0a2f881d4b5 now opening registration code is a lil better .
nishanth
parents: 30
diff changeset
   320
        raise Http404
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   321
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   322
def close_registration(request, event_key):
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   323
    """ simply check for is_org and then unset the registration_is_open flag.
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   324
    """
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   325
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   326
    user = request.user
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   327
    try:
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   328
        event = Event.objects.get(key__iexact=event_key)
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   329
    except Event.DoesNotExist:
77
121a7aa78469 changed the urls to map to new url configuration.
nishanth
parents: 76
diff changeset
   330
        return redirect("/workshop/registration")
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   331
30
b85cb9cc9010 now closing registration code is a lil better .
nishanth
parents: 29
diff changeset
   332
    if user in event.organizers.all() and user.is_staff:
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   333
        event.registration_is_open = False
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   334
        event.save()
14
cd6911eaac2c moved templates into templates directory and added user in context .
nishanth
parents: 13
diff changeset
   335
        return render_to_response('reg_close.html', {'user':user, 'event': event})
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   336
    else:
30
b85cb9cc9010 now closing registration code is a lil better .
nishanth
parents: 29
diff changeset
   337
        raise Http404
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   338
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   339
def register_for_event(request, event_key):
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   340
    """ check if the user is logged in.
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   341
    simply add him to the attendees list.
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   342
    """
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   343
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   344
    user = request.user
20
9354ef8119c6 added account_inactive and resend_activationkey functionalities
nishanth
parents: 19
diff changeset
   345
    if user.is_authenticated() and user.is_active:
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   346
        try:
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   347
            event = Event.objects.get(key__iexact=event_key)
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   348
        except Event.DoesNotExist:
77
121a7aa78469 changed the urls to map to new url configuration.
nishanth
parents: 76
diff changeset
   349
            return redirect("/workshop/registration")
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   350
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   351
        event.attendees.add(user)
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   352
        return render_to_response("event_register.html", {"user":user, 'event':event})
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   353
    else:
77
121a7aa78469 changed the urls to map to new url configuration.
nishanth
parents: 76
diff changeset
   354
        return redirect("/workshop/registration")
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   355
17
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   356
def view_profile(request):
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   357
    """ check if user is logged in.
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   358
    then show the profile.
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   359
    """
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   360
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   361
    user = request.user
50
fd37bbece439 now a user can login even if he is not active. he gets account inactive message on homepage. we have to make changes to other views suitably .
nishanth
parents: 49
diff changeset
   362
    if not ( user.is_authenticated() and user.is_active ):
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
   363
        return redirect("/workshop/registration")
17
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   364
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   365
    user_profile = user.get_profile()
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   366
    return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile})
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   367
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   368
def edit_profile(request):
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   369
    """ check if user is logged in.
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   370
    """
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   371
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   372
    user = request.user
54
345d4413b85c added is_active filter in list_feedbacks view.
nishanth
parents: 52
diff changeset
   373
    if not ( user.is_authenticated() and user.is_active ):
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
   374
        return redirect("/workshop/registration")
17
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   375
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   376
    user_profile = user.get_profile()
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   377
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   378
    if request.method == "POST":
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   379
        form = reg_forms.EditProfileForm(request.POST)
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   380
        if form.is_valid():
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   381
            reg_events.update_profile(user, form.cleaned_data)
80
cb36fc4f29df changed url in few other locations.
nishanth
parents: 77
diff changeset
   382
            return redirect('/workshop/registration/profile/view')
17
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   383
        else:
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   384
            return render_to_response('edit_profile.html', {'user':user, 'form':form})
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   385
    else:
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   386
        old_info = {'first_name': user.first_name,
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   387
                    'last_name': user.last_name,
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   388
                    'gender':user_profile.gender,
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   389
                    'profession': user_profile.profession,
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   390
                    'affiliated_to': user_profile.affiliated_to,
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   391
                    'interests': user_profile.interests,
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   392
                   }
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   393
        form = reg_forms.EditProfileForm(old_info)
125b6fc8f20b users can view and edit profile .
nishanth
parents: 16
diff changeset
   394
        return render_to_response('edit_profile.html', {'user':user, 'form':form})
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   395
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   396
def list_events(request):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   397
    """ Get all the events including those that are over and list them.
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   398
    """
13
05248e27104a added closing registration and registering for a workshop .
nishanth
parents: 12
diff changeset
   399
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   400
    user = request.user
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   401
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   402
    today = datetime.now()
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   403
    context = {'user':user,
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   404
               'upcoming_events': Event.objects.filter(start_date__gt=today),
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   405
               'ongoing_events': Event.objects.filter(start_date__lte=today, stop_date__gte=today),
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   406
               'previous_events': Event.objects.filter(stop_date__lt=today),
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   407
              }
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   408
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   409
    return render_to_response('list_events.html', context)
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   410
19
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   411
def list_attendees(request, event_key):
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   412
    """ see if the request user is org.
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   413
    Else redirect him to homepage.
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   414
    """
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   415
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   416
    user = request.user
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   417
    try:
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   418
        event = Event.objects.get(key__iexact=event_key)
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   419
    except Event.DoesNotExist:
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
   420
        return redirect("/workshop/registration")
19
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   421
54
345d4413b85c added is_active filter in list_feedbacks view.
nishanth
parents: 52
diff changeset
   422
    if not user in event.organizers.all() and user.is_active:
76
b0f5c8666edf changed the redirect path to new home page everywhere.
nishanth
parents: 62
diff changeset
   423
        return redirect("/workshop/registration")
19
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   424
    
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   425
    profile = user.get_profile()
115860e87238 implemented list people functionality .
nishanth
parents: 18
diff changeset
   426
    return render_to_response('list_attendees.html', {'user':user, 'event':event, 'attendees':event.attendees.all()})