profile/views.py
author Nishanth Amuluru <nishanth@fossee.in>
Fri, 07 Jan 2011 12:53:12 +0530
changeset 281 20f411241654
parent 276 c8c47fcb46f0
child 282 69d1c4b99503
permissions -rwxr-xr-x
added key to the notification
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
     1
from django.shortcuts import render_to_response, redirect
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
     2
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
     3
from django.contrib.auth.decorators import login_required
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
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
     5
from django.views.decorators.csrf import csrf_protect
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
     6
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
     7
from pytask.profile.forms import EditProfileForm
266
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
     8
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
     9
@login_required
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    10
def view_profile(request):
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    11
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    12
    user = request.user
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    13
    profile = user.get_profile()
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    14
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    15
    context = {"user": user,
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    16
               "profile": profile,
4dfcc826b241 Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 241
diff changeset
    17
              }
267
b1245d75938d Added template for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents: 266
diff changeset
    18
    return 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
    19
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    20
@login_required
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    21
def edit_profile(request):
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    22
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    23
    user = request.user
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    24
    profile = user.get_profile()
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    25
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    26
    context = {"user": user,
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    27
               "profile": profile,
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    28
              }
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    29
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    30
    context.update(csrf(request))
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    31
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    32
    if request.method == "POST":
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    33
        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
    34
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    35
        if form.is_valid():
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    36
            form.save()
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    37
            return redirect("/accounts/profile/view")
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    38
        else:
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    39
            context.update({"form":form})
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    40
            return render_to_response("profile/edit.html", context)
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    41
    else:
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    42
        form = EditProfileForm(instance=profile)
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    43
        context.update({"form":form})
dde894b36370 created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents: 267
diff changeset
    44
        return 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
    45
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    46
@login_required
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    47
def browse_notifications(request):
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    48
    """ 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
    49
    datetime order."""
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    50
275
c701e68f8d35 fixed a typo and browse notifications works fine
Nishanth Amuluru <nishanth@fossee.in>
parents: 274
diff changeset
    51
    user = request.user
273
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    52
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    53
    active_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date').reverse()
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    54
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    55
    context = {'user':user,
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    56
               'notifications':active_notifications,
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    57
              }                               
274
5cd56898033c created template for browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 273
diff changeset
    58
273
8318df7e2d52 created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 269
diff changeset
    59
    return 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
    60
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
    61
@login_required
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
    62
def view_notification(request, 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
    63
    """ 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
    64
    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
    65
    """
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
    66
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
    67
    user = get_user(request.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
    68
    newest, newer, notification, older, 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
    69
    get_notification(nid, 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
    70
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
    71
    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
    72
        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
    73
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
    74
    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
    75
    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
    76
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
    77
    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
    78
               '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
    79
               '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
    80
               '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
    81
               '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
    82
               '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
    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
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
    85
    return render_to_response('profile/view_notification.html', context)