Giter Club home page Giter Club logo

django-notifications's Introduction

django-notifications Documentation

build-status Coverage Status

django-notifications is a GitHub notification alike app for Django, it was derived from django-activity-stream

The major difference between django-notifications and django-activity-stream:

  • django-notifications is for building something like Github "Notifications"
  • While django-activity-stream is for building Github "News Feed"

Notifications are actually actions events, which are categorized by four main components.

  • Actor. The object that performed the activity.
  • Verb. The verb phrase that identifies the action of the activity.
  • Action Object. (Optional) The object linked to the action itself.
  • Target. (Optional) The object to which the activity was performed.

Actor, Action Object and Target are GenericForeignKeys to any arbitrary Django object. An action is a description of an action that was performed (Verb) at some instant in time by some Actor on some optional Target that results in an Action Object getting created/updated/deleted.

For example: justquick (actor) closed (verb) issue 2 (action_object) on activity-stream (target) 12 hours ago

Nomenclature of this specification is based on the Activity Streams Spec: http://activitystrea.ms/specs/atom/1.0/

Requirements

  • Python 3.7, 3.8, 3.9, 3.10, 3.11
  • Django 3.2, 4.0, 4.1

Installation

Installation is easy using pip and will install all required libraries.

$ pip install django-notifications-hq

or get it from source

$ git clone https://github.com/django-notifications/django-notifications
$ cd django-notifications
$ python setup.py sdist
$ pip install dist/django-notifications-hq*

Note that django-model-utils will be installed: this is required for the pass-through QuerySet manager.

Then to add the Django Notifications to your project add the app notifications to your INSTALLED_APPS and urlconf.

The app should go somewhere after all the apps that are going to be generating notifications like django.contrib.auth

INSTALLED_APPS = (
    'django.contrib.auth',
    ...
    'notifications',
    ...
)

Add the notifications urls to your urlconf:

urlpatterns = [
    ...
    path('inbox/notifications/', include('notifications.urls', namespace='notifications')),
    ...
]

To run schema migration, execute python manage.py migrate notifications.

Generating Notifications

Generating notifications is probably best done in a separate signal.

from django.db.models.signals import post_save
from notifications.signals import notify
from myapp.models import MyModel

def my_handler(sender, instance, created, **kwargs):
    notify.send(instance, verb='was saved')

post_save.connect(my_handler, sender=MyModel)

To generate an notification anywhere in your code, simply import the notify signal and send it with your actor, recipient, and verb.

from notifications.signals import notify

notify.send(user, recipient=user, verb='you reached level 10')

The complete syntax is.

notify.send(actor, recipient, verb, action_object, target, level, description, public, timestamp, **kwargs)

Arguments:

  • actor: An object of any type. (Required) Note: Use sender instead of actor if you intend to use keyword arguments
  • recipient: A Group or a User QuerySet or a list of User. (Required)
  • verb: An string. (Required)
  • action_object: An object of any type. (Optional)
  • target: An object of any type. (Optional)
  • level: One of Notification.LEVELS ('success', 'info', 'warning', 'error') (default=info). (Optional)
  • description: An string. (Optional)
  • public: An boolean (default=True). (Optional)
  • timestamp: An tzinfo (default=timezone.now()). (Optional)

Extra data

You can attach arbitrary data to your notifications by doing the following:

  • Add to your settings.py: DJANGO_NOTIFICATIONS_CONFIG = { 'USE_JSONFIELD': True}

Then, any extra arguments you pass to notify.send(...) will be attached to the .data attribute of the notification object. These will be serialised using the JSONField's serialiser, so you may need to take that into account: using only objects that will be serialised is a good idea.

Soft delete

By default, delete/(?P<slug>\d+)/ deletes specified notification record from DB. You can change this behaviour to "mark Notification.deleted field as True" by:

  • Add to your settings.py: DJANGO_NOTIFICATIONS_CONFIG = { 'SOFT_DELETE': True}

With this option, QuerySet methods unread and read contain one more filter: deleted=False. Meanwhile, QuerySet methods deleted, active, mark_all_as_deleted, mark_all_as_active are turned on. See more details in QuerySet methods section.

API

QuerySet methods

Using django-model-utils, we get the ability to add queryset methods to not only the manager, but to all querysets that will be used, including related objects. This enables us to do things like:

    Notification.objects.unread()

which returns all unread notifications. To do this for a single user, we can do:

    user = User.objects.get(pk=pk)
    user.notifications.unread()

There are some other QuerySet methods, too.

qs.unsent()

Return all of the unsent notifications, filtering the current queryset. (emailed=False)

qs.sent()

Return all of the sent notifications, filtering the current queryset. (emailed=True)

qs.unread()

Return all of the unread notifications, filtering the current queryset. When SOFT_DELETE=True, this filter contains deleted=False.

qs.read()

Return all of the read notifications, filtering the current queryset. When SOFT_DELETE=True, this filter contains deleted=False.

qs.mark_all_as_read() | qs.mark_all_as_read(recipient)

Mark all of the unread notifications in the queryset (optionally also filtered by recipient) as read.

qs.mark_all_as_unread() | qs.mark_all_as_unread(recipient)

Mark all of the read notifications in the queryset (optionally also filtered by recipient) as unread.

qs.mark_as_sent() | qs.mark_as_sent(recipient)

Mark all of the unsent notifications in the queryset (optionally also filtered by recipient) as sent.

qs.mark_as_unsent() | qs.mark_as_unsent(recipient)

Mark all of the sent notifications in the queryset (optionally also filtered by recipient) as unsent.

qs.deleted()

Return all notifications that have deleted=True, filtering the current queryset. Must be used with SOFT_DELETE=True.

qs.active()

Return all notifications that have deleted=False, filtering the current queryset. Must be used with DELETE=True.

qs.mark_all_as_deleted() | qs.mark_all_as_deleted(recipient)

Mark all notifications in the queryset (optionally also filtered by recipient) as deleted=True. Must be used with DELETE=True.

qs.mark_all_as_active() | qs.mark_all_as_active(recipient)

Mark all notifications in the queryset (optionally also filtered by recipient) as deleted=False. Must be used with SOFT_DELETE=True.

Model methods

obj.timesince([datetime])

A wrapper for Django's timesince function.

obj.mark_as_read()

Mark the current object as read.

Template tags

Put {% load notifications_tags %} in the template before you actually use notification tags.

notifications_unread

    {% notifications_unread %}

Give the number of unread notifications for a user, or nothing (an empty string) for an anonymous user.

Storing the count in a variable for further processing is advised, such as:

    {% notifications_unread as unread_count %}
    ...
    {% if unread_count %}
        You have <strong>{{ unread_count }}</strong> unread notifications.
    {% endif %}

Live-updater API

To ensure users always have the most up-to-date notifications, django-notifications includes a simple javascript API for updating specific fields within a django template.

There are two possible API calls that can be made:

  1. api/unread_count/ that returns a javascript object with 1 key: unread_count eg:

    {"unread_count":1}
    
  2. api/unread_list/ that returns a javascript object with 2 keys: unread_count and unread_list eg:

    {
     "unread_count":1,
     "unread_list":[--list of json representations of notifications--]
    }
    

    Representations of notifications are based on the django method: model_to_dict

    Query string arguments:

    • max - maximum length of unread list.
    • mark_as_read - mark notification in list as read.

    For example, get api/unread_list/?max=3&mark_as_read=true returns 3 notifications and mark them read (remove from list on next request).

