<s> import json <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import HttpResponse <EOL> from django . shortcuts import render , Http404 , HttpResponseRedirect , redirect , get_object_or_404 <EOL> from . models import Notification <EOL> @ login_required <EOL> def all ( request ) : <EOL> notifications = Notification . objects . all_for_user ( request . user ) <EOL> context = { <EOL> "<STR_LIT>" : notifications , <EOL> } <EOL> return render ( request , "<STR_LIT>" , context ) <EOL> @ login_required <EOL> def read ( request , id ) : <EOL> notification = get_object_or_404 ( Notification , id = id ) <EOL> try : <EOL> next = request . GET . get ( '<STR_LIT>' , None ) <EOL> if notification . recipient == request . user : <EOL> notification . read = True <EOL> notification . save ( ) <EOL> if next is not None : <EOL> return HttpResponseRedirect ( next ) <EOL> else : <EOL> return redirect ( "<STR_LIT>" ) <EOL> else : <EOL> raise Http404 <EOL> except : <EOL> raise redirect ( "<STR_LIT>" ) <EOL> @ login_required <EOL> def get_notifications_ajax ( request ) : <EOL> if request . is_ajax ( ) and request . method == "<STR_LIT:POST>" : <EOL> notifications = Notification . objects . all_for_user ( request . user ) . recent ( ) <EOL> count = notifications . count ( ) <EOL> notes = [ ] <EOL> for note in notifications : <EOL> notes . append ( str ( note . get_link ) ) <EOL> data = { <EOL> "<STR_LIT>" : notes , <EOL> "<STR_LIT:count>" : count , <EOL> } <EOL> print data <EOL> json_data = json . dumps ( data ) <EOL> print json_data <EOL> return HttpResponse ( json_data , content_type = '<STR_LIT:application/json>' ) <EOL> else : <EOL> raise Http404 </s>
