Welcome to referrals’s documentation!¶
Contents:
Django-simple-referrals¶
A simple application that allows you to generate referral links and track referrals
Documentation¶
There are two types of referral structure: flat and multilevel.
A flat structure means that the user can have referrals, and they will all be on the same level.
Multilevel structure means that the user can have children who, in turn, also have children, each of which will be on a level lower (deeper) than the parent.
The full documentation is at https://django-simple-referrals.readthedocs.io.
Quickstart¶
Install referrals:
pip install django-simple-referrals
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'referrals',
...
)
Add referrals’s URL patterns:
from referrals import urls as referrals_urls
urlpatterns = [
...
url(r'^referrals/', include('referrals_urls', namespace='referrals')),
...
]
Usage¶
- Override your SignupForm
from referrals.widgets import ReferralWidget
from referrals.fields import ReferralField
class ReferralSignupForm(SignupForm):
referral = ReferralField(widget=ReferralWidget())
- After registration, send a signal
If you want to use a flat structure:
from referrals.signals import create_flat_referral
create_flat_referral.send(sender=User, request, user)
Or, if you want to use a multi-level structure:
from referrals.signals import create_multi_level_referral
create_flat_referral.send(sender=User, request, user, 'position')
Where the ‘position’ must be ‘child’ or ‘sibling’
If you pass the value “child”, then a child will be created from the referral, by whose link the user has registered. If you specify “sibling”, you will create a referral that is at the same level as the user whose link the user is registered with.
3) Template tags with referral link:
{% referrals %} # Import template tags
{% input %} # Use in any place in your html code
An incompromise will be created with the button “Copy” by clicking on it, the referral link of this user will be copied to the clipboard.
{% token %} # Also you can use this in any place in your html code
It just returns a token with a link to the current site
- Add to your settings:
DJANGO_REFERRALS_DEFAULT_INPUT_VALUE = '40ed41dc-d291-4358-ae4e-d3c07c2d67dc' # The token to be used by
# default. WARNING: Must be uuid4
DJANGO_REFERRALS_DEFAULT_URL = 'http://localhost:8000/' # Address for referral link
DJANGO_REFERRALS_PREFIX = '' # Prefix for key in localStorage.
# by default key its 'referralLink'
DJANGO_REFERRALS_DEFAULT_INPUT_VALUE - This is a user token, under which users will be registered by default.
Get the superuser token:
from django.contrib.auth import get_user_model
from referrals.models import Link
User = get_user_model()
user = User.objects.filter(is_superuser=True).first()
if user:
link = Link.objects.create(user=user)
print(str(link.token))
If you use a multi-level structure, first create a root user:
from referrals.models import MultiLevelReferral
from django.contrib.auth import get_user_model
User = get_user_model()
root_user = User.objects.order_by('?')
MultiLevelReferral.add_root(user=root_user)
Put this javascript code wherever your referral link will lead.
<script type="text/javascript" src="{% url 'referrals:javascript_code' %}"></script>
Features¶
- TODO
- Create a class for extracting the defaul UUID token
- Added social buttons with link and token
Running Tests¶
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox
Installation¶
At the command line:
$ easy_install django-referrals
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv django-referrals
$ pip install django-referrals
Usage¶
To use referrals in a project, add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'referrals.apps.ReferralsConfig',
...
)
Add referrals’s URL patterns:
from referrals import urls as referrals_urls
urlpatterns = [
...
url(r'^', include(referrals_urls)),
...
]
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/narnikgamarnikus/django-referrals/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¶
referrals could always use more documentation, whether as part of the official referrals 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/narnikgamarnikus/django-referrals/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-referrals for local development.
Fork the django-referrals repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/django-referrals.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-referrals $ cd django-referrals/ $ 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 referrals 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/narnikgamarnikus/django-referrals/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Vladimir Myshkovski <vladimirmyshkovski@gmail.com>
Contributors¶
None yet. Why not be the first?