Exemple #1
0
class Message(BaseModel, IndexedModelMixin):
    """Message model."""

    _index_class = IndexedMessage

    attachments = columns.List(columns.UserDefinedType(MessageAttachment))
    body_html = columns.Text()
    body_plain = columns.Text()
    date = columns.DateTime()
    date_delete = columns.DateTime()
    date_insert = columns.DateTime()
    discussion_id = columns.UUID()
    external_references = columns.UserDefinedType(ExternalReferences)
    identities = columns.List(columns.UserDefinedType(Identity))
    importance_level = columns.Integer()
    is_answered = columns.Boolean()
    is_draft = columns.Boolean()
    is_unread = columns.Boolean()
    is_received = columns.Boolean(default=False)
    message_id = columns.UUID(primary_key=True, default=uuid.uuid4)
    parent_id = columns.UUID()
    participants = columns.List(columns.UserDefinedType(Participant))
    privacy_features = columns.Map(columns.Text(), columns.Text())
    pi = columns.UserDefinedType(PIModel)
    raw_msg_id = columns.UUID()
    subject = columns.Text()  # Subject of email, the message for short
    tags = columns.List(columns.Text(), db_field="tagnames")
    type = columns.Text()
    user_id = columns.UUID(primary_key=True)
Exemple #2
0
class user(Model, UserMixin):
    hidden = ['password', 'google_id', 'facebook_id']

    id = columns.UUID(required=True, partition_key=True)

    password = columns.Bytes(required=False, )

    privacy = columns.Text(required=False, )

    email = columns.Text(
        required=False,
        index=True,
    )

    user_type = columns.Text(required=False, )

    email_confirmed = columns.Boolean(required=False, default=False)

    profile_completed = columns.Boolean(required=False, )

    google_id = columns.Text(
        required=False,
        index=True,
    )
    facebook_id = columns.Text(
        required=False,
        index=True,
    )

    created_at = columns.DateTime()
    updated_at = columns.DateTime()
class tbl_hello_world(Model):
    task_id = columns.BigInt(partition_key=True, primary_key=True)
    start_time = columns.Text()
    end_time = columns.Text()
    is_risk = columns.Boolean()
    predictable_characterization = columns.Text()
    predictable_identification = columns.Boolean()
    fault_scenario = columns.Text()
    root_cause = columns.Text()
Exemple #4
0
class Settings(BaseModel):
    """All settings related to an user."""

    user_id = columns.UUID(primary_key=True)
    default_locale = columns.Text()
    message_display_format = columns.Text()
    contact_display_format = columns.Text()
    contact_display_order = columns.Text()
    notification_enabled = columns.Boolean()
    notification_message_preview = columns.Text()
    notification_sound_enabled = columns.Boolean()
    notification_delay_disappear = columns.Integer()
Exemple #5
0
class Organization(BaseUserType):
    """Contact organizations model."""

    _pkey = 'organization_id'

    deleted = columns.Boolean(default=False)
    department = columns.Text()
    is_primary = columns.Boolean(default=False)
    job_description = columns.Text()
    label = columns.Text()
    name = columns.Text()
    organization_id = columns.UUID(default=uuid.uuid4)
    title = columns.Text()
    type = columns.Text()  # work, other
Exemple #6
0
class MeasurementRaw(Model):
    __keyspace__ = 'measurements'
    site = columns.Text(required=True, primary_key=True)
    meas_name = columns.Text(required=True, primary_key=True)
    ts = columns.DateTime(primary_key=True) # timestamp in schema
    sensor = columns.Text(required=True, primary_key=True)
    station = columns.Text(required=True, primary_key=True)
    company = columns.Text(required=True, primary_key=True)
    lat_lon = UserDefinedType(Geopoint)
    meas_description = columns.Text()
    meas_status = columns.Boolean()
    meas_unit = columns.Text()
    meas_val_b = columns.Boolean()
    meas_val_f = columns.Float()
    meas_val_s = columns.Text()
Exemple #7
0
class HarvesterResponse(models.Model):
    """A parody of requests.response but stored in cassandra
    Should reflect all methods of a response object
    Contains an additional field time_made, self-explanitory
    """
    __table_name__ = 'responses'

    method = columns.Text(primary_key=True)
    url = columns.Text(primary_key=True, required=True)

    # Raw request data
    ok = columns.Boolean()
    content = columns.Bytes()
    encoding = columns.Text()
    headers_str = columns.Text()
    status_code = columns.Integer()
    time_made = columns.DateTime(default=datetime.now)

    def json(self):
        return json.loads(self.content)

    @property
    def headers(self):
        return CaseInsensitiveDict(json.loads(self.headers_str))

    @property
    def text(self):
        return six.u(self.content)