How to use:

  1. Put {% load notifications_tags %} in the template before you actually use notification tags.

  2. In the area where you are loading javascript resources add the following tags in the order below:

    <script src="{% static 'notifications/notify.js' %}" type="text/javascript"></script>
    {% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' %}
    

    register_notify_callbacks takes the following arguments:

    1. badge_class (default live_notify_badge) - The identifier class of the element to show the unread count, that will be periodically updated.
    2. menu_class (default live_notify_list) - The identifier class of the element to insert a list of unread items, that will be periodically updated.
    3. refresh_period (default 15) - How often to fetch unread items from the server (integer in seconds).
    4. fetch (default 5) - How many notifications to fetch each time.
    5. callbacks (default <empty string>) - A comma-separated list of javascript functions to call each period.
    6. api_name (default list) - The name of the API to call (this can be either list or count).
    7. mark_as_read (default False) - Marks notifications as read when fetched.
  3. To insert a live-updating unread count, use the following template:

    {% live_notify_badge %}
    

    live_notify_badge takes the following arguments:

    • badge_class (default live_notify_badge) - The identifier class for the <span> element that will be created to show the unread count.
  4. To insert a live-updating unread list, use the following template:

    {% live_notify_list %}
    

    live_notify_list takes the following arguments:

    • list_class (default live_notify_list) - The identifier class for the <ul> element that will be created to insert the list of notifications into.

Using the live-updater with bootstrap

The Live-updater can be incorporated into bootstrap with minimal code.

To create a live-updating bootstrap badge containing the unread count, simply use the template tag:

{% live_notify_badge badge_class="badge" %}

To create a live-updating bootstrap dropdown menu containing a selection of recent unread notifications, simply use the template tag:

{% live_notify_list list_class="dropdown-menu" %}

Customising the display of notifications using javascript callbacks

While the live notifier for unread counts should suit most use cases, users may wish to alter how unread notifications are shown.

The callbacks argument of the register_notify_callbacks dictates which javascript functions are called when the unread api call is made.

To add a custom javascript callback, simply add this to the list, like so:

{% register_notify_callbacks callbacks='fill_notification_badge,my_special_notification_callback' %}

The above would cause the callback to update the unread count badge, and would call the custom function my_special_notification_callback. All callback functions are passed a single argument by convention called data, which contains the entire result from the API.

For example, the below function would get the recent list of unread messages and log them to the console:

function my_special_notification_callback(data) {
    for (var i=0; i < data.unread_list.length; i++) {
        msg = data.unread_list[i];
        console.log(msg);
    }
}

Testing the live-updater

  1. Clone the repo
  2. Run ./manage.py runserver
  3. Browse to yourserverip/test/
  4. Click 'Make a notification' and a new notification should appear in the list in 5-10 seconds.

Serializing the django-notifications Model

See here - http://www.django-rest-framework.org/api-guide/relations/#generic-relationships

In this example the target object can be of type Foo or Bar and the appropriate serializer will be used.

class GenericNotificationRelatedField(serializers.RelatedField):

    def to_representation(self, value):
        if isinstance(value, Foo):
            serializer = FooSerializer(value)
        if isinstance(value, Bar):
            serializer = BarSerializer(value)

        return serializer.data


class NotificationSerializer(serializers.Serializer):
    recipient = PublicUserSerializer(User, read_only=True)
    unread = serializers.BooleanField(read_only=True)
    target = GenericNotificationRelatedField(read_only=True)

Thanks to @DaWy

AbstractNotification model

In case you need to customize the notification model in order to add field or customised features that depend on your application, you can inherit and extend the AbstractNotification model, example:

#In your_app/models.py

from django.db import models
from notifications.base.models import AbstractNotification


class Notification(AbstractNotification):
    # custom field example
    category = models.ForeignKey('myapp.Category',
                                 on_delete=models.CASCADE)

    class Meta(AbstractNotification.Meta):
        abstract = False

You will require to define NOTIFICATIONS_NOTIFICATION_MODEL setting in setting.py as follows:

# In your_project/settings.py

NOTIFICATIONS_NOTIFICATION_MODEL = 'your_app.Notification'

Notes

Email Notification

Sending email to users has not been integrated into this library. So for now you need to implement it if needed. There is a reserved field Notification.emailed to make it easier.

Sample App

A sample app has been implemented in notifications/tests/sample_notifications that extends django-notifications with the sole purpose of testing its extensibility. You can run the SAMPLE APP by setting the environment variable SAMPLE_APP as follows

export SAMPLE_APP=1
# Run the Django development server with sample_notifications app installed
python manage.py runserver
# Unset SAMPLE_APP to remove sample_notifications app from list of INSTALLED_APPS
unset SAMPLE_APP

django-notifications Team

Core contributors (in alphabetical order):

Contribute

We are looking for contributors, for anyone who'd like to contribute and willing to put time and energy on this project, please contact Yang Yubo.

django-notifications's People

Contributors

alazaro avatar alvarolqueiroz avatar archatas avatar areski avatar danxshap avatar drager avatar driverdan avatar evidlo avatar funkybob avatar giff-h avatar illing2005 avatar julianogouveia avatar kiraware avatar legostormtroopr avatar max-wittig avatar miguelsr avatar miratcan avatar nemesifier avatar osminogin avatar pandafy avatar petrdlouhy avatar schinckel avatar srtab avatar theromis avatar tuky avatar utkucanbykl avatar yangyubo avatar yaoelvon avatar ypcrumble avatar zhang-z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-notifications's Issues

[South migration] DatabaseError: relation "notifications_notification" does not exist

Hi, I'm running into an error though I'm following the installation instructions. Any thoughts what it could be?

DatabaseError: relation "notifications_notification" does not exist

(env)[bteeuwen@Ben-2 ~/dev/mijnhercules]$ pip install django-notifications-hq
Downloading/unpacking django-notifications-hq
  Downloading django-notifications-hq-0.6.0.tar.gz
  Running setup.py egg_info for package django-notifications-hq

    warning: no files found matching '*.txt' under directory 'notifications'
    warning: no files found matching '*.po' under directory 'notifications'
Requirement already satisfied (use --upgrade to upgrade): django>=1.4 in ./env/lib/python2.7/site-packages (from django-notifications-hq)
Downloading/unpacking django-model-utils>=1.1.0 (from django-notifications-hq)
  Downloading django-model-utils-1.4.0.tar.gz
  Running setup.py egg_info for package django-model-utils

Installing collected packages: django-notifications-hq, django-model-utils
  Running setup.py install for django-notifications-hq

    warning: no files found matching '*.txt' under directory 'notifications'
    warning: no files found matching '*.po' under directory 'notifications'
  Running setup.py install for django-model-utils

Successfully installed django-notifications-hq django-model-utils
Cleaning up...

(env)[bteeuwen@Ben-2 ~/dev/mijnhercules]$ ./manage.py migrate notifications --fake 0001
 - Soft matched migration 0001 to 0001_initial.
Running migrations for notifications:
 - Migrating forwards to 0001_initial.
 > notifications:0001_initial
   (faked)

(env)[bteeuwen@Ben-2 ~/dev/mijnhercules]$ ./manage.py migrate notifications
Running migrations for notifications:
 - Migrating forwards to 0006_auto__add_field_notification_level.
 > notifications:0002_auto__add_field_notification_data
FATAL ERROR - The following SQL query failed: ALTER TABLE "notifications_notification" ADD COLUMN "data" text NULL;
The error was: relation "notifications_notification" does not exist

Error in migration: notifications:0002_auto__add_field_notification_data
DatabaseError: relation "notifications_notification" does not exist

Publish to PyPI

Latest version on PyPI is 0.7.0 and there have been some nice features added since then.

User gets notifications of their own activity

Hello :) First of all, I think this is a great notifications package! I've just managed to implement it and I've noticed a little issue that I haven't been able to solve... I have notifications set up for comments, so when someone posts a comment on an object, the user who owns that object is notified. However, when a user posts a comment on their own object, they still receive a notification that they have done so. It's not a huge issue, but perhaps a little annoying and confusing from a users point of view. I was wondering if anyone knows how to prevent sending notifications to a user if they are the owner of the object they are commenting on... I'm using the following code to generate the notification:

def comment_action(sender, comment=None, target=None, **kwargs):
    if comment.user:
        notify.send(comment.user, recipient=comment.content_object.user, verb=u'commented', action_object=comment,
            target=comment.content_object, description=comment.comment)
comment_was_posted.connect(comment_action)

Emailing Notification

Hi All,

I might be being dense - if so apologies!

I can see a model field for 'emailed', but cannot see a way to actually trigger sending an email to the recipient. How does one do this?

Thanks

Any tutorial out there?

It's a bit confusing for a newbie to use it. Is there a real app tutorial out there for django-notifications?

Missing migration

Currently in git the last migration is 0003. Makemigrations produces another migration that is not in git.
It would be great to update this, since it makes some problems deploying in some environments.

-Thanks!

Configure continuous testing

It'd be handy to have a continuous testing suite configured so as pull requests come in we can easily verify the integrity of the code.

I've used travis-CI and Coveralls on a few projects and its really handy. Unfortunately, only project owners or members of the organisation can do this. If you haven't got the time, if you add me in I'd be happy to volunteer to do this as its relatively straight forward. You can then remove me after as its a one time setup.

Why is pagination ignored in the all() view?

I'm trying to get pagination working and saw the page = request.GET.get('p') code in the all view, but it wasn't working.

After a closer look it seems there is a return straight back on lines 19-21:

