예제 #1
0
class TZWithGoodStringDefault(models.Model):
    """Test should validate that"""
    timezone = TimeZoneField(
        default='US/Eastern',
        max_length=64,
        null=True,
    )
예제 #2
0
class TZWithBadStringDefault(models.Model):
    """Test should check that a ValidationError is raised when..."""
    timezone = TimeZoneField(
        default='Bad/Worse',
        max_length=64,
        null=True,
    )
예제 #3
0
class CodeBoxSchedule(LabelDescriptionAbstractModel, CacheableAbstractModel):
    PERMISSION_CONFIG = {
        'admin': {
            'write': FULL_PERMISSIONS,
            'read': {API_PERMISSIONS.READ},
        }
    }

    codebox = models.ForeignKey(CodeBox,
                                related_name='schedules',
                                on_delete=models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True)

    interval_sec = models.IntegerField(null=True, default=None, blank=True)
    crontab = models.CharField(max_length=40, blank=True, null=True)
    scheduled_next = models.DateTimeField(null=True, blank=True, db_index=True)
    timezone = TimeZoneField(default='UTC')
    socket = models.ForeignKey('sockets.Socket',
                               blank=True,
                               null=True,
                               default=None,
                               on_delete=models.CASCADE)
    event_handler = models.TextField(default=None, null=True)

    objects = SchedulerManager()

    class Meta:
        ordering = ('id', )
        verbose_name = 'Schedule'

    def __str__(self):
        return 'Schedule[id=%s, label=%s]' % (
            self.pk,
            self.label,
        )

    def clean(self):
        if self.crontab and self.interval_sec:
            raise ValidationError(
                "You can't specify both crontab and interval_sec.")
        elif (not self.crontab) and (not self.interval_sec):
            raise ValidationError(
                "Either crontab or interval_sec has to be specified.")

    def seconds_to_next(self, now=None):
        if self.interval_sec:
            return self.interval_sec
        elif self.crontab:
            return compute_remaining_seconds_from_crontab(
                self.crontab, self.timezone, now)

    def schedule_now(self):
        self.scheduled_next = timezone.now()
        self.save(update_fields=('scheduled_next', ))

    def schedule_next(self):
        now = timezone.now()
        self.scheduled_next = now + timedelta(0, self.seconds_to_next(now))
        self.save(update_fields=('scheduled_next', ))
예제 #4
0
파일: models.py 프로젝트: siddusmj/acnt
class Names(models.Model):
    id = models.CharField(max_length=225, primary_key=True)
    real_name = models.CharField(max_length=250)
    timezone = TimeZoneField(choices=PRETTY_ALL_TIMEZONES_CHOICES)
    activity_periods = models.ManyToManyField('Periods')

    def __str__(self):
        return f'{self.id} {self.real_name} {self.timezone} '
예제 #5
0
class LocationTimeZoneChoices(models.Model):
    timezone = TimeZoneField(
        verbose_name=_('timezone'),
        max_length=64,
        null=True,
        blank=True,
        choices=PRETTY_ALL_TIMEZONES_CHOICES,
    )
예제 #6
0
class TZWithLowMaxLength(models.Model):
    """Test should check to make sure that the `max_length` is set to the
    maximum length of the longest value provided by pytz.all_timezones.

    """
    timezone = TimeZoneField(
        max_length=15,
        null=True,
    )
예제 #7
0
class Profile(models.Model):
    """Hold user profile options not in default user model."""

    REFRESH_FREQUENCY = Choices(('daily', _('Daily')), ('twice_a_day', _('Twice a Day')), ('hourly', _('Hourly')))

    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile", unique=True)
    custom_timezone = TimeZoneField(choices=TIMEZONE_CHOICES, default='America/New_York')
    refresh_frequency = models.CharField(choices=REFRESH_FREQUENCY, default=REFRESH_FREQUENCY.daily, max_length=20)
    tags = TaggableManager(blank=True)

    def __str__(self):
        """Representation of a profile."""
        return u"<Profile ID:{}; User ID:{}; Timezone:{}>".format(self.pk, self.user_id, self.custom_timezone)