Exemple #8
0
class UserTransactions(DjangoCassandraModel):
    transaction_id = columns.UUID(primary_key=True)
    user_id = columns.UUID()
    created_date = columns.DateTime()
    trade_type = columns.Text()
    purchase_type = columns.Text()
    currency = columns.Text()
    staring_price = columns.Float()
    closing_price = columns.Float()
    amount = columns.Float()
    start_time = columns.DateTime()
    end_time = columns.DateTime()
    changes_allowed_time = columns.DateTime()
    outcome = columns.Text()
    status = columns.Text()
    time_close = columns.DateTime()
    level_pips = columns.Integer()
    levels_price = columns.Text()
    level_owners = columns.Text()
    join_date = columns.DateTime()
    level_start_price = columns.Float()
    level_end_price = columns.Float()
    level_selected = columns.Integer()
    created_by = columns.UUID()
    parent_id = columns.UUID()
    child = columns.Boolean()
    available_levels = columns.List(columns.Integer())
Exemple #9
0
class TestModel(DjangoCassandraModel):

    __table_name = "test_model"
    __keyspace__ = "dis_test"
    nrc = columns.Text(primary_key=True, required=False)
    name = columns.Text(required=False)
    occupation = columns.Text(required=False)
    labour_id = columns.Text(index=True)
    race = columns.Text(required=False)
    religion = columns.Text(required=False)
    father_name = columns.Text(required=False)
    father_nrc = columns.Text(required=False)
    marital_status = columns.Boolean(required=False)
    dob = columns.Date(required=False)
    spouse_name = columns.Text(required=False)
    spouse_nrc = columns.Text(required=False)
    street = columns.Text(required=False)
    city = columns.Text(required=False)
    home_no = columns.Text(required=False)
    ward = columns.Text(required=False)
    township = columns.Text(required=False)
    gender = columns.Text(required=False)

    def __str__(self):
        return '%s %s %s' % (self.nrc, self.name, self.race)

        class Meta:
            db_table = "test_model"

    def address_approval(self):
        return '%s %s %s' % (self.nrc, self.name, self.father_name,
                             self.street, self.ward, self.home_no,
                             self.township)
class TestModel(models.Model):
    __connection__ = 'cassandra'
    __keyspace__ = 'db'

    id = columns.BigInt(primary_key=True)
    created_at = columns.DateTime()
    deleted = columns.Boolean(default=False)
Exemple #11
0
class Contact(BaseModel, IndexedModelMixin):
    """Contact model."""

    _index_class = IndexedContact

    user_id = columns.UUID(primary_key=True)
    contact_id = columns.UUID(primary_key=True)  # clustering key

    additional_name = columns.Text()
    addresses = columns.List(columns.UserDefinedType(PostalAddress))
    avatar = columns.Text()
    date_insert = columns.DateTime()
    date_update = columns.DateTime()
    deleted = columns.Boolean(default=False)
    emails = columns.List(columns.UserDefinedType(Email))
    family_name = columns.Text()
    given_name = columns.Text()
    groups = columns.List(columns.Text)
    identities = columns.List(columns.UserDefinedType(SocialIdentity))
    ims = columns.List(columns.UserDefinedType(IM))
    infos = columns.Map(columns.Text, columns.Text)
    name_prefix = columns.Text()
    name_suffix = columns.Text()
    organizations = columns.List(columns.UserDefinedType(Organization))
    phones = columns.List(columns.UserDefinedType(Phone))
    pi = columns.UserDefinedType(PIModel)
    privacy_features = columns.Map(columns.Text(), columns.Text())
    tags = columns.List(columns.UserDefinedType(ResourceTag))
    title = columns.Text()  # computed value, read only
Exemple #12
0
class AbstractBaseModel(Model, JsonMixin):
    """
    AbstractBaseModel
    This model is only intended to be used as a base class for other models
    """
    __abstract__ = True

    changed_on = columns.DateTime()
    created_on = columns.DateTime(default=datetime.utcnow)
    # super_active field, in case admin staff needs to disable the entry
    super_active = columns.Boolean(default=True)

    # --------------
    # Super Methods
    # --------------
    def save(self):
        self.changed_on = datetime.utcnow()
        signal('on_save').send(self.object, instance=self)
        return super(AbstractBaseModel, self).save()

    def update(self, **values):
        self.changed_on = datetime.utcnow()
        return super(AbstractBaseModel, self).update(**values)

    # --------------
    # Properties
    # --------------
    @property
    def object(self):
        return self.__table_name__