return render(request, 'notifications/list.html', {
    'notifications': qs
})

So the code after this never executes.
Is there a reason for this?

Template tags

Hi all. First of all thanks for the great app, it's working really smooth and took almost no time to learn how to use it.

The thing here is that I could create notifications on post_save signals, I could then gather the unread messages for a user and pass them to the template to show them, but what I couldn't manage to do looking at the docs (readme) and trying every possible format for the tags is how to place the notifications_unread in the template. It's always empty.

I tried:

· {% notifications_unread %}
· {{ notifications_unread }}
· {% with notifications_unread as unread_count %}
{% endwith %}

And all are giving unknown tag error. Thanks in advance.

get unread notifications list more than 5

when use register_notify_callbacks to get the list of unread notifications objects, the default size is 5, how to get all unread objects use this? how to send the 'max' value in {% register_notify_callbacks callback='....' %} ?

Notification to all users

Hi!, in my project i need that all users receive a notification when some event occurs. Is that possible?

Thanks

Release problems

I think there were some problems with the latest releases, the released versions do not have the bugfixes for the custom user models problem.

Notifications for many users

Hi!

I was checking the project and I found it really great! , I am using it in mi app to notify when a meeting is programed, is edited or is canceled. I need to notify about the meeting changes for all meeting guests.

I tried to pass an array in the parameter recipient however it get me an error. Is there any way to notify all my meeting guests about the meeting changes? Can I use the lib for that purpose?

Thanks!

Best regards

Support For Django 1.9 In pip installed package

Two things seem to be true about the version of django-notifications-hq which pip installs:

  1. It's incompatible with django 1.9
  2. The source isn't the same as what's presently in the git repo, for example init.py

Am I missing something? Or will it take some time until a compatible version makes it into pip?

?next={{ some_url }} doesn't url_decode {{ some_url }}

Suppose I send a user to /inbox/notifications/mark-as-read/111270/ but I want to send them on to another page straight away.

So I use e.g.:

