Skip to main content

Add mention feature to your django application.

Project description

=============================
django-exo-mentions
=============================

.. image:: https://badge.fury.io/py/django-exo-mentions.svg
:target: https://badge.fury.io/py/django-exo-mentions

.. image:: https://travis-ci.org/exolever/django-exo-mentions.svg?branch=master
:target: https://travis-ci.org/exolever/django-exo-mentions

.. image:: https://codecov.io/gh/exolever/django-exo-mentions/branch/master/graph/badge.svg
:target: https://codecov.io/gh/exolever/django-exo-mentions


Documentation
-------------

The purpose of this package is to handle in some way mentions to users in a text field of a model. You can choose the model you want, the field you want to listen to mentions, the pattern you use to codify the mention and the callback to notify to your app.

The package will notify to callback function each time there is a mention in this field of the model. Then you can act accordingly on your application requisites.

The full documentation is at https://exo-mentions.readthedocs.io.

Quickstart
----------

Install django-exo-mentions::

pip install django-exo-mentions

=====
Usage
=====

To use django-exo-mentions in a project, add it to your `INSTALLED_APPS`:

.. code-block:: python

INSTALLED_APPS = (
...
'exo_mentions',
...
)

Define a signal for the callback

.. code-block:: python

from django.dispatch import receiver
from django.core.signals import request_finished

@receiver(request_finished)
def post_detect_mention_callback(sender, **kwargs):
""" You will receive information of the mention
user_from: kwargs.get('user_from')
User that mentions
object_pk: kwargs.get('object_pk')
User's Pk that has been mentioned
target: kwargs.get('target')
The object where the mention was made
"""

# Your code here

Register a model and field in which you want to detect mentions.
You can override the pattern if you want.

.. code-block:: python

from django.apps import AppConfig
from exo_mentions.registry import register

class MyAppConfig(AppConfig):
name = 'myapp'

def ready(self):
model = Post
field = 'description'
callback = post_detect_mention_callback

register(model, field, callback)

At this point the library will notify to the callback each time there is a mention in the field of the registered model. Thats all! :)

.. code-block:: python

def register(model, field, callback, pattern):
"""
This method handles the mentions about the model in the field and notify to the callback when there is any mention

Parameters
----------
model : Models
The model to register for detect mentions
field : str
Field of the model to detect mentions
callback : function
Callback function to notify when there are mentions
pattern : regular expression
The pattern to codify the mentions (default r'class="mention" data-user=[\'"]?([^\'" >]+)')

"""


Running Tests
-------------

Does the code actually work?

Docker, Compose, and Tox are used to approximate the environment that Travis CI, Code Climate, and Coveralls all run when you push. This will allow you to test your code against multiple versions of Python (3.4, 3.5, 3.6, 3.7) locally before pushing it or even committing it. For more information about how to get Docker, please visit `documentation
https://docs.docker.com/install/linux/docker-ce/ubuntu/`_.

To run everything (this will take a while the first time you run it, but subsequent runs will be quick):

$ docker build -t django-exo-mentions/tox:latest .




History
-------

1.0.0 (2018-09-25)
++++++++++++++++++

* First release on PyPI.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-exo-mentions-1.0.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distributions

django_exo_mentions-1.0.0-py3.6.egg (16.3 kB view details)

Uploaded Source

django_exo_mentions-1.0.0-py2.py3-none-any.whl (10.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-exo-mentions-1.0.0.tar.gz.

File metadata

  • Download URL: django-exo-mentions-1.0.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.5

File hashes

Hashes for django-exo-mentions-1.0.0.tar.gz
Algorithm Hash digest
SHA256 40f1e9f1cf86455c9fe0688f0a6619ca4d85f8b1b89aac1c68cc4e5b6e967804
MD5 a15c3cbc26695778a5b51ec728508eae
BLAKE2b-256 420e3f7dbf07d1bcfd0c759c491b4a8af90deeeea2e2ee15cafbb0846c8bc08b

See more details on using hashes here.

File details

Details for the file django_exo_mentions-1.0.0-py3.6.egg.

File metadata

  • Download URL: django_exo_mentions-1.0.0-py3.6.egg
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2

File hashes

Hashes for django_exo_mentions-1.0.0-py3.6.egg
Algorithm Hash digest
SHA256 77fc3148f358fa9465d9b0db8b8ac441f9c53c95f918e2affed93fe64ffe30ca
MD5 4f031c559fb30f896e018667fb53d7f8
BLAKE2b-256 252cafa00810d8a03a021f7cb3a4c41b5322047e29a90ae61ca20ced6385f6cf

See more details on using hashes here.

File details

Details for the file django_exo_mentions-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_exo_mentions-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.5

File hashes

Hashes for django_exo_mentions-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8a472e1bb2e025512b3bd2b4bb7667261c8ea4966298a6f89f58aac84c02a461
MD5 67182e8b95b5edd48dc9d6088e1214ac
BLAKE2b-256 ddeb5529bd42b2f929c225e35e8a235cc06f67510043f35e9b6ecb23383bf0b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page