Exemple #13
0
class GroupMessage(DjangoCassandraModel):
    groupid = columns.Text(partition_key=True)
    id = columns.BigInt(primary_key=True)
    author = columns.UUID()
    content = columns.Text(required=True)
    attach = columns.Text()
    image = columns.Text()
    available = columns.Boolean()
    created_at = columns.DateTime(default=datetime.now())
    updated_at = columns.DateTime()

    class Meta:
        get_pk_field = 'groupid'

    def __str__(self):
        return self.author

    @staticmethod
    def last_30_messages(groupid):
        return GroupMessage.objects.filter(
            groupid=groupid).order_by('-id')[:30]

    @staticmethod
    def last_messages(groupid):
        return GroupMessage.objects.filter(groupid=groupid).order_by('-id')[:1]

    @staticmethod
    def get_list_groups():
        return GroupMessage.objects.distinct(['groupid'
                                              ]).order_by('created_at')
Exemple #14
0
class DataSetMap(Model):
    operator_id = columns.BigInt(primary_key=True)
    acronym = columns.Text(primary_key=True)
    kpi_name = columns.Text(primary_key=True)
    has_enough = columns.Boolean()

    __keyspace__ = "data_det"
    __table_name__ = "data_set_map"
Exemple #15
0
class User(Model):
    __keyspace__ = "soda"
    id = columns.UUID(primary_key=True, default=uuid.uuid4)
    email = columns.Text()
    password = columns.Text()
    created_at = columns.DateTime(default=datetime.now)
    is_valid = columns.Boolean(default=False)
    scopes = columns.List(value_type=columns.Text)
Exemple #16
0
class AdminUser(DjangoCassandraModel):
    __table_name__ = 'admin_user'
    username = columns.Text(max_length=20, primary_key=True)
    email = columns.Text(required=True, index=True)
    first_name = columns.Text(max_length=100)
    last_name = columns.Text(max_length=100)
    password = columns.Text(required=True, max_length=50)
    created_date = columns.DateTime(default=datetime.now, index=True)
    is_active = columns.Boolean(default=True)
Exemple #17
0
class User(Model):
    class ROLES:
        REGULAR_USER = 0
        ADMIN = 1

    user_id = columns.UUID(primary_key=True)
    username = columns.Text(required=True, index=True)
    first_name = columns.Text(required=True)
    last_name = columns.Text(required=True)
    email = EmailField(required=True)
    password = columns.Text(required=True)
    created = columns.DateTime()
    updated = columns.DateTime()
    role = columns.Integer(default=ROLES.REGULAR_USER)
    is_active = columns.Boolean(index=True, default=True)
    ban_reason = columns.Text()
    deleted = columns.Boolean(default=False, index=True)

    api_key = columns.Text(index=True)

    def __init__(self, **values):
        super().__init__(**values)
        if not self.user_id:
            self.user_id = self.generate_user_id()
            self.password = self.hash_password(values.pop('password'))

    def check_password(self, password):
        return sha512_crypt.verify(password, self.password)

    def generate_user_id(self):
        return uuid.uuid4().hex

    @staticmethod
    def hash_password(password):
        return sha512_crypt.hash(password)

    @staticmethod
    def generate_api_key(length=32):
        return ''.join(
            random.choice(string.ascii_letters + string.digits) for _ in
            range(length))

    def __repr__(self):
        return "<User(user_id='{}')>".format(self.user_id)
Exemple #18
0
class MessageAttachment(BaseUserType):

    """Attachment nested in message."""

    content_type = columns.Text()
    file_name = columns.Text()
    is_inline = columns.Boolean()
    size = columns.Integer()
    url = columns.Text()  # objectsStore uri for temporary file (draft)
    mime_boundary = columns.Text()  # for attachments embedded in raw messages
Exemple #19
0
class file(Model):

    id = columns.UUID(required=True, partition_key=True)

    path = columns.Text(required=False, index=True)

    tmp = columns.Boolean(required=False, )

    created_at = columns.DateTime()
    updated_at = columns.DateTime()
Exemple #20
0
class UserModel(Model):
    id = columns.UUID(default=uuid.uuid4)
    first_name = columns.Text(required=True)
    last_name = columns.Text(required=True)
    username = columns.Text(required=True, primary_key=True)
    email = columns.Text(required=True)
    active = columns.Boolean(default=False)
    admin = columns.Boolean(default=False)
    create_at = columns.DateTime(default=datetime.now())

    def to_dict(self):
        return {
            'id': str(self.id),
            'first_name': self.first_name,
            'last_name': self.last_name,
            'username': self.username,
            'email': self.email,
            'active': self.active,
            'admin': self.admin,
            'create_at': self.create_at,
        }

    @staticmethod
    def schema():
        return {
            'first_name': {
                'type': 'string',
                'required': True,
            },
            'last_name': {
                'type': 'string',
                'required': True,
            },
            'username': {
                'type': 'string',
                'required': True,
            },
            'email': {
                'type': 'string',
                'required': True,
                'regex': '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$',
            },
        }