`/inbox/notifications/mark-as-read/111270/?next=/some_page/

But if I want to send them to e.g. /some_page/?get_var=hello_world I get stuck. I can urlencode the ?next= url but django-notifications doesn't decode this correctly. Is there a reason for this? If not I'll form the repo and add the urldecode to views.py's _next bits.

Typo in README.md

from notifications.signal import notify

The 'signal' should be 'signals'.

'ascii' codec can't decode byte error when accessing admin interface

Hi guys,
First of all I would like to say thank you for this app. It's really easy to setup and use it and it brings a lot of great functionality. It works great but when I try to open notifications list in Django admin interface I'm getting this error:

'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128). You passed in <Notification: [Bad Unicode data]> (<class 'notifications.models.Notification'>)

I think this happens because I have cyrillic characters in notification target field. This issue is also reproducible with django-activity-stream. Please let me know if there is any temporary workaround. I'm using django-notifications-hq==0.6.2.

Notifications with anonymous actors

First off this is a great app, thanks for sharing your code.

On my site I'd like to be able to send notifications where the actor is an unregistered user. How would you recommend doing this? Setting null=True on the actor field, or creating an "anonymous" user in the database?

wrong migrations when using custom user model

I am using custom user model, so the table for model auth.User doesn't exists. However the migration depends on its existence.

One solution is to create your own migration:
./manage.py schemamigration notifications --auto
so the Foreign key dependency is changed to the actual custom user model. This is not very convenient.

Another would be to drop migrations altogether and depend on syncdb. This however would break future compatibility.

Any other idea?

PyPi Version is old

Hi, any chance you could update the version on PyPi?

The code is nearly a year old and doesn't support custom user models.

Thanks!

Serializing the django-notifications Model

I'm trying to serialize the model included in django-notifications package with DRF (for a RESTFUL API)

But i'm facing a problem. When I acces the model Notification inside notifications\models.py and try to make a ModelSerializer of it, then raise this error:

NotificationQuerySet' object has no attribute 'recipient'.

My ModelSerializer:

class NotificationSerializer(serializers.ModelSerializer):

    class Meta:
        model = Notification
        fields = ('description', 'recipient',)

Any tip on this? I don't understand why is trying to accesing NotificationQuerySet instead of Notification model...

Thanks in andvance.

Lack of AJAX functionality

Hi, great package, thanks for it, good job!

In my opinion it doesn't have some ajax functionality. It's not the good idea to re render and redirect a user to the same page after marking a single notice as read. It would be nice to add this functionality as in most cases we use this marking buttons near the notice and don't want to reload the page.

I think it's possible to check if request.is_ajax() in views and perform certain actions. What are your thoughts on this?

Date reading of a notification

Hello,

We know if a notification was read but we don't know when exactly, would it not possible to add the date in models?

Thanks.

Live javascript updater failing to work

More details were raised by @thetylerhayes here in #72:

I know this has already been merged, but where are item.object and item.subject in this repo's standard JSON response? Those aren't available in data.unread_list items AFAICT.

I'm testing out this repo right now and it's falling down here.

Screenshots may help:

screenshot 2015-11-10 16 57 21

screenshot 2015-11-10 16 58 17

Difference with Django-Activity-Stream

Hello, in your readme, you note this was derived from Django-Activity-Stream. Besides the name, what distinguishes this package from D.A.S?

If there is something obvious, it could be helpful to add it to the readme to aid developers evaluating the many choices of activity packages.

Thank you.

Deleting doesn't do anything

I'm having issues with an unrelated bug and was going back over some code changes and it seems that the delete view was changed to use a delete flag f351e92 , however the querysets don't actually filter these out. So a notification is flagged as deleted, but still appears (I think).

@zhang-z obviously included and recommended this change for a reason, so their input would be handy.

But there are a few proposals I can think of:

  1. Revert to use djangos delete, have user rely on third party libraries to manage recovery
    • Pros: Notifications are low information so deleting won't lose info
    • Cons: Relies on third-party apps
  2. Override all queryset so deleted notifications are hidden, add deleted queryset to access, posibly even a 'trash' view for recovering/permanently deleting notifications
    • Pros: Self-contained management of deletes, easier/safer for users, more "professional" approach
    • Cons: (minimal) feature bloat, minor additional effort to make new screens.

Each has their benefits and drawbacks, so thoughts would be handy. Its a small piece of work either way and I can find some time to fix it up, but it is worth investigating before a 0.6.3 release.

Reverse relations

Have you considered creating reverse generic relations so that given an action object, you can easily get a reference to any notifications for it?

For example, in my delete_comment view, I'd like to get any notification objects for that comment and delete them. A reverse relation would be very helpful here.

Deprecation warning: RemovedInDjango19Warning

I can see following warning in Django 1.8:

django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.

from django.contrib.contenttypes import generic

HTML Representation

Hey,

First thanks for the awesome simple setup for this. django-notification was really outdated and broken and I didn't like it.

So for displaying notifications, in the comments on the model it shows an example of html output labeled HTML Representation. Does the model give output for that and if so how can I display it that way in a template? Or is it just showing how you could lay it out?

Invalid block tag: 'register_notify_callbacks'

Hello guys,

First, i don't know if this is the right channel to place this question. Let me know if there is a more appropriate mail-list.

I'm running Python3.4 and Django1.8. And i'm getting this kind of errors from register_notify_callbacks, when rendering the template:

TemplateSyntaxError at /dashboard/
Invalid block tag: 'register_notify_callbacks'
{% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' %}

Are Python3.4 and Django1.8 supported?
Am I missing something?

<!-- base.html -->
  1 {% load staticfiles %}
  2 {% load notifications_tags %}
 25 
 26     <!-- Django Notifications-->
 27     <script src="{% static 'notifications/notify.js' %}" type="text/javascr
 28     {% register_notify_callbacks callbacks='fill_notification_list,fill_not
 29 
# settings.py
 33 INSTALLED_APPS = (
 34     'django_admin_bootstrapped',
 35     'django.contrib.admin',
 36     'django.contrib.auth',
 37     'django.contrib.contenttypes',
 38     'django.contrib.sessions',
 39     'django.contrib.messages',
 40     'django.contrib.staticfiles',
 41     'django_extensions',
 42     'rest_framework',
 43     'water_meter',
 44     'website',
 45     'sabesp',
 46     'bootstrapform',
 47     'localflavor',
 48     'notifications',
 49 )

Thanks!

JSON access to recent notifications

Some projects may find it useful to have an easy to drop in Javascript/JSON function with an appropriate updating field that fetches notifications on behalf of the user:

For example, inserting the code similar to the following into a template:

{% load notifications_tags %}
{% live_notify_icon %}

Would provide an auto-updating notification badge indicating there are unread notfications, without a page refresh.

Similarly, something like this:

{% load notifications_tags %}
{% live_notify_menu 5 %}

Would provide a simple ul menu with the 5 most recent unread notifications (with the number being configurable).

I've assigned this bug to me already and can do some work on it, and if there is interest we can look at pulling it in.

For reference, this would be done in a way that adds no extra requirements, and done using raw javascript so we don't force libraries like jquery onto users.

Any thoughts on this?

AttributeError: 'module' object has no attribute 'PassThroughManager'

I'm unable to import any notification.models because they reference a manager that no longer exists in a dependent package:

Traceback:
   File "/usr/local/myproject/src/myproject/myapp/models.py", line 100, in <module>
     from notifications.models import Notification
   File "/usr/local/myproject/.env/local/lib/python2.7/site-packages/notifications/models.py", line 123, in <module>
     class Notification(models.Model):
   File "/usr/local/myproject/.env/local/lib/python2.7/site-packages/notifications/models.py", line 185, in Notification
     objects = managers.PassThroughManager.for_queryset_class(NotificationQuerySet)()
AttributeError: 'module' object has no attribute 'PassThroughManager'

It looks like PassThroughManager was removed but the setup.py still allows this incompatible version to be installed.

AppRegistryNotReady with Django 1.9

I use Django 1.9 and django-notifications-hq 0.8.0. When I run python manage.py runserver, it raises this exception. When I remove notifications from INSTALLED_APPS, the exception goes away.

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/me/myproject/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/me/myproject/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/me/myproject/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
    commands = get_commands()
  File "/home/me/myproject/.venv/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
    result = user_function(*args, **kwds)
  File "/home/me/myproject/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
    for app_config in reversed(list(apps.get_app_configs())):
  File "/home/me/myproject/.venv/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
    self.check_apps_ready()
  File "/home/me/myproject/.venv/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.