Ejemplo n.º 1
0
class Airline(models.Model):
    _id = models.CharField(max_length=255,
                           default='',
                           unique=True,
                           db_index=True)
    main_color = models.CharField(max_length=255, null=True)
    additional_color = models.CharField(max_length=255, null=True)
    phone_number = models.CharField(max_length=255, null=True)
    website_address = models.CharField(max_length=255, null=True)
    address = models.TextField(null=True, blank=True)
    pending_destroy = models.BooleanField(default=False)
    online_checkin_address = models.TextField(null=True, blank=True)
    aviasales_path = models.TextField(null=True, blank=True)
    code = models.CharField(max_length=3, null=False, blank=False)
    alliance_mongo_id = models.CharField(max_length=255, null=True)
    created_at = models.DateTimeField(null=True)  # auto_now_add=True
    updated_at = models.DateTimeField(null=True)  # auto_now=True
    iata_name = ArrayField(models.CharField(max_length=255), null=True)
    pending_iata_name = ArrayField(models.CharField(max_length=255), null=True)
    weight = JsonBField()
    name = JsonBField(default={})
    description = JsonBField(default={})

    def __unicode__(self):
        return u'%s [%s]' % (self.name['en'], self.code)
Ejemplo n.º 2
0
class Place(models.Model):
    _id = models.CharField(max_length=255,
                           default='',
                           unique=True,
                           db_index=True)
    code = models.CharField(max_length=3)
    name = JsonBField()
    weight = JsonBField()
    coordinates = models.PointField(null=True)
    flightable = models.BooleanField(default=False)
Ejemplo n.º 3
0
class UserAuth(models.Model):
    """
    A way of authenticating a user. Generally either a third-party verifiable
    identity using OAuth or similar, or an identity token the user can provide
    themselves like an email address that will be combined with the password
    field on User.

    Each identity backend should have a single "identifier" field that can be
    looked up via an indexed equality query, and then all other relevant data
    in a "data" JSON blob.
    """

    TYPE_CHOICES = [
        ("email", "Email"),
        ("twitter", "Twitter"),
        ("facebook", "Facebook"),
        ("google", "Google"),
    ]

    user = models.ForeignKey(User, related_name="auths")
    type = models.CharField(max_length=30, choices=TYPE_CHOICES)
    identifier = models.TextField(db_index=True)
    data = JsonBField(blank=True, null=True)

    @classmethod
    def by_identifier(cls, id_type, identifier):
        # Check identifier type is valid
        if id_type not in [x for x, y in cls.TYPE_CHOICES]:
            raise ValueError("Invalid identifier type %s" % id_type)
        # Normalise identifier
        identifier = cls.normalise_identifier(id_type, identifier)
        # Get the right object
        try:
            return UserAuth.objects.get(type=id_type, identifier=identifier)
        except UserAuth.DoesNotExist:
            return None

    @classmethod
    def normalise_identifier(cls, id_type, identifier):
        """
        Normalises identifiers to avoid comparison errors.
        """
        if id_type == "email":
            return identifier.lower()
        elif id_type == "twitter":
            return identifier.lower()
        else:
            return identifier

    def __unicode__(self):
        return "%s: %s" % (self.type, self.human_name)

    @property
    def human_name(self):
        """
        Returns a human-understandable name for the identifier
        (e.g. the facebook profile name rather than the user ID)
        """
        return self.identifier
Ejemplo n.º 4
0
class Event(models.Model):
    project = models.ForeignKey("ae_reflex.Project", related_name='events')
    data = JsonBField()
    source_key = models.ForeignKey("ae_reflex.Key", null=True)
    created = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.project.name
Ejemplo n.º 5
0
class Grade(models.Model):
    data = JsonBField()

    def find_by_project_id(self, project_id):
        results = Grade.objects.filter(
            data__jcontains={"summary": {
                "project_id": project_id
            }})
        if (results and results[0]):
            return results[0]
        return None
Ejemplo n.º 6
0
class Subset(FilterMixin, models.Model):
    """Stores a single subset."""

    name = models.CharField(max_length=100)
    description = models.TextField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(settings.AUTH_USER_MODEL)
    project = models.ForeignKey('projects.Project', related_name='subsets')
    filters = JsonBField(blank=True, null=True)
    where_clause = models.TextField(blank=True, null=True)
    history = HistoricalRecords()
Ejemplo n.º 7
0
class Subset(FilterMixin, models.Model):
    """
    Subsets define pre-defined query for a share of all data in a project.
    """
    name = models.CharField(max_length=100)
    description = models.TextField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(settings.AUTH_USER_MODEL)
    project = models.ForeignKey('projects.Project', related_name='subsets')
    filters = JsonBField(blank=True, null=True)
    where_clause = models.TextField(blank=True, null=True)
Ejemplo n.º 8
0
class Rule(models.Model):
    """
    Rules are used in data groupings to define directives to filter data in a
    project.
    """
    grouping = models.ForeignKey('Grouping', related_name='rules')
    category = models.ForeignKey('categories.Category')
    min_date = models.DateTimeField(null=True)
    max_date = models.DateTimeField(null=True)
    constraints = JsonBField(null=True, default=None)
    status = models.CharField(choices=STATUS,
                              default=STATUS.active,
                              max_length=20)

    objects = RuleManager()

    def get_query(self):
        """
        Returns the SQL where clause for the rule. It combines the where clause
        parts of each field in the category. See Grouping.get_where_clause()
        to find out how it's applied.

        Returns
        -------
        str
            SQL where clause for the rule
        """
        queries = ['(category_id = %s)' % self.category.id]

        if self.min_date is not None:
            queries.append('(created_at >= to_date(\'' +
                           self.min_date.strftime('%Y-%m-%d %H:%I') +
                           '\', \'YYYY-MM-DD HH24:MI\'))')

        if self.max_date is not None:
            queries.append('(created_at <= to_date(\'' +
                           self.max_date.strftime('%Y-%m-%d %H:%I') +
                           '\', \'YYYY-MM-DD HH24:MI\'))')

        if self.constraints is not None:
            for key in self.constraints:
                field = self.category.fields.get_subclass(key=key)
                queries.append(field.get_filter(self.constraints[key]))

        return '(%s)' % ' AND '.join(queries)

    def delete(self):
        """
        Deletes the Filter by setting its status to DELETED.
        """
        self.status = STATUS.deleted
        self.save()
