Ejemplo n.º 1
0
class service_table(Model):
    # service info
    service_uuid = columns.UUID(primary_key=True)
    user = columns.Text(index=True)
    start_time = columns.BigInt(index=True)
    end_time = columns.BigInt(index=True)
    state = columns.Text(required=False)
    status = columns.Text(index=True)
    topofile = columns.Text(required=False)
    topology = columns.Text(required=False)
    reason = columns.Text(required=False)
    cnr_info = columns.Text(required=False)
    vnc_info = columns.Text(required=False)
    # cbr info
    cbr_name = columns.Text()
    cbr_num = columns.Integer()
    cbr_type = columns.Text()
    cbr_image = columns.Text(required=False)
    cbr_branch = columns.Text(required=False)
    cbr_label = columns.Text(required=False)
    # rpd info
    rpd_names = columns.List(value_type=columns.Text)
    rpd_num = columns.Integer()
    rpd_type = columns.Text()
    rpd_image = columns.Text(required=False)
    rpd_branch = columns.Text(required=False)
    rpd_label = columns.Text(required=False)
    # cm info
    cm_num = columns.Integer()
    # tng info
    tgn = columns.Text()
    tgn_port_speed = columns.Text(required=False)
    tgn_type = columns.Text(required=False)
    tgn_name = columns.Text(required=False)
    tgn_conn_ports = columns.List(value_type=columns.Text, required=False)
Ejemplo n.º 2
0
class accomodation(Model):
    file_fields = ['photos']
    json_fields = ['rooms']

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

    type = columns.Text(required=False, )
    name = columns.Text(required=False, )
    phone = columns.Text(required=False, )
    address = columns.Text(required=False, )
    facilities = columns.List(
        columns.Text,
        required=False,
    )
    description = columns.Text(required=False, )
    photos = columns.List(
        columns.Text,
        required=False,
    )
    rooms = columns.Text(
        required=False,
        default=
        '[{"enabled":false,"type":"shared half","quota":null,"price":null},{"enabled":false,"type":"shared 3 ppl","quota":null,"price":null},{"enabled":false,"type":"private double bed","quota":null,"price":null}]'
    )

    created_at = columns.DateTime()
    updated_at = columns.DateTime()
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
class BargainerModel(UserType):
    __type_name__ = 'bargainer'
    algo_type = columns.Text(required=True)
    current_price_history = columns.List(
        value_type=UserDefinedType(CurrentPriceModel), default=[])
    price_change_history = columns.List(
        value_type=UserDefinedType(PriceChangeModel), default=[])
Ejemplo n.º 5
0
class DocumentModel(models.Model):
    __table_name__ = 'documents'

    # Raw
    source = columns.Text(primary_key=True, partition_key=True)
    docID = columns.Text(primary_key=True, index=True, clustering_order='ASC')

    doc = columns.Bytes()
    filetype = columns.Text()
    timestamps = columns.Map(columns.Text, columns.Text)

    # Normalized
    uris = columns.Text()
    title = columns.Text()
    contributors = columns.Text()
    providerUpdatedDateTime = columns.DateTime()

    description = columns.Text()
    freeToRead = columns.Text()
    languages = columns.List(columns.Text())
    licenses = columns.Text()
    publisher = columns.Text()
    subjects = columns.List(columns.Text())
    tags = columns.List(columns.Text())
    sponsorships = columns.Text()
    version = columns.Text()
    otherProperties = columns.Text()
    shareProperties = columns.Text()

    # Additional metadata
    versions = columns.List(columns.UUID)
Ejemplo n.º 6
0
class PortfolioStat(Model):
    id = columns.Integer(primary_key=True)
    reward = columns.Float()
    risk = columns.Float()
    time_evaluated = columns.Float()
    latency = columns.Float()
    weights = columns.List(columns.Float())
    weight_labels = columns.List(columns.Text())
Ejemplo n.º 7
0
class purchasedetail(DjangoCassandraModel):
    cname = columns.Text(max_length=30)
    orderno = columns.Integer(primary_key=True)
    productdetails = columns.List(value_type=text)
    totalcost = columns.Integer()
    img = columns.List(value_type=text)
    status = columns.Text(max_length=30)
    date = columns.Text(max_length=30)
    orderby = columns.Text(max_length=30)
Ejemplo n.º 8
0
class TestNestedModel(Model):

    partition = columns.UUID(primary_key=True, default=uuid4)
    list_list = columns.List(columns.List(columns.Integer), required=False)
    map_list = columns.Map(columns.Text,
                           columns.List(columns.Text),
                           required=False)
    set_tuple = columns.Set(columns.Tuple(columns.Integer, columns.Integer),
                            required=False)
Ejemplo n.º 9
0
class Courses(Model):
        __keyspace__ = 'courses'
        id = columns.Integer(primary_key=True)
        startTime = columns.Time()
        endTime = columns.Time()
        geCodes = columns.List(columns.Text())
        name = columns.Text()
        quarter = columns.Text()
        prerequisites = columns.List(columns.Text())
        session = _session
Ejemplo n.º 10
0
class Catalog(BaseModel):
    name = columns.Text(required=True)
    description = columns.Text(required=False)
    ic_subset = columns.List(value_type=columns.Text, required=True)
    version = columns.Text(required=False)
    status = columns.Text(required=False)
    owner = columns.Text(required=True)
    visibility = columns.Text(required=True)
    tags = columns.List(value_type=columns.Text, required=False)
    ic_subset = columns.List(value_type=columns.Text, required=True)
Ejemplo n.º 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.DateTime()
    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.Text(), db_field="tagnames")
    title = columns.Text()  # computed value, read only
Ejemplo n.º 12
0
class IndexedCollectionsTestModel(Model):

    test_id = columns.Integer(primary_key=True)
    attempt_id = columns.Integer(index=True)
    description = columns.Text()
    expected_result = columns.Integer()
    test_result = columns.Integer(index=True)
    test_list = columns.List(columns.Integer, index=True)
    test_set = columns.Set(columns.Integer, index=True)
    test_map = columns.Map(columns.Text, columns.Integer, index=True)

    test_list_no_index = columns.List(columns.Integer, index=False)
    test_set_no_index = columns.Set(columns.Integer, index=False)
    test_map_no_index = columns.Map(columns.Text, columns.Integer, index=False)
Ejemplo n.º 13
0
class CassSpectrum(Model):
    __table_name__ = "spectra"
    id = columns.UUID(primary_key=True, default=uuid.uuid4)
    spectrum_id = columns.Text(index=True)
    wavelengths = columns.List(columns.Double())
    intensities = columns.List(columns.Double())
    metadata = columns.Map(key_type=columns.Text, value_type=columns.Text)

    def to_dict(self):
        return {
            "id": self.spectrum_id,
            "wavelengths": self.intensities,
            "intensities": self.intensities,
            "metadata": self.metadata
        }
Ejemplo n.º 14
0
class test(Model):

    id = columns.UUID(required=True, partition_key=True)
    ls = columns.List(
        columns.Text,
        required=False,
    )
    lsi = columns.List(
        columns.Integer,
        required=False,
    )
    dm = columns.Decimal(required=False, )

    created_at = columns.DateTime()
    updated_at = columns.DateTime()
Ejemplo n.º 15
0
class ExternalReferences(BaseUserType):

    """External references nested in message."""

    ancestors_ids = columns.List(columns.Text())
    message_id = columns.Text()
    parent_id = columns.Text()
Ejemplo n.º 16
0
class Tag(Base):
    __table_name__ = 'tags'

    bucket = columns.Text(primary_key=True, partition_key=True, required=True)
    tag = columns.Text(primary_key=True, required=True)
    transactions = columns.List(columns.UserDefinedType(TransactionObject))

    @classmethod
    def get_transaction_hashes(cls, tag):
        tag_meta = Tag.get(tag)

        if not tag_meta:
            return list()

        return [
            transaction['hash'] for transaction in tag_meta['transactions']
        ]

    @classmethod
    def get(cls, tag):
        try:
            tag = Tag.objects.get(bucket=tag[:5], tag=tag)
            return tag.as_json()
        except DoesNotExist:
            return None

    def as_json(self):
        return {'tag': self.tag, 'transactions': self.transactions}
Ejemplo n.º 17
0
class Approvee(Base):
    __table_name__ = 'approvees'

    bucket = columns.Text(primary_key=True, partition_key=True, required=True)
    hash = columns.Text(primary_key=True, required=True)
    approvees = columns.List(columns.UserDefinedType(TransactionObject))

    @classmethod
    def get(cls, hash):
        try:
            approvee = Approvee.objects.get(bucket=hash[:5], hash=hash)
            return approvee.as_json()
        except DoesNotExist:
            return None

    def as_json(self):
        return {'hash': self.hash, 'transactions': self.transactions}

    @classmethod
    def get_approvees_hashes(cls, hash):
        approvee_meta = Approvee.get(hash)

        if not approvee_meta:
            return list()

        return [
            transaction['hash'] for transaction in approvee_meta['approvees']
        ]
Ejemplo n.º 18
0
class Blob(Model):
    """Blob Model"""
    id = columns.Text(primary_key=True, default=default_uuid)
    parts = columns.List(columns.Text, default=[], index=True)
    size = columns.Integer(default=0)
    hash = columns.Text(default="")

    @classmethod
    def create_from_file(cls, fileobj, size):
        """Create an object from an opened file"""
        blob = cls.create(size=size)
        hasher = hashlib.sha256()

        chunk_size = 1024 * 1024 * 1
        parts = []
        while True:
            data = fileobj.read(chunk_size)
            if not data:
                break
            part = BlobPart.create(content=data, blob_id=blob.id)
            parts.append(part.id)

            hasher.update(data)

        blob.update(parts=parts, hash=hasher.hexdigest())
        return blob

    @classmethod
    def find(cls, id_):
        """Find an object from its id"""
        return cls.objects.filter(id=id_).first()

    def __unicode__(self):
        return unicode(self.id)
Ejemplo n.º 19
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())
Ejemplo n.º 20
0
class group(Model):
    group_id = columns.Integer(primary_key=True)
    create_time = columns.DateTime()
    modify_time = columns.DateTime()
    group_name = columns.Text(index=True)
    group_member = columns.List(columns.Text)
    group_description = columns.Text()
Ejemplo n.º 21
0
class school_profile(Model):
    file_fields = ['logo', 'photos', 'registration_document']
    json_fields = ['contact_persons']

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

    user_id = columns.UUID(required=False, index=True)

    status = columns.Text(required=False, )
    name = columns.Text(required=False, )
    address = columns.Text(required=False, )
    city = columns.Text(required=False, )
    country = columns.Text(required=False, )
    introduction = columns.Text(required=False, )
    website = columns.Text(required=False, )
    contact_persons = columns.Text(
        required=False,
        default=
        '[{"last_name":null,"first_name":null,"title":null,"email":null,"tel":null},{"last_name":null,"first_name":null,"title":null,"email":null,"tel":null}]'
    )
    registration_document = columns.Text(required=False, )
    stripe = columns.Text(required=False, )
    logo = columns.Text(required=False, )
    photos = columns.List(
        columns.Text,
        required=True,
    )

    created_at = columns.DateTime()
    updated_at = columns.DateTime()
Ejemplo n.º 22
0
 def test_instantiation_with_column_class(self):
     """
     Tests that columns instantiated with a column class work properly
     and that the class is instantiated in the constructor
     """
     column = columns.List(columns.Text)
     assert isinstance(column.value_col, columns.Text)
Ejemplo n.º 23
0
class tweet_bank(DjangoCassandraModel):
    tweetid = columns.Text(primary_key=True)
    pdt_sentiment = columns.Double()
    sentimentid = columns.Text()
    tweet = columns.Text()
    tweet_text = columns.Text()
    tweet_text_cleaned = columns.List(columns.Text)
Ejemplo n.º 24
0
class PublicKey(BaseModel):
    """Public cryptographic keys model."""

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

    resource_type = columns.Text()
    label = columns.Text()

    date_insert = columns.DateTime(default=datetime.utcnow)
    date_update = columns.DateTime()
    expire_date = columns.DateTime()

    emails = columns.List(columns.Text())

    key = columns.Text()
    fingerprint = columns.Text()
    size = columns.VarInt()

    # JWT parameters
    kty = columns.Text()  # rsa / ec
    use = columns.Text()  # sig / enc
    alg = columns.Text()  # algorithm
    # Elliptic curve public key parameters (rfc7518 6.2.1)
    crv = columns.Text()
    x = columns.VarInt()
    y = columns.VarInt()
Ejemplo n.º 25
0
 def test_to_python(self):
     """ Tests that to_python of value column is called """
     column = columns.List(JsonTestColumn)
     val = [1, 2, 3]
     db_val = column.to_database(val)
     assert db_val.value == [json.dumps(v) for v in val]
     py_val = column.to_python(db_val.value)
     assert py_val == val
Ejemplo n.º 26
0
class TestModelSave(Model):
    partition = columns.UUID(primary_key=True, default=uuid4)
    cluster = columns.Integer(primary_key=True)
    count = columns.Integer(required=False)
    text = columns.Text(required=False, index=True)
    text_set = columns.Set(columns.Text, required=False)
    text_list = columns.List(columns.Text, required=False)
    text_map = columns.Map(columns.Text, columns.Text, required=False)
Ejemplo n.º 27
0
class ContactLookup(BaseModel):
    """Lookup any information needed to recognize a user contact."""

    user_id = columns.UUID(primary_key=True)
    value = columns.Text(
        primary_key=True)  # address or 'identifier' in identity
    type = columns.Text(primary_key=True)  # email, IM, etc.
    contact_ids = columns.List(columns.UUID())  # many contacts is allowed
Ejemplo n.º 28
0
 def test_to_python(self):
     """ Tests that to_python of value column is called """
     column = columns.List(JsonTestColumn)
     val = [1, 2, 3]
     db_val = column.to_database(val)
     self.assertEqual(db_val, [json.dumps(v) for v in val])
     py_val = column.to_python(db_val)
     self.assertEqual(py_val, val)
Ejemplo n.º 29
0
class IngredientModel(DjangoCassandraModel):
    class Meta:
        get_pk_field = 'id'

    id = columns.UUID(primary_key=True, default=uuid.uuid1())
    name = columns.Text(primary_key=True)
    category = columns.Text()
    usedby = columns.List(columns.UUID)
Ejemplo n.º 30
0
class Contact(BaseContactModel):

    """Contact model."""

    # Redefine, need default
    deleted = columns.Integer(default=0)
    title = columns.Text()          # computed value, read only
    # detailed name structure
    given_name = columns.Text()
    additional_name = columns.Text()
    family_name = columns.Text()
    name_prefix = columns.Text()
    name_suffix = columns.Text()
    tags = columns.List(columns.Text)
    groups = columns.List(columns.Text)
    # everything else in a map
    infos = columns.Map(columns.Text, columns.Text)