Python django.db.models.EmailField() Examples

The following are 10 code examples of django.db.models.EmailField(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.db.models , or try the search function .
Example #1
Source File: models.py    From django-ra-erp with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_redirect_url_prefix(cls):
        """
        Get the url for the change list of this model
        :return: a string url
        """
        return reverse('%s:%s_%s_changelist' % (
            app_settings.RA_ADMIN_SITE_NAME, cls._meta.app_label, cls.get_class_name().lower()))


# class BasePersonInfo(BaseInfo):
#     address = models.CharField(_('address'), max_length=260, null=True, blank=True)
#     telephone = models.CharField(_('telephone'), max_length=130, null=True, blank=True)
#     email = models.EmailField(_('email'), null=True, blank=True)
#
#     class Meta:
#         abstract = True
#         # swappable = swapper.swappable_setting('ra', 'BasePersonInfo') 
Example #2
Source File: introspect.py    From django-anonymizer with MIT License 5 votes vote down vote up
def get_replacer_for_field(field):
    # Some obvious ones:
    if isinstance(field, EmailField):
        return '"email"'

    # Use choices, if available.
    choices = getattr(field, 'choices', None)
    if choices is not None and len(choices) > 0:
        return '"choice"'

    field_type = field.get_internal_type()
    if field_type == "CharField" or field_type == "TextField":
        # Guess by the name

        # First, go for complete match
        for pattern, result in charfield_replacers:
            if re.match(pattern + "$", field.attname):
                return result

        # Then, go for a partial match.
        for pattern, result in charfield_replacers:
            if re.search(pattern, field.attname):
                return result

        # Nothing matched.
        if field_type == "TextField":
            return '"lorem"'

        # Just try some random chars
        return '"varchar"'

    try:
        r = field_replacers[field_type]
    except KeyError:
        r = "UNKNOWN_FIELD"

    return r 
Example #3
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_email_convert_string():
    assert_conversion(models.EmailField, graphene.String) 
Example #4
Source File: models.py    From PonyConf with Apache License 2.0 5 votes vote down vote up
def get_filter_url(self):
        return reverse('talk-list') + '?category=%d' % self.pk


#class Attendee(PonyConfModel):
#
#    user = models.ForeignKey(User, null=True)
#    name = models.CharField(max_length=64, blank=True, default="")
#    email = models.EmailField(blank=True, default="")
#
#    def get_name(self):
#        if self.user:
#            return str(self.user.profile)
#        else:
#            return self.name
#    get_name.short_description = _('Name')
#
#    def get_email(self):
#        if self.user:
#            return self.user.email
#        else:
#            return self.email
#    get_email.short_description = _('Email')
#
#    def __str__(self):
#        return self.get_name() 
Example #5
Source File: tests.py    From django-sqlserver with MIT License 5 votes vote down vote up
def test_email_field(self):
        field = models.EmailField()
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.EmailField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {"max_length": 254})
        field = models.EmailField(max_length=255)
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.EmailField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {"max_length": 255}) 
Example #6
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_email_field(self):
        field = models.EmailField()
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.EmailField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {"max_length": 254})
        field = models.EmailField(max_length=255)
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.EmailField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {"max_length": 255}) 
Example #7
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_email_field(self):
        field = models.EmailField()
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.EmailField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {"max_length": 254})
        field = models.EmailField(max_length=255)
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.EmailField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {"max_length": 255}) 
Example #8
Source File: db_compat.py    From tri.table with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def setup_db_compat_django():
    from tri_table import register_column_factory
    try:
        # noinspection PyUnresolvedReferences
        from django.db.models import IntegerField, FloatField, TextField, BooleanField, AutoField, CharField, DateField, DateTimeField, DecimalField, EmailField, TimeField, ForeignKey, ManyToOneRel, ManyToManyField, ManyToManyRel, UUIDField
    except ImportError:
        pass
    else:
        # The order here is significant because of inheritance structure. More specific must be below less specific.

        register_column_factory(CharField, Shortcut(call_target__attribute='text'))
        register_column_factory(UUIDField, Shortcut(call_target__attribute='text'))
        register_column_factory(TimeField, Shortcut(call_target__attribute='time'))
        register_column_factory(EmailField, Shortcut(call_target__attribute='email'))
        register_column_factory(DecimalField, Shortcut(call_target__attribute='decimal'))
        register_column_factory(DateField, Shortcut(call_target__attribute='date'))
        register_column_factory(DateTimeField, Shortcut(call_target__attribute='datetime'))
        register_column_factory(BooleanField, Shortcut(call_target__attribute='boolean'))
        register_column_factory(TextField, Shortcut(call_target__attribute='text'))
        register_column_factory(FloatField, Shortcut(call_target__attribute='float'))
        register_column_factory(IntegerField, Shortcut(call_target__attribute='integer'))
        register_column_factory(AutoField, Shortcut(call_target__attribute='integer', show=False))
        register_column_factory(ManyToOneRel, None)
        register_column_factory(ManyToManyField, Shortcut(call_target__attribute='many_to_many'))
        register_column_factory(ManyToManyRel, None)

        register_column_factory(ForeignKey, Shortcut(call_target__attribute='foreign_key')) 
