Exemplo n.º 1
0
class Reconsent(models.Model):
    email = CIEmailField(max_length=255, unique=True)
    reconsented_at = models.DateTimeField(auto_now_add=True)
    ip_address = models.GenericIPAddressField()
    
    def __str__(self):
        return self.email
Exemplo n.º 2
0
class User(models.Model):

    def get_default_role():
        return Role.objects.get(name="user").id
    def get_default_user_type():
        return UserType.objects.get(name="default").id
    def get_default_user_status():
        return UserStatus.objects.get(name="pending").id 
    DEFAULT_ROLE = 4    
    DEFAULT_USER_STATUS = 4
    DEFAULT_USER_TYPE = 6           
    
    id = models.AutoField(primary_key=True)
    role = models.ForeignKey(Role,default=get_default_role,on_delete=models.CASCADE)
    user_status = models.ForeignKey(UserStatus,default=get_default_user_status,on_delete=models.CASCADE)
    user_type = models.ForeignKey(UserType,default=get_default_user_type,on_delete=models.CASCADE)
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    email_id = CIEmailField(max_length=100,unique=True) # CREATE EXTENSION IF NOT EXISTS citext; 
    password = models.CharField(max_length=100)
    is_active = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    deleted_at = models.DateTimeField(null=True,blank=True)
    deleted_why = models.TextField(null=True, blank=True)

    class Meta:
        db_table = 'user'
Exemplo n.º 3
0
class NationBuilderPerson(models.Model):
    member = models.OneToOneField(Member, related_name = 'nation_builder_person',
                                  blank = True, null = True, default = None, on_delete=models.CASCADE)
    email = CIEmailField(max_length=255, unique=True) # duplicate of member.email so that supporters can be promoted to members when joining
    unique_token = models.CharField(max_length = unique_token_length, default = unused_unique_token)
    nation_builder_id = models.IntegerField(blank=True, null=True, default=None)

    def __str__(self):
        return '%s - %s (%s, %s)' % ('Member' if self.member else 'Supporter', self.email, self.unique_token, str(self.nation_builder_id) if self.nation_builder_id else '')
Exemplo n.º 4
0
class EmailSettings(SingletonModel):
    test_email_address = CIEmailField(default='')
    send_count = models.PositiveIntegerField(default=1000)
    is_active = models.BooleanField(default=False)
    activation_email = models.ForeignKey(Email,
                                         related_name='+',
                                         blank=True,
                                         null=True,
                                         default=None,
                                         on_delete=SET_NULL)
Exemplo n.º 5
0
class Member(AbstractBaseUser, PermissionsMixin):
    email = CIEmailField(verbose_name='email address', max_length=255, unique=True)
    name = models.CharField(max_length=255)
    is_active = models.BooleanField(default=False)
    activation_key = models.CharField(max_length=activation_key_length, default=activation_key_default)
    last_emailed = models.DateField(blank=True, null=True, default=None)
    is_ncg = models.BooleanField(default=False, verbose_name = 'NCG')
    is_members_council = models.BooleanField(default=False, verbose_name = "Members' council (can act on behalf of the member's council)")
    new_login_email = CIEmailField(max_length=255, blank=True, null=True, default=None)
    login_email_verification_key = models.CharField(max_length=activation_key_length, blank=True, null=True, default=None)
    is_anonymised = models.BooleanField(default=False, verbose_name = "Personal data has been anonymised")

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name']
    
    objects = MemberManager()

    # identify the member publicly by their name
    def get_full_name(self):
        return self.name
    def get_short_name(self):
        return self.name

    def __str__(self):
        return '%s (%s)' % (self.name, self.email)
    anonymise_string_length = 20
    def anonymise_user(self):
        self.name = get_random_string(self.anonymise_string_length)
        self.email = get_random_string(self.anonymise_string_length) +'@void.com'
        self.is_active = False
        self.is_anonymised = True
        self.save()

    @property
    def is_staff(self):
        return self.is_superuser
