Django email confirmation for any Model and any Field.
Project description
django-email-confirm-la
Django email confirmation for any Model and any Field.
Requirements
Python (2.7+)
Django (1.6, 1.7)
Installation
$ pip install django-email-confirm-la
in your settings.py:
INSTALLED_APPS = (
...
'email_confirm_la',
...
)
DEFAULT_FROM_EMAIL = 'hello@your-domain.com'
EMAIL_CONFIRM_LA_HTTP_PROTOCOL = 'http'
EMAIL_CONFIRM_LA_DOMAIN = 'your-domain.com'
If you are using the sites framework, then EMAIL_CONFIRM_LA_DOMAIN can be omitted and Site.objects.get_current().domain will be used.
in your urls.py:
urlpatterns = patterns(
'',
url(r'^email_confirmation/', include('email_confirm_la.urls')),
...
)
then run
$ python manage.py syncdb
$ python manage.py migrate
Models
For User Model
from django.contrib.auth.models import User
from email_confirm_la.models import EmailConfirmation
user = User.objects.get(username='vinta')
unconfirmed_email = 'vinta.chen@gmail.com'
email_confirmation = EmailConfirmation.objects.set_email_for_object(
email=unconfirmed_email,
content_object=user,
)
For Any Model And Any Field
assumed you have a model:
from django.db import models
class YourModel(models.Model):
...
user_support_email = models.EmailField(max_length=255)
marketing_email = models.EmailField(max_length=255)
...
and you want to confirm some emails:
from your_app.models import YourModel
from email_confirm_la.models import EmailConfirmation
some_model_instance = YourModel.objects.get(id=42)
email_confirmation = EmailConfirmation.objects.set_email_for_object(
email='marvin@therestaurantattheendoftheuniverse.com',
content_object=some_model_instance,
email_field_name='user_support_email'
)
email_confirmation = EmailConfirmation.objects.set_email_for_object(
email='arthur.dent@therestaurantattheendoftheuniverse.com',
content_object=some_model_instance,
email_field_name='marketing_email'
)
Signals
post_email_confirmation_send
post_email_confirm
post_email_save
you can do something like:
from django.dispatch import receiver
from email_confirm_la.signals import post_email_confirm
@receiver(post_email_confirm)
def post_email_confirm_callback(sender, confirmation, **kwargs):
model_instace = confirmation.content_object
email = confirmation.email
do_stuff()
Commands
$ python manage.py clear_expired_email_confirmations
Settings
Default values of app settings:
EMAIL_CONFIRM_LA_HTTP_PROTOCOL = 'http'
EMAIL_CONFIRM_LA_DOMAIN = ''
EMAIL_CONFIRM_LA_CONFIRM_EXPIRE_SEC = 60 * 60 * 24 * 1 # 1 day
EMAIL_CONFIRM_LA_CONFIRM_URL_REVERSE_NAME = 'confirm_email'
EMAIL_CONFIRM_LA_SAVE_EMAIL_TO_INSTANCE = True
History
0.2.0 (2014-11-08)
Django 1.7 compatibility
0.1.0 (2014-10-31)
Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-email-confirm-la-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8604aacbbfffeaa8536b58dd57a65ead7109f46a13ba7cc07d8bf22afe14500b |
|
MD5 | b5816caa5486379b93507d814b28f4c5 |
|
BLAKE2b-256 | 838cd162cc2b7f5bce0186cdfc13a19e597bd1fbb5b7886ae1ae9772c849b454 |