Commit a5395e8e by benjaoming

syntax highlighting for README

parent 233bcf44
...@@ -8,10 +8,12 @@ and we will try to get the keys for their PyPi repo or something... but meanwhil ...@@ -8,10 +8,12 @@ and we will try to get the keys for their PyPi repo or something... but meanwhil
django_notify does this: django_notify does this:
from django_notify import notify ```python
from django_notify import notify
EVENT_KEY = "my_key"
notify(_("OMG! Something happened"), EVENT_KEY) EVENT_KEY = "my_key"
notify(_("OMG! Something happened"), EVENT_KEY)
```
All users subscribing to `EVENT_KEY` will have a notification created in their All users subscribing to `EVENT_KEY` will have a notification created in their
stack. If you have emails enabled, they may get a summary of notifications at an stack. If you have emails enabled, they may get a summary of notifications at an
...@@ -35,30 +37,32 @@ this: ...@@ -35,30 +37,32 @@ this:
Here is a snippet example to get you started, but you need to get ui.js from [django-wiki/plugins/notifications](https://github.com/benjaoming/django-wiki/tree/master/wiki/plugins/notifications) Here is a snippet example to get you started, but you need to get ui.js from [django-wiki/plugins/notifications](https://github.com/benjaoming/django-wiki/tree/master/wiki/plugins/notifications)
<h2>Notifications:</h2> ```html
<ul> <h2>Notifications:</h2>
<li class="notifications-empty"><a href="#"><em>{% trans "No notifications" %}</em></a></li> <ul>
<li class="divider"></li> <li class="notifications-empty"><a href="#"><em>{% trans "No notifications" %}</em></a></li>
<li> <li class="divider"></li>
<a href="#" onclick="notify_mark_read()"> <li>
<i class="icon-check"></i> <a href="#" onclick="notify_mark_read()">
{% trans "Clear notifications list" %} <i class="icon-check"></i>
</a> {% trans "Clear notifications list" %}
</li> </a>
<!-- Example of a settings page linked directly under the notifications --> </li>
<li> <!-- Example of a settings page linked directly under the notifications -->
<a href="{% url 'wiki:notification_settings' %}"> <li>
<i class="icon-wrench"></i> <a href="{% url 'wiki:notification_settings' %}">
{% trans "Notification settings" %} <i class="icon-wrench"></i>
</a> {% trans "Notification settings" %}
</li> </a>
</ul> </li>
<script type="text/javascript"> </ul>
URL_NOTIFY_GET_NEW = "{% url "notify:json_get" %}"; <script type="text/javascript">
URL_NOTIFY_MARK_READ = "{% url "notify:json_mark_read_base" %}"; URL_NOTIFY_GET_NEW = "{% url "notify:json_get" %}";
URL_NOTIFY_GOTO = "{% url "notify:goto_base" %}"; URL_NOTIFY_MARK_READ = "{% url "notify:json_mark_read_base" %}";
</script> URL_NOTIFY_GOTO = "{% url "notify:goto_base" %}";
<script type="text/javascript" src="{{ STATIC_URL }}wiki/plugins/notifications/js/ui.js"></script> </script>
<script type="text/javascript" src="{{ STATIC_URL }}wiki/plugins/notifications/js/ui.js"></script>
```
Usage Usage
----- -----
...@@ -66,10 +70,12 @@ Usage ...@@ -66,10 +70,12 @@ Usage
### Adding a notification ### Adding a notification
```python
from django_notify import notify from django_notify import notify
EVENT_KEY = "my_key" EVENT_KEY = "my_key"
notify(_("OMG! Something happened"), EVENT_KEY) notify(_("OMG! Something happened"), EVENT_KEY)
```
### Adding a notification with a certain target object ### Adding a notification with a certain target object
...@@ -77,7 +83,9 @@ The Notification model has a GenericForeignKey which can link it to any other ...@@ -77,7 +83,9 @@ The Notification model has a GenericForeignKey which can link it to any other
object. This is nice, because you might have an intention to go the other way object. This is nice, because you might have an intention to go the other way
around and ask "for this object, are there any notifications?" around and ask "for this object, are there any notifications?"
```python
notify(_("OMG! Something happened"), EVENT_KEY, target_object=my_model_instance) notify(_("OMG! Something happened"), EVENT_KEY, target_object=my_model_instance)
```
### Excluding certain recepients ### Excluding certain recepients
...@@ -85,10 +93,12 @@ By setting the kwarg `filter_exclude` to a dictionary of lookup fields for ...@@ -85,10 +93,12 @@ By setting the kwarg `filter_exclude` to a dictionary of lookup fields for
`models.Subscription`, you may exclude certain users from getting a notification. `models.Subscription`, you may exclude certain users from getting a notification.
For instance, if a notification is solely for staff members: For instance, if a notification is solely for staff members:
```python
notify( notify(
_("OMG! Something happened"), EVENT_KEY, _("OMG! Something happened"), EVENT_KEY,
filter_exclude={'settings__user__is_staff': True} filter_exclude={'settings__user__is_staff': True}
) )
```
### Disabling notifications ### Disabling notifications
...@@ -96,10 +106,12 @@ Use `decorators.disable_notify` to ensure that all notifications within a functi ...@@ -96,10 +106,12 @@ Use `decorators.disable_notify` to ensure that all notifications within a functi
For instance: For instance:
```python
from django_notify.decorators import disable_notify from django_notify.decorators import disable_notify
@disable_notify @disable_notify
def my_view(request): def my_view(request):
... ...
```
*This is a work in progress* *This is a work in progress*
---------------------------- ----------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment