# Path: registration/models.py
# class RegistrationProfile(models.Model):
#     """
#     A simple profile which stores an activation key for use during
#     user account registration.
#     
#     Generally, you will not want to interact directly with instances
#     of this model; the provided manager includes methods
#     for creating and activating new accounts, as well as for cleaning
#     out accounts which have never been activated.
#     
#     While it is possible to use this model as the value of the
#     ``AUTH_PROFILE_MODULE`` setting, it's not recommended that you do
#     so. This model's sole purpose is to store data temporarily during
#     account registration and activation.
#     
#     """
#     ACTIVATED = u"ALREADY_ACTIVATED"
#     
#     user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
#     activation_key = models.CharField(_('activation key'), max_length=40)
#     language = models.CharField(_(u'Language'), max_length=5, default='en')
#     objects = RegistrationManager()
#     
#     class Meta:
#         verbose_name = _('registration profile')
#         verbose_name_plural = _('registration profiles')
#     
#     def __unicode__(self):
#         return u"Registration information for %s" % self.user
#     
#     def activation_key_expired(self):
#         """
#         Determine whether this ``RegistrationProfile``'s activation
#         key has expired, returning a boolean -- ``True`` if the key
#         has expired.
#         
#         Key expiration is determined by a two-step process:
#         
#         1. If the user has already activated, the key will have been
#            reset to the string constant ``ACTIVATED``. Re-activating
#            is not permitted, and so this method returns ``True`` in
#            this case.
# 
#         2. Otherwise, the date the user signed up is incremented by
#            the number of days specified in the setting
#            ``ACCOUNT_ACTIVATION_DAYS`` (which should be the number of
#            days after signup during which a user is allowed to
#            activate their account); if the result is less than or
#            equal to the current date, the key has expired and this
#            method returns ``True``.
#         
#         """
#         expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)
#         return self.activation_key == self.ACTIVATED or \
#                (self.user.date_joined + expiration_date <= datetime_now())
#     activation_key_expired.boolean = True
# 
#     def send_activation_email(self, site):
#         """
#         Send an activation email to the user associated with this
#         ``RegistrationProfile``.
#         
#         The activation email will make use of two templates:
# 
#         ``registration/activation_email_subject.txt``
#             This template will be used for the subject line of the
#             email. Because it is used as the subject line of an email,
#             this template's output **must** be only a single line of
#             text; output longer than one line will be forcibly joined
#             into only a single line.
# 
#         ``registration/activation_email.txt``
#             This template will be used for the body of the email.
# 
#         These templates will each receive the following context
#         variables:
# 
#         ``activation_key``
#             The activation key for the new account.
# 
#         ``expiration_days``
#             The number of days remaining during which the account may
#             be activated.
# 
#         ``site``
#             An object representing the site on which the user
#             registered; depending on whether ``django.contrib.sites``
#             is installed, this may be an instance of either
#             ``django.contrib.sites.models.Site`` (if the sites
#             application is installed) or
#             ``django.contrib.sites.models.RequestSite`` (if
#             not). Consult the documentation for the Django sites
#             framework for details regarding these objects' interfaces.
# 
#         """
#         ctx_dict = {'activation_key': self.activation_key,
#                     'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
#                     'site': site}
#         subject = render_to_string('registration/activation_email_subject.txt',
#                                    ctx_dict)
#         # Email subject *must not* contain newlines
#         subject = ''.join(subject.splitlines())
#         
#         message = render_to_string('registration/activation_email.txt',
#                                    ctx_dict)
#         
#         celery_send_mail.delay(subject, message, settings.DEFAULT_FROM_EMAIL, self.user.email)


from django.contrib import admin
from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from registration.models import RegistrationProfile
        """
        Activates the selected users, if they are not alrady
        activated.
        
        """
        for profile in queryset:
            RegistrationProfile.objects.activate_user(profile.activation_key)
    activate_users.short_description = _("Activate users")

    def resend_activation_email(self, request, queryset):
        """
        Re-sends activation emails for the selected users.

        Note that this will *only* send activation emails for users
        who are eligible to activate; emails will not be sent to users
        whose activation keys have expired or who have already
        activated.
        
        """
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)

        for profile in queryset:
            if not profile.activation_key_expired():
                profile.send_activation_email(site)
    resend_activation_email.short_description = _("Re-send activation emails")



# Path: registration/models.py
# class RegistrationProfile(models.Model):
#     """
#     A simple profile which stores an activation key for use during
#     user account registration.
#     
#     Generally, you will not want to interact directly with instances
#     of this model; the provided manager includes methods
#     for creating and activating new accounts, as well as for cleaning
#     out accounts which have never been activated.
#     
#     While it is possible to use this model as the value of the
#     ``AUTH_PROFILE_MODULE`` setting, it's not recommended that you do
#     so. This model's sole purpose is to store data temporarily during
#     account registration and activation.
#     
#     """
#     ACTIVATED = u"ALREADY_ACTIVATED"
#     
#     user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
#     activation_key = models.CharField(_('activation key'), max_length=40)
#     language = models.CharField(_(u'Language'), max_length=5, default='en')
#     objects = RegistrationManager()
#     
#     class Meta:
#         verbose_name = _('registration profile')
#         verbose_name_plural = _('registration profiles')
#     
#     def __unicode__(self):
#         return u"Registration information for %s" % self.user
#     
#     def activation_key_expired(self):
#         """
#         Determine whether this ``RegistrationProfile``'s activation
#         key has expired, returning a boolean -- ``True`` if the key
#         has expired.
#         
#         Key expiration is determined by a two-step process:
#         
#         1. If the user has already activated, the key will have been
#            reset to the string constant ``ACTIVATED``. Re-activating
#            is not permitted, and so this method returns ``True`` in
#            this case.
# 
#         2. Otherwise, the date the user signed up is incremented by
#            the number of days specified in the setting
#            ``ACCOUNT_ACTIVATION_DAYS`` (which should be the number of
#            days after signup during which a user is allowed to
#            activate their account); if the result is less than or
#            equal to the current date, the key has expired and this
#            method returns ``True``.
#         
#         """
#         expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)
#         return self.activation_key == self.ACTIVATED or \
#                (self.user.date_joined + expiration_date <= datetime_now())
#     activation_key_expired.boolean = True
# 
#     def send_activation_email(self, site):
#         """
#         Send an activation email to the user associated with this
#         ``RegistrationProfile``.
#         
#         The activation email will make use of two templates:
# 
#         ``registration/activation_email_subject.txt``
#             This template will be used for the subject line of the
#             email. Because it is used as the subject line of an email,
#             this template's output **must** be only a single line of
#             text; output longer than one line will be forcibly joined
#             into only a single line.
# 
#         ``registration/activation_email.txt``
#             This template will be used for the body of the email.
# 
#         These templates will each receive the following context
#         variables:
# 
#         ``activation_key``
#             The activation key for the new account.
# 
#         ``expiration_days``
#             The number of days remaining during which the account may
#             be activated.
# 
#         ``site``
#             An object representing the site on which the user
#             registered; depending on whether ``django.contrib.sites``
#             is installed, this may be an instance of either
#             ``django.contrib.sites.models.Site`` (if the sites
#             application is installed) or
#             ``django.contrib.sites.models.RequestSite`` (if
#             not). Consult the documentation for the Django sites
#             framework for details regarding these objects' interfaces.
# 
#         """
#         ctx_dict = {'activation_key': self.activation_key,
#                     'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
#                     'site': site}
#         subject = render_to_string('registration/activation_email_subject.txt',
#                                    ctx_dict)
#         # Email subject *must not* contain newlines
#         subject = ''.join(subject.splitlines())
#         
#         message = render_to_string('registration/activation_email.txt',
#                                    ctx_dict)
#         
#         celery_send_mail.delay(subject, message, settings.DEFAULT_FROM_EMAIL, self.user.email)


# Path: registration/admin.py
from django.contrib import admin
from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from registration.models import RegistrationProfile

        """
        Activates the selected users, if they are not alrady
        activated.
        
        """
        for profile in queryset:
            RegistrationProfile.objects.activate_user(profile.activation_key)
    activate_users.short_description = _("Activate users")

    def resend_activation_email(self, request, queryset):
        """
        Re-sends activation emails for the selected users.

        Note that this will *only* send activation emails for users
        who are eligible to activate; emails will not be sent to users
        whose activation keys have expired or who have already
        activated.
        
        """
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)

        for profile in queryset:
            if not profile.activation_key_expired():
                profile.send_activation_email(site)
    resend_activation_email.short_description = _("Re-send activation emails")



admin.site.register(RegistrationProfile, RegistrationAdmin)