pytask/profile/views.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Sun, 16 Jan 2011 20:54:42 +0530
changeset 427 42156890006d
parent 418 df241055a1a7
child 440 56ea209e559f
permissions -rwxr-xr-x
Move all the content from create form to edit form for tasks.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
     1
from django import shortcuts
266
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
     2
from django.contrib.auth.decorators import login_required
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
     3
from django.contrib.auth.models import User
269
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
     4
from django.core.context_processors import csrf
411
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
     5
from django.core.urlresolvers import reverse
409
09e381a7c2c3 Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 378
diff changeset
     6
from django.http import Http404
269
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
     7
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
     8
from pytask.profile.forms import EditProfileForm
409
09e381a7c2c3 Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 378
diff changeset
     9
from pytask.profile.utils import get_notification
09e381a7c2c3 Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 378
diff changeset
    10
from pytask.profile.utils import get_user
09e381a7c2c3 Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 378
diff changeset
    11
266
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    12
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    13
@login_required
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    14
def view_profile(request):
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
    15
    """ Display the profile information.
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
    16
    """
266
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    17
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    18
    user = request.user
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    19
    profile = user.get_profile()
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    20
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    21
    context = {"user": user,
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    22
               "profile": profile,
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    23
              }
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    24
    return shortcuts.render_to_response("profile/view.html", context)
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    25
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    26
@login_required
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    27
def view_user_profile(request, user_id):
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    28
    """ Display the profile information of the user specified in the ID.
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    29
    """
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    30
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    31
    
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    32
    user = shortcuts.get_object_or_404(User, pk=user_id)
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    33
    profile = user.get_profile()
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    34
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    35
    context = {"user": user,
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    36
               "profile": profile,
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    37
              }
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    38
    return shortcuts.render_to_response("profile/view.html", context)
269
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    39
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    40
@login_required
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    41
def edit_profile(request):
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
    42
    """ Make only a few fields editable.
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
    43
    """
269
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    44
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    45
    user = request.user
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    46
    profile = user.get_profile()
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    47
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    48
    context = {"user": user,
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    49
               "profile": profile,
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    50
              }
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    51
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    52
    context.update(csrf(request))
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    53
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    54
    if request.method == "POST":
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    55
        form = EditProfileForm(request.POST, instance=profile)
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    56
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    57
        if form.is_valid():
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    58
            form.save()
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    59
            return shortcuts.redirect(reverse('view_profile'))
269
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    60
        else:
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    61
            context.update({"form":form})
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    62
            return shortcuts.render_to_response("profile/edit.html", context)
269
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    63
    else:
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    64
        form = EditProfileForm(instance=profile)
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    65
        context.update({"form":form})
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    66
        return shortcuts.render_to_response("profile/edit.html", context)
273
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    67
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    68
@login_required
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    69
def browse_notifications(request):
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    70
    """ get the list of notifications that are not deleted and display in
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    71
    datetime order."""
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    72
275
c701e68f8d35 fixed a typo and browse notifications works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 274
diff changeset
    73
    user = request.user
273
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    74
411
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
    75
    active_notifications = user.notification_sent_to.filter(
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
    76
      is_deleted=False).order_by('-sent_date')
273
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    77
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    78
    context = {'user':user,
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    79
               'notifications':active_notifications,
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    80
              }                               
274
5cd56898033c created template for browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 273
diff changeset
    81
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    82
    return shortcuts.render_to_response('profile/browse_notifications.html', context)
276
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    83
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    84
@login_required
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    85
def view_notification(request, notification_id):
276
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    86
    """ get the notification depending on nid.
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    87
    Display it.
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    88
    """
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    89
282
69d1c4b99503 fixed a typo
Nishanth Amuluru <nishanth@fossee.in>
parents: 276
diff changeset
    90
    user = request.user
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    91
    newest, newer, notification, older, oldest = get_notification(
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
    92
      notification_id, user)
