Example #1
0
class Host(ForwardZoneMember):
    name = DnsNameField(unique=True)
    contact = pgfields.CIEmailField(blank=True)
    ttl = models.IntegerField(blank=True, null=True, validators=[validate_ttl])
    hinfo = models.ForeignKey(HinfoPreset,
                              models.DO_NOTHING,
                              db_column='hinfo',
                              blank=True,
                              null=True)
    loc = models.TextField(blank=True, validators=[validate_loc])
    comment = models.TextField(blank=True)

    class Meta:
        db_table = 'host'

    def __str__(self):
        return str(self.name)

    def loc_string(self, zone):
        """String representation for zonefile export."""
        data = {
            'name': idna_encode(qualify(self.name, zone)),
            'record_type': 'LOC',
            'record_data': self.loc
        }
        return '{name:30} IN {record_type:6} {record_data}\n'.format_map(data)
Example #2
0
    class AllFields(models.Model):
        bigintegerfield = models.BigIntegerField()
        binaryfield = models.BinaryField()
        booleanfield = models.BooleanField()
        charfield = models.CharField()
        commaseparatedintegerfield = models.CommaSeparatedIntegerField()
        datefield = models.DateField()
        datetimefield = models.DateTimeField()
        decimalfield = models.DecimalField()
        durationfield = models.DurationField()
        emailfield = models.EmailField()
        filefield = models.FileField()
        filepathfield = models.FilePathField()
        floatfield = models.FloatField()
        genericipaddressfield = models.GenericIPAddressField()
        ipaddressfield = models.IPAddressField()
        imagefield = models.ImageField()
        integerfield = models.IntegerField()
        nullbooleanfield = models.NullBooleanField()
        positiveintegerfield = models.PositiveIntegerField()
        positivesmallintegerfield = models.PositiveSmallIntegerField()
        slugfield = models.SlugField()
        smallintegerfield = models.SmallIntegerField()
        textfield = models.TextField()
        timefield = models.TimeField()
        urlfield = models.URLField()
        uuidfield = models.UUIDField()
        arrayfield = ps_fields.ArrayField(models.CharField())
        cicharfield = ps_fields.CICharField()
        ciemailfield = ps_fields.CIEmailField()
        citextfield = ps_fields.CITextField()
        hstorefield = ps_fields.HStoreField()

        class Meta:
            app_label = "tests"
Example #3
0
class Host(ForwardZoneMember):
    name = DnsNameField(unique=True)
    contact = pgfields.CIEmailField(blank=True)
    ttl = models.IntegerField(blank=True, null=True, validators=[validate_ttl])
    comment = models.TextField(blank=True)

    class Meta:
        db_table = 'host'

    def __str__(self):
        return str(self.name)
Example #4
0
class Lead(models.Model):
    """
    This contains Lead(Participant) related information
    """
    name = models.CharField(max_length=100)
    phone_number = models.CharField(max_length=20)
    target = models.ForeignKey(Target, on_delete=models.PROTECT)
    email = pg_fields.CIEmailField(max_length=100)
    history = pg_fields.ArrayField(
        pg_fields.CITextField()
    )
    lead_status = models.CharField(max_length=3, choices=LEAD_STATUS_CHOICES, default='INTR')
    target_type = models.CharField(max_length=4, choices=TARGET_TYPES, default='HP')
    created_at = models.DateTimeField(default=timezone.now)
    updated_at = models.DateTimeField(default=timezone.now)
Example #5
0
class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField(max_length=100, null=True, blank=True)
    last_name = models.CharField(max_length=100, null=True, blank=True)
    phone = models.CharField(max_length=20,
                             validators=[validate_mobile],
                             null=True,
                             unique=True)
    email = pg_fields.CIEmailField(blank=True, null=True)
    is_staff = models.BooleanField(
        _("staff status"),
        default=False,
        help_text=_("People who are the part of organisation."),
    )
    is_active = models.BooleanField(
        _("active"),
        default=True,
        help_text=_(
            "Designates whether this user should be treated as active."),
    )
    is_admin = models.BooleanField(
        _("admin"),
        default=False,
        help_text=_("Whether the user is admin of site or not."),
    )
    created_on = models.DateTimeField(auto_now_add=True)
    updated_on = models.DateTimeField(auto_now=True)
    USERNAME_FIELD = "phone"

    objects = UserManager()

    @property
    def full_name(self):
        return self.get_full_name()

    def get_full_name(self):
        full_name = "%s %s" % (self.first_name, self.last_name)
        return full_name.strip() or self.phone

    def __str__(self):
        return self.get_full_name()
Example #6
0
class BaseZone(BaseModel, ZoneHelpers):
    updated = models.BooleanField(default=True)
    primary_ns = DnsNameField()
    nameservers = models.ManyToManyField(NameServer, db_column='ns')
    email = pgfields.CIEmailField()
    serialno = models.BigIntegerField(default=create_serialno,
                                      validators=[validate_32bit_uint])
    serialno_updated_at = models.DateTimeField(default=timezone.now)
    refresh = models.IntegerField(default=10800)
    retry = models.IntegerField(default=3600)
    expire = models.IntegerField(default=1814400)
    soa_ttl = models.IntegerField(default=43200, validators=[validate_ttl])
    default_ttl = models.IntegerField(default=43200, validators=[validate_ttl])

    class Meta:
        abstract = True

    def __str__(self):
        return str(self.name)

    @property
    def zf_string(self):
        """String representation for zonefile export."""
        data = {
            'origin':
            idna_encode(qualify(self.name, self.name, shortform=False)),
            'default_ttl':
            self.default_ttl,
            'name':
            '@',
            'record_type':
            'SOA',
            'mname':
            idna_encode(qualify(self.primary_ns, self.name, shortform=False)),
            'rname':
            idna_encode(encode_mail(self.email)),
            'serial':
            self.serialno,
            'refresh':
            self.refresh,
            'retry':
            self.retry,
            'expire':
            self.expire,
            'soa_ttl':
            self.soa_ttl,
            'zupdated_at':
            timezone.localtime(self.updated_at),
            'supdated_at':
            timezone.localtime(self.serialno_updated_at)
        }
        zf = """$ORIGIN {origin}
$TTL {default_ttl}
{name:30} IN {record_type:6} {mname} {rname} (
                                         {serial}    ; Serialnumber
                                         {refresh}   ; Refresh
                                         {retry}     ; Retry
                                         {expire}    ; Expire
                                         {soa_ttl} ) ; Negative Cache
; zone.updated_at: {zupdated_at}
; zone.serialno_updated_at: {supdated_at}
""".format_map(data)
        return zf

    def update_serialno(self, force=False):
        """Update serialno if zone has been updated since the serial number
        was updated.
        """
        # Need the have a timedelta as serialno_updated_at to not exhaust
        # the 1000 possible daily serial numbers.
        min_delta = timedelta(minutes=1)
        if force or self.updated and \
           timezone.now() > self.serialno_updated_at + min_delta:
            new_serial = create_serialno(self.serialno)
            # If hitting the daily limit, make sure not to change the
            # other variables.
            if new_serial == self.serialno:
                return
            self.serialno = new_serial
            self.serialno_updated_at = timezone.now()
            self.updated = False
            try:
                with transaction.atomic():
                    self.save()
            except DatabaseError:
                pass