Ejemplo n.º 9
0
class Route(models.Model):
    _id = models.CharField(max_length=255,
                           default='',
                           unique=True,
                           db_index=True)
    airline_mongo_ids = ArrayField(models.CharField(max_length=255), null=True)
    created_at = models.DateTimeField()  # auto_now_add=True
    updated_at = models.DateTimeField()  # auto_now=True
    dest_mongo_id = models.CharField(max_length=255)
    orig_mongo_id = models.CharField(max_length=255)
    max_duration = models.BigIntegerField(null=True)
    min_duration = models.BigIntegerField(null=True)
    weight = JsonBField()
Ejemplo n.º 10
0
class FlightCode(models.Model):
    _id = models.CharField(max_length=255,
                           default='',
                           unique=True,
                           db_index=True)
    aircraft_mongo_ids = ArrayField(models.CharField(max_length=255),
                                    null=True)
    created_at = models.DateTimeField(null=True)  # auto_now_add=True
    updated_at = models.DateTimeField(null=True)  # auto_now=True
    first_date = models.DateTimeField(null=True)
    last_date = models.DateTimeField(null=True)
    airline_mongo_id = models.CharField(max_length=255)
    flight_number = models.CharField(max_length=255)
    aircraft = models.CharField(max_length=255, null=True)
    airport_route_mongo_id = models.CharField(max_length=255)
    weight = JsonBField()
    durations = ArrayField(models.IntegerField(), null=True)
    duration = models.IntegerField(null=True)
Ejemplo n.º 11
0
class UserGroup(FilterMixin, models.Model):
    """
    A user gropup assigned to a project.
    """
    name = models.CharField(max_length=100)
    description = models.TextField(blank=True, null=True)
    users = models.ManyToManyField(settings.AUTH_USER_MODEL)
    project = models.ForeignKey('projects.Project', related_name='usergroups')
    can_contribute = models.BooleanField(default=True)
    can_moderate = models.BooleanField(default=False)
    filters = JsonBField(blank=True, null=True)
    where_clause = models.TextField(blank=True, null=True)

    def save(self, *args, **kwargs):
        """
        Overwrites save to implement integrity ensurance.
        """
        if self.can_moderate:
            self.can_contribute = True

        super(UserGroup, self).save(*args, **kwargs)
Ejemplo n.º 12
0
class Greeting(models.Model):
    # Relations

    # Attributes - Mandatory
    name = models.CharField(default="", max_length=32)
    data = JsonBField()

    # Attributes - Optional
    # Object Manager
    objects = managers.GreetingManager()

    # Custom Properties
    # Methods

    # Meta and String
    class Meta:
        verbose_name = _("Greeting")
        verbose_name_plural = _("Greetings")

    def __str__(self):
        return self.name
Ejemplo n.º 13
0
class Observation(models.Model):
    """
    Stores a single observation.
    """
    location = models.ForeignKey(
        Location, related_name='locations'
    )
    project = models.ForeignKey(
        'projects.Project', related_name='observations'
    )
    category = models.ForeignKey('categories.Category')
    status = models.CharField(
        choices=OBSERVATION_STATUS,
        default=OBSERVATION_STATUS.active,
        max_length=20
    )
    properties = JsonBField(default={})
    created_at = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name='creator'
    )
    updated_at = models.DateTimeField(null=True, auto_now_add=True)
    updator = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name='updator',
        null=True
    )
    version = models.IntegerField(default=1)
    search_matches = models.TextField()
    display_field = models.TextField(null=True, blank=True)
    num_media = models.IntegerField(default=0)
    num_comments = models.IntegerField(default=0)

    history = HistoricalRecords()
    objects = ObservationManager()

    class Meta:
        ordering = ['-updated_at', 'id']

    @classmethod
    def validate_partial(self, category, data):
        """
        Validates the data against the category field definition. This is a
        partial validation, which is used to validate drafts, field values
        that are not provided are not validated.

        Parameter
        ---------
        category : geokey.categories.models.Category
            Category that the data is validated against
        data : dict
            Dictionary of key-value-pairs; incoming data that is validated

        Raises
        ------
        ValidationError:
            when data is invalid
        """
        is_valid = True
        error_messages = []

        for field in category.fields.all().filter(status='active'):
            if field.key in data and data.get(field.key) is not None:
                try:
                    field.validate_input(data.get(field.key))
                except InputError, error:
                    is_valid = False
                    error_messages.append(error)

        if not is_valid:
            raise ValidationError(error_messages)
Ejemplo n.º 14
0
class Community_Information(modelsGis.Model):

    json_column = JsonBField()  # can pass attributes like null, blank, ecc.
    geom = modelsGis.GeometryField(null=True)
Ejemplo n.º 15
0
class TextModelB(models.Model):
    data = JsonBField()