276
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    93
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    94
    if not notification:
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    95
        raise Http404
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    96
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    97
    notification.is_read = True
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    98
    notification.save()
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
    99
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   100
    context = {'user':user,
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   101
               'notification':notification,
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   102
               'newest':newest,
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   103
               'newer':newer,
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   104
               'older':older,
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   105
               'oldest':oldest,
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   106
              }
c8c47fcb46f0 created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 275
diff changeset
   107
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   108
    return shortcuts.render_to_response(
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   109
      'profile/view_notification.html', context)
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   110
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   111
@login_required
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   112
def delete_notification(request, notification_id):
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   113
    """ check if the user owns the notification and delete it.
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   114
    """
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   115
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   116
    user = request.user
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   117
    newest, newer, notification, older, oldest = get_notification(
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   118
      notification_id, user)
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   119
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   120
    if not notification:
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   121
        raise Http404
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   122
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   123
    notification.is_deleted = True
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   124
    notification.save()
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   125
288
869a9ab7e2df fixed few typos
Nishanth Amuluru <nishanth@fossee.in>
parents: 287
diff changeset
   126
    if older:
411
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
   127
        redirect_url = reverse('view_notification',
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
   128
                               kwargs={'notification_id': older.id})
288
869a9ab7e2df fixed few typos
Nishanth Amuluru <nishanth@fossee.in>
parents: 287
diff changeset
   129
    else:
411
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
   130
        redirect_url = reverse('browse_notifications')
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   131
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   132
    return shortcuts.redirect(redirect_url)
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   133
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   134
@login_required
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   135
def unread_notification(request, notification_id):
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   136
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   137
    """ check if the user owns the notification and delete it.
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   138
    """
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   139
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   140
    user = request.user
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   141
    newest, newer, notification, older, oldest = get_notification(
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   142
      notification_id, user)
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   143
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   144
    if not notification:
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   145
        raise Http404
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   146
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   147
    notification.is_read = False
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   148
    notification.save()
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   149
288
869a9ab7e2df fixed few typos
Nishanth Amuluru <nishanth@fossee.in>
parents: 287
diff changeset
   150
    if older:
411
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
   151
        redirect_url = reverse('view_notification',
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
   152
                               kwargs={'notification_id': older.id})
288
869a9ab7e2df fixed few typos
Nishanth Amuluru <nishanth@fossee.in>
parents: 287
diff changeset
   153
    else:
411
edf514c6a820 Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 409
diff changeset
   154
        redirect_url = reverse('browse_notifications')
287
d24b4a7147d2 created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents: 282
diff changeset
   155
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   156
    return shortcuts.redirect(redirect_url)
378
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   157
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   158
@login_required
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   159
def view_user(request, uid):
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   160
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   161
    user = request.user
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   162
    profile = user.get_profile()
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   163
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   164
    viewing_user = get_user(uid)
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   165
    viewing_profile = viewing_user.get_profile()
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   166
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   167
    working_tasks = viewing_user.approved_tasks.filter(status="WR")
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   168
    completed_tasks = viewing_user.approved_tasks.filter(status="CM")
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   169
    reviewing_tasks = viewing_user.reviewing_tasks.all()
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   170
    claimed_tasks = viewing_user.claimed_tasks.all()
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   171
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   172
    can_view_info = True if profile.rights in ["MG", "DC"] else False
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   173
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   174
    context = {"user": user,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   175
               "profile": profile,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   176
               "viewing_user": viewing_user,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   177
               "viewing_profile": viewing_profile,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   178
               "working_tasks": working_tasks,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   179
               "completed_tasks": completed_tasks,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   180
               "reviewing_tasks": reviewing_tasks,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   181
               "claimed_tasks": claimed_tasks,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   182
               "can_view_info": can_view_info,
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   183
              }
8fcde6f8f750 added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents: 307
diff changeset
   184
418
df241055a1a7 Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 411
diff changeset
   185
    return shortcuts.render_to_response("profile/view_user.html", context)