Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelgodshall/469628 to your computer and use it in GitHub Desktop.
Save michaelgodshall/469628 to your computer and use it in GitHub Desktop.
#Taken from http://groups.google.com/group/django-users/browse_thread/thread/a743280fd76845e3#
class OfflineNotification(models.Model):
user = models.ForeignKey(User)
message = models.TextField()
level = models.PositiveSmallIntegerField(default=20)
created = models.DateTimeField(auto_now_add=True)
class OfflineNotificationsMiddleware:
def process_request(self, request):
if request.user.is_authenticated():
notifications = OfflineNotification.objects.filter(user=request.user).distinct('message')
for notification in notifications:
messages.add_message(request, notification.level, notification.message)
if notifications:
OfflineNotification.objects.filter(user=request.user).delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment