Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone, translation, six
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from django.contrib.auth.models import AnonymousUser
Expand All @@ -29,6 +30,7 @@
from account.signals import signup_code_sent, signup_code_used


@python_2_unicode_compatible
class Account(models.Model):

user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name="account", verbose_name=_("user"))
Expand Down Expand Up @@ -107,6 +109,7 @@ def user_post_save(sender, **kwargs):
Account.create(user=user)


@python_2_unicode_compatible
class AnonymousAccount(object):

def __init__(self, request=None):
Expand All @@ -117,10 +120,11 @@ def __init__(self, request=None):
else:
self.language = translation.get_language_from_request(request, check_path=True)

def __unicode__(self):
def __str__(self):
return "AnonymousAccount"


@python_2_unicode_compatible
class SignupCode(models.Model):

class AlreadyExists(Exception):
Expand All @@ -143,7 +147,7 @@ class Meta:
verbose_name = _("signup code")
verbose_name_plural = _("signup codes")

def __unicode__(self):
def __str__(self):
if self.email:
return "{0} [{1}]".format(self.email, self.code)
else:
Expand Down Expand Up @@ -243,6 +247,7 @@ def save(self, **kwargs):
self.signup_code.calculate_use_count()


@python_2_unicode_compatible
class EmailAddress(models.Model):

user = models.ForeignKey(settings.AUTH_USER_MODEL)
Expand All @@ -258,7 +263,7 @@ class Meta:
if not settings.ACCOUNT_EMAIL_UNIQUE:
unique_together = [("user", "email")]

def __unicode__(self):
def __str__(self):
return "{0} ({1})".format(self.email, self.user)

def set_as_primary(self, conditional=False):
Expand Down Expand Up @@ -293,6 +298,7 @@ def change(self, new_email, confirm=True):
self.send_confirmation()


@python_2_unicode_compatible
class EmailConfirmation(models.Model):

email_address = models.ForeignKey(EmailAddress)
Expand All @@ -306,7 +312,7 @@ class Meta:
verbose_name = _("email confirmation")
verbose_name_plural = _("email confirmations")

def __unicode__(self):
def __str__(self):
return "confirmation for {0}".format(self.email_address)

@classmethod
Expand Down