Exemple #21
0
class RawMessage(BaseModel):
    """Raw message model."""

    raw_msg_id = columns.UUID(primary_key=True, default=uuid.uuid4)
    raw_data = columns.Bytes(
    )  # may be empty if data is too large to fit into cassandra
    raw_size = columns.Integer()  # number of bytes in 'data' column
    uri = columns.Text(
    )  # where object is stored if it was too large to fit into raw_data column
    delivered = columns.Boolean()  # true only if complete delivery succeeded
Exemple #22
0
class FilterRule(BaseModel):
    """User filter rules model."""

    user_id = columns.UUID(primary_key=True)
    rule_id = columns.UUID(primary_key=True)
    date_insert = columns.DateTime()
    name = columns.Text()
    filter_expr = columns.Text()
    position = columns.Integer()
    stop_condition = columns.Boolean()
Exemple #23
0
class Phone(BaseUserType):
    """Contact phones model."""

    _pkey = 'phone_id'
    uniq_name = 'number'

    is_primary = columns.Boolean(default=False)
    number = columns.Text()
    phone_id = columns.UUID(default=uuid.uuid4)
    type = columns.Text()
    uri = columns.Text()  # RFC3966
class WeatherDataset(Model):
    __keyspace__        = 'spardata'
    __connection__      = 'cluster1'
    year                = columns.Integer(primary_key=True, required=True)
    month               = columns.Integer(primary_key=True, required=True)
    date                = columns.Date(primary_key=True, required=True)
    station_location    = columns.Text(primary_key=True, required=True)
    tmin                = columns.Double(required=False, default=None)
    tmax                = columns.Double(required=False, default=None)
    tavg                = columns.Double(required=False, default=None)
    prcp                = columns.Boolean(required=False, default=False)
Exemple #25
0
 class ByArchitecture(Model, ConfigurationModel):
     __table_name__ = 'configurations_by_architecture'
     architecture = columns.Text(partition_key=True, required=True)
     style = columns.Text(primary_key=True, required=False)
     platform = columns.Text(primary_key=True, required=True)
     version = columns.Integer(primary_key=True, required=True)
     model = columns.Text(primary_key=True, required=False)
     flavor = columns.Text(primary_key=True, required=False)
     is_simulator = columns.Boolean(primary_key=True, required=True)
     version_name = columns.Text(primary_key=True, required=False)
     last_run = columns.DateTime(required=True)
Exemple #26
0
class DevicePublicKey(BaseModel):
    """Device public key."""

    user_id = columns.UUID(primary_key=True)
    device_id = columns.UUID(primary_key=True, default=uuid.uuid4)
    fingerprint = columns.Text(primary_key=True)

    date_insert = columns.DateTime(required=True,
                                   default=datetime.datetime.now(tz=pytz.utc))
    is_current = columns.Boolean(default=False)
    public_key = columns.Text()
Exemple #27
0
class Email(BaseUserType):
    """Contact emails model."""

    _pkey = 'email_id'
    uniq_name = 'address'

    address = columns.Text()
    email_id = columns.UUID(default=uuid.uuid4)
    is_primary = columns.Boolean(default=False)
    label = columns.Text()
    type = columns.Text()  # home, work, other
Exemple #28
0
class IM(BaseUserType):
    """Contact instant messaging adresses model."""

    _pkey = 'im_id'
    uniq_name = 'address'

    address = columns.Text()
    im_id = columns.UUID(default=uuid.uuid4)
    is_primary = columns.Boolean(default=False)
    label = columns.Text()
    protocol = columns.Text()
    type = columns.Text()
Exemple #29
0
class UserModel(DjangoCassandraModel):
    class Meta:
        get_pk_field = 'id'

    id = columns.UUID(primary_key=True, default=uuid.uuid1())
    lastname = columns.Text(required=False)
    firstname = columns.Text(required=False)
    username = columns.Text()
    password = columns.Text()
    admin = columns.Boolean(required=False)
    favorite = columns.Set(columns.UUID(), required=False)
    stock = columns.Map(columns.Text(), columns.Float(), required=False)
Exemple #30
0
class DNS(ConnBaseModel):
    __discriminator_value__ = 'DNS'
    trans_id = columns.Integer(required=False)
    rtt = columns.Text(required=False)
    query = columns.Text(required=False)
    qclass = columns.Text(required=False)
    qclass_name = columns.Text(required=False)
    qtype = columns.Text(required=False)
    qtype_name = columns.Text(required=False)
    rcode = columns.Integer(required=False)
    rcode_name = columns.Text(required=False)
    aa = columns.Boolean(required=False)
    tc = columns.Boolean(required=False)
    rd = columns.Boolean(required=False)
    ra = columns.Boolean(required=False)
    z = columns.Integer(required=False)
    answers = columns.Set(columns.Text, required=False)
    ttls = columns.Set(columns.Float, required=False)
    rejected = columns.Boolean(required=False)
    addl = columns.Text(required=False)
    auth = columns.Text(required=False)