Exemplo n.º 6
0
class Person(models.Model):
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    #  Jards Macalé is an amazing brazilian musician! =]
    enjoy_jards_macale = models.BooleanField(default=True)
    like_metal_music = models.BooleanField(default=False)
    name = models.CharField(max_length=30)
    nickname = models.SlugField(max_length=36)
    age = models.IntegerField()
    bio = models.TextField()
    birthday = models.DateField()
    birth_time = models.TimeField()
    appointment = models.DateTimeField()
    blog = models.URLField()
    occupation = models.CharField(max_length=10, choices=OCCUPATION_CHOICES)
    uuid = models.UUIDField(primary_key=False)
    name_hash = models.BinaryField(max_length=16)
    days_since_last_login = models.BigIntegerField()
    duration_of_sleep = models.DurationField()
    email = models.EmailField()
    id_document = models.CharField(unique=True, max_length=10)

    try:
        from django.contrib.postgres.fields import ArrayField, HStoreField, JSONField
        from django.contrib.postgres.fields.citext import (
            CICharField,
            CIEmailField,
            CITextField,
        )

        acquaintances = ArrayField(models.IntegerField())
        data = JSONField()
        hstore_data = HStoreField()
        ci_char = CICharField(max_length=30)
        ci_email = CIEmailField()
        ci_text = CITextField()
    except ImportError:
        # Skip PostgreSQL-related fields
        pass

    if BAKER_GIS:
        geom = models.GeometryField()
        point = models.PointField()
        line_string = models.LineStringField()
        polygon = models.PolygonField()
        multi_point = models.MultiPointField()
        multi_line_string = models.MultiLineStringField()
        multi_polygon = models.MultiPolygonField()
        geom_collection = models.GeometryCollectionField()
Exemplo n.º 7
0
class User(AbstractBaseUser):
  EMAIL_FIELD = 'email'
  USERNAME_FIELD = 'username'

  id = B64IDField(primary_key=True, editable=False)
  email = CIEmailField(max_length=255, unique=True)
  username = CITextField(max_length=255, unique=True)

  is_active = True

  objects = UserManager()

  @property
  def is_admin(self):
    # TODO(mgraczyk): Fix
    return self.email.lower() == '*****@*****.**'
Exemplo n.º 8
0
class Intention(models.Model):
    vote = models.ForeignKey(Vote,
                             related_name='intentions',
                             on_delete=CASCADE)
    choice = models.ForeignKey(Choice,
                               related_name='intentions',
                               on_delete=CASCADE)
    email = CIEmailField(verbose_name='email address', max_length=255)
    nation_builder_id = models.IntegerField(blank=True,
                                            null=True,
                                            default=None)
    recorded_at = models.DateTimeField(auto_now_add=True)
    tags_written_to_nation_builder = models.BooleanField(default=False)
    email_unknown_in_nation_builder = models.NullBooleanField(default=None)
    processed_at = models.DateTimeField(blank=True, null=True, default=None)

    def __str__(self):
        return self.email
Exemplo n.º 9
0
class Person(models.Model):
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    happy = models.BooleanField(default=True)
    unhappy = models.BooleanField(default=False)
    bipolar = models.BooleanField(default=False)
    name = models.CharField(max_length=30)
    nickname = models.SlugField(max_length=36)
    age = models.IntegerField()
    bio = models.TextField()
    birthday = models.DateField()
    birth_time = models.TimeField()
    appointment = models.DateTimeField()
    blog = models.URLField()
    occupation = models.CharField(max_length=10, choices=OCCUPATION_CHOICES)
    uuid = models.UUIDField(primary_key=False)
    name_hash = models.BinaryField(max_length=16)
    wanted_games_qtd = models.BigIntegerField()
    duration_of_sleep = models.DurationField()
    email = models.EmailField()

    try:
        from django.contrib.postgres.fields import ArrayField, HStoreField, JSONField
        from django.contrib.postgres.fields.citext import CICharField, CIEmailField, CITextField
        acquaintances = ArrayField(models.IntegerField())
        data = JSONField()
        hstore_data = HStoreField()
        ci_char = CICharField(max_length=30)
        ci_email = CIEmailField()
        ci_text = CITextField()
    except ImportError:
        # Skip PostgreSQL-related fields
        pass

    if MOMMY_GIS:
        geom = models.GeometryField()
        point = models.PointField()
        line_string = models.LineStringField()
        polygon = models.PolygonField()
        multi_point = models.MultiPointField()
        multi_line_string = models.MultiLineStringField()
        multi_polygon = models.MultiPolygonField()
        geom_collection = models.GeometryCollectionField()
Exemplo n.º 10
0
class Member(AbstractBaseUser, PermissionsMixin):
    momentum_group = models.ForeignKey(MomentumGroup,
                                       related_name='members',
                                       blank=True,
                                       null=True,
                                       on_delete=SET_NULL)
    email = CIEmailField(verbose_name='email address',
                         max_length=255,
                         unique=True)
    name = models.CharField(max_length=255)
    is_active = models.BooleanField(default=False)
    activation_key = models.CharField(max_length=activation_key_length,
                                      default=activation_key_default)
    last_emailed = models.DateField(blank=True, null=True, default=None)
    is_ncg = models.BooleanField(default=False, verbose_name='NCG')
    is_members_council = models.BooleanField(
        default=False,
        verbose_name=
        "Members' council (can act on behalf of the member's council)")

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name']

    objects = MemberManager()

    # identify the member publicly by their name
    def get_full_name(self):
        return self.name

    def get_short_name(self):
        return self.name

    # debug
    def __str__(self):
        return self.email

    @property
    def is_staff(self):
        return self.is_superuser