예제 #8
0
class TZWithGoodTZInfoDefault(models.Model):
    timezone = TimeZoneField(
        default=pytz.timezone('US/Pacific'),
        max_length=64,
        null=True,
    )
예제 #9
0
class LocationTimeZone(models.Model):
    timezone = TimeZoneField(verbose_name=_('timezone'),
                             max_length=64,
                             null=True,
                             blank=True)
예제 #10
0
class ModelWithBadPopulateFrom(models.Model):
    timezone = TimeZoneField(default='US/Eastern')
    timestamp = LinkedTZDateTimeField(
        default=settings.TEST_DATETIME,
        populate_from='invalid_field_reference',
    )
예제 #11
0
class ModelWithLocalTimeZone(models.Model):
    timezone = TimeZoneField(default='US/Eastern')
    timestamp = LinkedTZDateTimeField(default=settings.TEST_DATETIME,
                                      populate_from='timezone')
예제 #12
0
class KITUser(models.Model):

    user = models.OneToOneField(User)
    dob = models.DateField(blank=False, null=True)
    timezone = TimeZoneField(choices=PRETTY_COMMON_TIMEZONES_CHOICES,
                             default="Africa/Lagos")

    parent = models.ForeignKey('self',
                               on_delete=models.CASCADE,
                               null=True,
                               blank=True,
                               limit_choices_to={'is_admin': True})
    phone_number = PhoneNumberField(blank=True, null=True)

    is_admin = models.BooleanField(default=False)
    address = models.OneToOneField(OrganizationContact, null=True, blank=True)
    ip_address = models.GenericIPAddressField(null=True, editable=False)

    email_validated = models.BooleanField(default=False)
    email_validated_date = models.DateTimeField(null=True)

    phone_validated = models.BooleanField(default=False)
    phone_validated_date = models.DateTimeField(null=True)

    objects = models.Manager()

    def __str__(self):
        return "{}".format(self.user.get_full_name())

    def get_absolute_url(self):
        return reverse('core:kituser-detail', args=[self.pk])

    #@cached_as(timeout=600)    #this cached all the way into kitsystem. Need to fix before recaching
    def get_parent(self):
        if self.is_admin:
            return self
        return self.parent

    def get_contacts(self):

        #if self.kitbilling.is_full_admin == False:
        #    return Contact.objects.filter(kit_user=self.pk)
        if self.is_admin:
            #return self.kituser_set.contact_set
            return Contact.objects.filter(kit_user__parent=self.pk)
        else:
            my_groups = self.groups_belongto.all()
            users_who_are_in_groups_i_belong_to = KITUser.objects.filter(
                groups_belongto__in=my_groups)
            contacts1 = Contact.objects.filter(
                kit_user__in=users_who_are_in_groups_i_belong_to)
            #Contact.objects.filter(kit_user__cousergroup)

            if self.parent.kitsystem.company_wide_contacts == True:

                contacts2 = Contact.objects.filter(
                    kit_user__parent=self.parent).distinct()
            else:
                contacts2 = Contact.objects.filter(
                    kit_user__groups_belongto__kit_admin=self.parent).distinct(
                    )
            #return {'contact1': contacts1, 'contact2':contacts2} #self.contact_set.all(cousergroup__kit_user=self.pk)
            return contacts2

    def get_contact_groups(self):
        if self.is_admin:
            return ContactGroup.objects.filter(kit_user=self.pk)
        else:
            return ContactGroup.objects.filter(kit_user=self.pk)

    def get_private_events(self):

        #if self.kitbilling.is_full_admin == False:
        #    return Event.objects.filter(contact__kit_user=self.pk)
        if self.is_admin:
            '''
            Return the private events of all contacts created by users
            under the groups I admin over
            '''
            return Event.objects.filter(contact__kit_user__parent=self.pk)
        else:
            #get events of groups I belong to
            #if you are allowed to see all contacts in the organisation,
            #then you can view the anniversaries of all of them
            if self.parent.kitsystem.company_wide_contacts == True:
                return Event.objects.filter(
                    contact__kit_user__parent=self.parent).distinct()
            else:
                return Event.objects.filter(
                    contact__kit_user__groups_belongto__kit_admin=self.parent
                ).distinct()

    def get_public_events(self):

        #if self.kitbilling.is_full_admin == False:
        #    return PublicEvent.objects.filter(kit_user=self.pk).order_by("date")
        if self.is_admin:
            return PublicEvent.objects.filter(
                kit_user__parent=self.pk).order_by("date")
        else:
            #get events of groups I belong to. May chance this later
            if self.parent.kitsystem.company_wide_contacts == True:
                return PublicEvent.objects.filter(
                    kit_user__parent=self.parent).order_by("date")
            else:
                return PublicEvent.objects.filter(
                    kit_user__groups_belongto__kit_admin=self.parent).order_by(
                        "date").distinct()

    def get_templates(self):

        if self.is_admin:
            return MessageTemplate.objects.filter(kit_admin=self)
        else:
            if self.parent.kitsystem.company_wide_contacts == True:
                # get all smtp settings created by the admin
                return MessageTemplate.objects.filter(kit_admin=self.parent)
            else:
                # get smtp settings of groups I belong to.
                gib2 = self.groups_belongto.all()
                return MessageTemplate.objects.filter(cou_group__in=gib2)

    def get_processed_messages(self):
        processedmessages = apps.get_model('messaging', 'ProcessedMessages')

        #if self.kitbilling.is_full_admin == False:
        #    return processedmessages.objects.filter(created_by = self.pk)
        if self.is_admin:
            return processedmessages.objects.filter(
                created_by__parent=self.pk).order_by('-processed_at')
        else:
            return processedmessages.objects.filter(
                created_by=self.pk).order_by('-processed_at')

    def get_queued_messages(self):
        queuedmessages = apps.get_model('messaging', 'QueuedMessages')

        #if self.kitbilling.is_full_admin == False:
        #    return queuedmessages.objects.filter(created_by = self.pk).order_by('-queued_at')
        if self.is_admin:
            return queuedmessages.objects.filter(
                created_by__parent=self.pk).order_by('-queued_at')
        else:
            return queuedmessages.objects.filter(
                created_by=self.pk).order_by('-queued_at')

    def get_running_messages(self):
        RunningMessage = apps.get_model('messaging', 'RunningMessage')

        #if self.kitbilling.is_full_admin == False:
        #    return RunningMessage.objects.filter(created_by = self.pk).order_by('-started_at')
        if self.is_admin:
            return RunningMessage.objects.filter(
                created_by__parent=self.pk).order_by('-started_at')
        else:
            return RunningMessage.objects.filter(
                created_by=self.pk).order_by('-started_at')

    def get_custom_data(self):
        if self.is_admin:
            return CustomData.objects.filter(created_by__parent=self.pk)
        else:
            return CustomData.objects.filter(created_by=self.pk)

    def get_failed_email_messages(self):
        failedemailmessage = apps.get_model('messaging', 'FailedEmailMessage')
        if self.is_admin:
            return failedemailmessage.objects.filter(owned_by__parent=self.pk)
        else:
            return failedemailmessage.objects.filter(
                owned_by=self.pk).order_by('-created')

    def get_failed_sms_messages(self):
        failedsmsmessage = apps.get_model('messaging', 'FailedSMSMessage')
        if self.is_admin:
            return failedsmsmessage.objects.filter(owned_by__parent=self.pk)
        else:
            return failedsmsmessage.objects.filter(
                owned_by=self.pk).order_by('-created')

    def get_default_sms_sender(self):
        kitsystem = apps.get_model('gomez', 'KITSystem')
        if self.is_admin:
            return kitsystem.objects.get(kit_admin=self).default_sms_sender
        else:
            return kitsystem.objects.get(
                kit_admin=self.parent).default_sms_sender

    #####Admin Things#######

    def get_kituser(self):
        if self.is_admin:
            return KITUser.objects.get(parent=self.pk)

    def get_kitusers(self):
        '''
        Admin, get child users
        '''
        if self.is_admin:
            return KITUser.objects.filter(parent=self.pk)
        #elif not self.kitbilling.is_full_admin:
        #    raise PermissionError("You don't have the necessary Permissions")

    def get_user_groups(self):
        #if self.kitbilling.is_full_admin == False:
        #    raise PermissionError("You don't have the necessary Permissions")
        if self.is_admin:
            return CoUserGroup.objects.filter(kit_admin=self.pk)

    def get_smtp_items(self):
        '''
            Only KIT_ADMINS can configure SMTP
        '''
        try:
            if self.is_admin:
                return SMTPSetting.objects.filter(kit_admin=self.pk)
            else:
                if self.parent.kitsystem.company_wide_contacts == True:
                    # get all smtp settings created by the admin
                    return SMTPSetting.objects.filter(kit_admin=self.parent)
                else:
                    # get smtp settings of groups I belong to.
                    gib2 = self.groups_belongto.all()
                    return SMTPSetting.objects.filter(cou_group__in=gib2)
        except InvalidToken:
            print(
                "Seems you have changed SECRET_KEY...all encrypted tokens have been invalidated"
            )