Example #9
Source File: models.py    From devops with MIT License 4 votes vote down vote up
def save(self, **kwargs):
        super(SignupCodeResult, self).save(**kwargs)
        self.signup_code.calculate_use_count()


# class EmailAddress(models.Model):
#
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     email = models.EmailField(unique=settings.ACCOUNT_EMAIL_UNIQUE)
#     verified = models.BooleanField(_("verified"), default=False)
#     primary = models.BooleanField(_("primary"), default=False)
#
#     objects = EmailAddressManager()
#
#     class Meta:
#         verbose_name = _("email address")
#         verbose_name_plural = _("email addresses")
#         if not settings.ACCOUNT_EMAIL_UNIQUE:
#             unique_together = [("user", "email")]
#
#     def __unicode__(self):
#         return "{0} ({1})".format(self.email, self.user)
#
#     def set_as_primary(self, conditional=False):
#         old_primary = EmailAddress.objects.get_primary(self.user)
#         if old_primary:
#             if conditional:
#                 return False
#             old_primary.primary = False
#             old_primary.save()
#         self.primary = True
#         self.save()
#         self.user.email = self.email
#         self.user.save()
#         return True
#
#     def send_confirmation(self, **kwargs):
#         confirmation = EmailConfirmation.create(self)
#         confirmation.send(**kwargs)
#         return confirmation
#
#     def change(self, new_email, confirm=True):
#         """
#         Given a new email address, change self and re-confirm.
#         """
#         with transaction.atomic():
#             self.user.email = new_email
#             self.user.save()
#             self.email = new_email
#             self.verified = False
#             self.save()
#             if confirm:
#                 self.send_confirmation() 
Example #10
Source File: models.py    From devops with MIT License 4 votes vote down vote up
def send(self, **kwargs):
        current_site = kwargs["site"] if "site" in kwargs else Site.objects.get_current()
        protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http")
        activate_url = "{0}://{1}{2}".format(
            protocol,
            current_site.domain,
            reverse(settings.ACCOUNT_EMAIL_CONFIRMATION_URL, args=[self.key])
        )
        ctx = {
            "account": self.account,
            "user": self.account.user,
            "activate_url": activate_url,
            "current_site": current_site,
            "key": self.key,
        }
        hookset.send_confirmation_email([self.account.user.email], ctx)
        self.sent = timezone.now()
        self.save()
        signals.email_confirmation_sent.send(sender=self.__class__, confirmation=self)

# class AccountDeletion(models.Model):
#
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.SET_NULL)
#     email = models.EmailField()
#     date_requested = models.DateTimeField(_("date requested"), default=timezone.now)
#     date_expunged = models.DateTimeField(_("date expunged"), null=True, blank=True)
#
#     class Meta:
#         verbose_name = _("account deletion")
#         verbose_name_plural = _("account deletions")
#
#     @classmethod
#     def expunge(cls, hours_ago=None):
#         if hours_ago is None:
#             hours_ago = settings.ACCOUNT_DELETION_EXPUNGE_HOURS
#         before = timezone.now() - datetime.timedelta(hours=hours_ago)
#         count = 0
#         for account_deletion in cls.objects.filter(date_requested__lt=before, user__isnull=False):
#             settings.ACCOUNT_DELETION_EXPUNGE_CALLBACK(account_deletion)
#             account_deletion.date_expunged = timezone.now()
#             account_deletion.save()
#             count += 1
#         return count
#
#     @classmethod
#     def mark(cls, user):
#         account_deletion, created = cls.objects.get_or_create(user=user)
#         account_deletion.email = user.email
#         account_deletion.save()
#         settings.ACCOUNT_DELETION_MARK_CALLBACK(account_deletion)
#         return account_deletion