<commit_before>django-email-confirm-la
=======================

.. image:: http://img.shields.io/travis/vinta/django-email-confirm-la/master.svg?style=flat-square
    :alt: Build Badge
    :target: https://travis-ci.org/vinta/django-email-confirm-la

.. image:: http://img.shields.io/coveralls/vinta/django-email-confirm-la/master.svg?style=flat-square
    :alt: Coverage Badge
    :target: https://coveralls.io/r/vinta/django-email-confirm-la

.. image:: http://img.shields.io/pypi/v/django-email-confirm-la.svg?style=flat-square
    :alt: Version Badge
    :target: https://pypi.python.org/pypi/django-email-confirm-la

Django email confirmation for any Model and any Field.

Requirements
============

- Python (2.6, 2.7, 3.3, 3.4)
- Django (1.4, 1.5, 1.6, 1.7)

Installation
============

.. code-block:: bash

    $ pip install django-email-confirm-la


In your ``settings.py`` add the ``email_confirm_la`` app (put it *after* your apps) and set the required settings:

.. code-block:: python

    INSTALLED_APPS = (
        ...
        'email_confirm_la',
        ...
    )

    DEFAULT_FROM_EMAIL = '<EMAIL>'
    EMAIL_CONFIRM_LA_HTTP_PROTOCOL = 'http'
    EMAIL_CONFIRM_LA_DOMAIN = 'your-domain.com'

If you are using the `sites <https://docs.djangoproject.com/en/dev/ref/contrib/sites/>`_ framework, then ``EMAIL_CONFIRM_LA_DOMAIN`` can be omitted and ``Site.objects.get_current().domain`` will be used.

in your ``urls.py``:

.. code-block:: python

    urlpatterns = patterns(
        '',
        url(r'^email_confirmation/', include('email_confirm_la.urls')),
        ...
    )

then run

.. code-block:: bash

    $ python manage.py syncdb
    $ python manage.py migrate

Models
======

For User Model
==============

.. code-block:: python

    from django.contrib.auth.models import User
    from email_confirm_la.models import EmailConfirmation

    user = User.objects.get(username='vinta')
    unconfirmed_email = '<EMAIL>'

    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:

.. code-block:: python

    from django.db import models

    class YourModel(models.Model):
        ...
        customer_support_email = models.EmailField(max_length=255, null=True, blank=True)
        marketing_email = models.EmailField(max_length=255, null=True, blank=True)
        ...

and you want to confirm some emails:

.. code-block:: python

    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='<EMAIL>',
        content_object=some_model_instance,
        email_field_name='customer_support_email'
    )

    email_confirmation = EmailConfirmation.objects.set_email_for_object(
        email='<EMAIL>',
        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:

.. code-block:: python

    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
========

.. code-block:: bash

    $ python manage.py clear_expired_email_confirmations

Templates
=========

You will want to override the project's email text and confirmation page.

Ensure the ``email_confirm_la`` app in ``INSTALLED_APPS`` is after the app that you will place the customized templates in so that the `django.template.loaders.app_directories.Loader <https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.app_directories.Loader>`_ finds *your* templates before the default templates.

Then copy the templates into your app:

.. code-block:: bash

    cp -R django-email-confirm-la/email_confirm_la/templates/email_confirm_la your_app/templates/email_confirm_la

Finally, modify them:

* ``email_confirmation_subject.txt``: Produces the subject line of the email.
* ``email/email_confirmation_message.html``: The HTML body of the email.
* ``email_confirm_success.html``: What the user sees after clicking a confirmation link (on success).
* ``email_confirm_fail.html:`` What the user sees after clicking a confirmation link that has expired or is invalid.

Settings
========

Default values of app settings:

.. code-block:: python

    EMAIL_CONFIRM_LA_HTTP_PROTOCOL = 'http'
    EMAIL_CONFIRM_LA_DOMAIN = ''<commit_msg>improve README<commit_after>django-email-confirm-la
=======================

.. image:: http://img.shields.io/travis/vinta/django-email-confirm-la/master.svg?style=flat-square
    :alt: Build Badge
    :target: https://travis-ci.org/vinta/django-email-confirm-la

.. image:: http://img.shields.io/coveralls/vinta/django-email-confirm-la/master.svg?style=flat-square
    :alt: Coverage Badge
    :target: https://coveralls.io/r/vinta/django-email-confirm-la

.. image:: http://img.shields.io/pypi/v/django-email-confirm-la.svg?style=flat-square
    :alt: Version Badge
    :target: https://pypi.python.org/pypi/django-email-confirm-la

Django email confirmation for any Model and any Field.

Requirements
============

- Python (2.6, 2.7, 3.3, 3.4)
- Django (1.4, 1.5, 1.6, 1.7)

Installation
============

.. code-block:: bash

    $ pip install django-email-confirm-la


In your ``settings.py``:

Add the ``email_confirm_la`` app (put it *after* your apps) and set the required settings:

.. code-block:: python

    INSTALLED_APPS = (
        ...
        'email_confirm_la',
        ...
    )

    DEFAULT_FROM_EMAIL = '<EMAIL>'
    EMAIL_CONFIRM_LA_HTTP_PROTOCOL = 'http'
    EMAIL_CONFIRM_LA_DOMAIN = 'your-domain.com'

If you are using the `sites <https://docs.djangoproject.com/en/dev/ref/contrib/sites/>`_ framework, then ``EMAIL_CONFIRM_LA_DOMAIN`` can be omitted and ``Site.objects.get_current().domain`` will be used.

In your ``urls.py``:

.. code-block:: python

    urlpatterns = patterns(
        '',
        url(r'^email_confirmation/', include('email_confirm_la.urls')),
        ...
    )

then run

.. code-block:: bash

    $ python manage.py syncdb
    $ python manage.py migrate

Models
======

For User Model
==============

.. code-block:: python

    from django.contrib.auth.models import User
    from email_confirm_la.models import EmailConfirmation

    user = User.objects.get(username='vinta')
    unconfirmed_email = '<EMAIL>'

    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:

.. code-block:: python

    from django.db import models

    class YourModel(models.Model):
        ...
        customer_support_email = models.EmailField(max_length=255, null=True, blank=True)
        marketing_email = models.EmailField(max_length=255, null=True, blank=True)
        ...

And you want to confirm some emails:

.. code-block:: python

    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='<EMAIL>',
        content_object=some_model_instance,
        email_field_name='customer_support_email'
    )

    email_confirmation = EmailConfirmation.objects.set_email_for_object(
        email='<EMAIL>',
        content_object=some_model_instance,
        email_field_name='marketing_email'
    )

Signals
=======

- ``post_email_confirmation_send``
- ``post_email_confirm``
- ``post_email_save``

In your ``models.py``:

.. code-block:: python

    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
========

.. code-block:: bash

    $ python manage.py clear_expired_email_confirmations

Templates
=========

You will want to override the project's email text and confirmation page.

Ensure the ``email_confirm_la`` app in ``INSTALLED_APPS`` is after the app that you will place the customized templates in so that the `django.template.loaders.app_directories.Loader <https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.app_directories.Loader>`_ finds *your* templates before the default templates.

Then copy the templates into your app:

.. code-block:: bash

    $ cp -R django-email-confirm-la/email_confirm_la/templates/email_confirm_la your_app/templates/email_confirm_la

Finally, modify them:

* ``email/email_confirmation_subject.txt``: Produces the subject line of the email.
* ``email/email_confirmation_message.html``: The HTML body of the email.
* ``email_confirm_success.html``: What the user sees after clicking a confirmation link (on success).
* ``email_confirm_fail.html:`` What the user sees after clicking a confirmation link that has expired or is invalid.

Settings
========

Default values of app settings:

.. code-block:: python

    EMAIL_CONFIRM_LA_HTTP_PROTOCOL = 'http'
    EMAIL_CONFIRM_LA_DOMAIN = ''
{'fraction_non_alphanumeric': 0.13337488314116547, 'fraction_numerical': 0.004985976939856653, 'mean_word_length': 3.747534516765286, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3976800', 'n_tokens_mistral': 3103, 'n_tokens_neox': 2984, 'n_words': 675}