예제 #13
0
class Trip(models.Model):
    title = models.CharField(max_length=45, verbose_name='nombre del viaje')

    active = models.BooleanField(default=True)

    init_date = models.DateTimeField(null=True,
                                     blank=True,
                                     verbose_name="fecha inicial")

    end_date = models.DateTimeField(null=True,
                                    blank=True,
                                    verbose_name="fecha Final")

    origin_city = models.ForeignKey(City,
                                    null=True,
                                    blank=True,
                                    verbose_name="Ciudad")

    destination_city = models.ForeignKey(City,
                                         null=True,
                                         blank=True,
                                         related_name="destination",
                                         verbose_name="destino")

    description = models.TextField(verbose_name='descripción',
                                   blank=True,
                                   null=True)

    origin_timezone = TimeZoneField(choices=PRETTY_ALL_TIMEZONES_CHOICES,
                                    default='America/Mexico_City',
                                    blank=True,
                                    null=True)

    destination_timezone = TimeZoneField(choices=PRETTY_ALL_TIMEZONES_CHOICES,
                                         default='America/Mexico_City',
                                         blank=True,
                                         null=True)

    price_per_person = models.DecimalField(max_digits=20,
                                           decimal_places=2,
                                           verbose_name="precio por persona",
                                           null=True,
                                           blank=True)

    seats_available = models.PositiveIntegerField(
        verbose_name='asientos disponibles')

    private = models.BooleanField(default=False, verbose_name='viaje privado')

    kids_allowed = models.BooleanField(default=False, verbose_name='niños')

    photograph = models.ImageField(upload_to='galleries',
                                   blank=True,
                                   null=True)

    circle_photograph = models.ImageField(upload_to='galleries',
                                          blank=True,
                                          null=True)

    itinerary_file = models.FileField(upload_to='trip_files',
                                      blank=True,
                                      null=True,
                                      verbose_name='itinerario')

    def __str__(self):
        return self.title
예제 #14
0
class Employees(models.Model):
	id=models.CharField(max_length=10,primary_key=True)
	real_name=models.CharField(max_length=20)
	tz=TimeZoneField(choices=PRETTY_ALL_TIMEZONES_CHOICES)