Welcome to django-exo-mentions’s documentation!¶
Contents:
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.
Usage¶
To use django-exo-mentions in a project, add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'exo_mentions',
...
)
Define a signal for the callback
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.
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! :)
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?
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox
Usage¶
To use django-exo-mentions in a project, add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'exo_mentions',
...
)
Add this url to your api urls:
Define a signal for the callback
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. If you want to get trace about who is the user that has made the mention, ensure the model registered define a property or a model field called created_by. You can override the pattern if you want.
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! :)
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=[\'"]?([^\'" >]+)')
"""
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/exolever/django-exo-mentions/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
django-exo-mentions could always use more documentation, whether as part of the official django-exo-mentions docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/exolever/django-exo-mentions/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up django-exo-mentions for local development.
Fork the django-exo-mentions repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/django-exo-mentions.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv django-exo-mentions $ cd django-exo-mentions/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 exo_mentions tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check https://travis-ci.org/exolever/django-exo-mentions/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- marfyl <github.com/marfyl>
- Tomás Garzón <tomasgarzonhervas@gmail.com>
- Javier Sújar <javier.sujar@gmail.com>
Contributors¶
None yet. Why not be the first?
\ Sort by:\ best rated\ newest\ oldest\
\\
Add a comment\ (markup):
\``code``
, \ code blocks:::
and an indented block after blank line