Exemplo n.º 11
0
class EmailTarget(models.Model):
    email = CIEmailField(max_length=255, unique=True)
    sent = models.NullBooleanField(default=None)
Exemplo n.º 12
0
class User(SoftDeleteMixin, TimestampMixin, AbstractBaseUser):
    ''' Custom user model. '''
    email = CIEmailField(
        max_length=255,
        unique=True,
    )
    following = models.ManyToManyField(
        'self',
        related_name='followers',
        symmetrical=False,
    )
    last_notification_read_time = models.DateTimeField(default=now)
    name = models.CharField(max_length=150)
    slug = models.SlugField(
        max_length=32,
        unique=True,
    )
    username = CICharField(
        max_length=32,
        unique=True,
    )

    objects = UserManager()

    USERNAME_FIELD = 'username'
    EMAIL_FIELD = 'email'

    def display_name(self) -> str:
        ''' Get user's display name.

        When this project was started, `name` was not a required field. This
        method would return the user's username if `name` was not set. Instead
        of changing this throughout the frontend I left it as is.
        '''
        return self.name

    def follow(self, user: object) -> None:
        ''' Follow `user`. '''
        if user != self:
            self.following.add(user)

    def get_followers(self):
        ''' Get users that are following user. '''
        return self\
            .followers\
            .filter(is_active=True)\
            .select_related('profile')\
            .prefetch_related('followers')\
            .prefetch_related('following')

    def get_following(self):
        ''' Get users that user is following. '''
        return self\
            .following\
            .filter(is_active=True)\
            .select_related('profile')\
            .prefetch_related('followers')\
            .prefetch_related('following')

    def save(self, *args, **kwargs):
        ''' Modify user input.

            - Make sure the user's email is all lowercase.
            - Create a slug for the user.
        '''
        self.email = self.email.lower()
        self.slug = slugify(self.username, allow_unicode=True)
        super().save(*args, **kwargs)

    def unfollow(self, user: object) -> None:
        ''' Unfollow `user`. '''
        self.following.remove(user)
Exemplo n.º 13
0
class Person(models.Model):
    gender = models.CharField(max_length=1, choices=GENDER_CH)
    happy = models.BooleanField(default=True)
    unhappy = models.BooleanField(default=False)
    bipolar = models.BooleanField(default=False)
    name = models.CharField(max_length=30)
    nickname = models.SlugField(max_length=36)
    age = models.IntegerField()
    bio = models.TextField()
    birthday = models.DateField()
    birth_time = models.TimeField()
    appointment = models.DateTimeField()
    blog = models.URLField()
    occupation = models.CharField(max_length=10, choices=OCCUPATION_CHOCIES)
    try:
        uuid = models.UUIDField(primary_key=False)
    except AttributeError:
        # New at Django 1.9
        pass
    try:
        name_hash = models.BinaryField(max_length=16)
    except AttributeError:
        # We can't test the binary field if it is not supported
        # (django < 1,6)
        pass
    try:
        from django.contrib.postgres.fields import ArrayField
        acquaintances = ArrayField(models.IntegerField())
    except ImportError:
        # New at Django 1.9
        pass

    try:
        from django.contrib.postgres.fields import JSONField
        data = JSONField()
    except ImportError:
        # New at Django 1.9
        pass

    try:
        from django.contrib.postgres.fields import HStoreField
        hstore_data = HStoreField()
    except ImportError:
        # New at Django 1.8
        pass

    # backward compatibility with Django 1.1
    try:
        wanted_games_qtd = models.BigIntegerField()
    except AttributeError:
        wanted_games_qtd = models.IntegerField()

    try:
        from django.contrib.postgres.fields.citext import CICharField, CIEmailField, CITextField
        ci_char = CICharField(max_length=30)
        ci_email = CIEmailField()
        ci_text = CITextField()
    except ImportError:
        # New at Django 1.11
        pass

    try:
        duration_of_sleep = models.DurationField()
    except AttributeError:
        pass

    if MOMMY_GIS:
        geom = models.GeometryField()
        point = models.PointField()
        line_string = models.LineStringField()
        polygon = models.PolygonField()
        multi_point = models.MultiPointField()
        multi_line_string = models.MultiLineStringField()
        multi_polygon = models.MultiPolygonField()
        geom_collection = models.GeometryCollectionField()