Esempio n. 1
0
class Guest(Model, UserMixin):
    class Meta:
        table_name = os.getenv("DYNAMO_TABLE")
        region = os.getenv("AWS_REGION")
        host = os.getenv("AWS_ENDPOINT_URL", None)

    id = UUIDAttribute(hash_key=True, default=uuid.uuid4)
    email = UnicodeAttribute()
    name = UnicodeAttribute()
    food_allergies = UnicodeAttribute(null=True)
    favourite_music = UnicodeAttribute(null=True)
    last_viewed = UTCDateTimeAttribute(null=True)
    last_responded = UTCDateTimeAttribute(null=True)
    number_of_guests = NumberAttribute(default=0)
    notes = UnicodeAttribute(null=True)
    will_attend = BooleanAttribute(null=True)
    filled_by_admin = BooleanAttribute(null=True)

    def get_id(self):
        return str(self.id)

    @staticmethod
    def find(guest_id: str):
        try:
            return Guest.get(guest_id)
        except DoesNotExist:
            return None

    @staticmethod
    def find_multi_id(guest_ids: list) -> iter:
        try:
            return Guest.batch_get(guest_ids)
        except DoesNotExist:
            return []
Esempio n. 2
0
 def test_boolean_deserialize(self):
     """
     BooleanAttribute.deserialize
     """
     attr = BooleanAttribute()
     assert attr.deserialize(True) is True
     assert attr.deserialize(False) is False
Esempio n. 3
0
class AppUser(Model):
    """
    A user of the Hubmetrix app
    """
    class Meta:
        table_name = 'hubmetrix-user'
        region = 'us-west-1'

    bc_store_hash = UnicodeAttribute(hash_key=True)
    bc_email = UnicodeAttribute()
    bc_id = NumberAttribute(range_key=True)
    bc_store_id = UnicodeAttribute(null=True)
    bc_access_token = UnicodeAttribute()
    bc_scope = UnicodeAttribute()
    bc_webhooks_registered = BooleanAttribute(default=False)
    bc_webhook_ids = ListAttribute(null=True)
    bc_deleted = BooleanAttribute(default=False)
    hs_refresh_token = UnicodeAttribute(null=True)
    hs_access_token = UnicodeAttribute(null=True)
    hs_expires_in = UnicodeAttribute(null=True)
    hs_app_id = UnicodeAttribute(null=True)
    hs_hub_domain = UnicodeAttribute(null=True)
    hs_hub_id = UnicodeAttribute(null=True)
    hs_token_type = UnicodeAttribute(null=True)
    hs_user = UnicodeAttribute(null=True)
    hs_user_id = UnicodeAttribute(null=True)
    hs_scopes = ListAttribute(null=True)
    hs_properties_exist = BooleanAttribute(default=False)
    hs_access_token_timestamp = UnicodeAttribute(null=True)
    cb_subscription_id = UnicodeAttribute(null=True)
    hm_last_sync_timestamp = UnicodeAttribute(null=True)
Esempio n. 4
0
class DEV_GPS_LOCATION(Model):
    class Meta:
        aws_access_key_id = 'AKIAJXFC3JRVYNIHX2UA'
        aws_secret_access_key = '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'
        table_name = "DEV_GPS_LOCATION"
        region = 'ap-south-1'
        write_capacity_units = 2
        read_capacity_units = 2

    created_by = UnicodeAttribute(null=True)
    changed_by = UnicodeAttribute(null=True)
    gps_device_provider = UnicodeAttribute(null=True)
    created_on = UTCDateTimeAttribute(default=datetime.now())
    updated_on = UTCDateTimeAttribute(default=datetime.now())
    deleted = BooleanAttribute(default=False)
    deleted_on = UTCDateTimeAttribute(null=True)
    device_id = UnicodeAttribute(hash_key=True)
    imei = UnicodeAttribute(null=True)
    driver_name = UnicodeAttribute(null=True)
    driver_number = UnicodeAttribute(null=True)
    driving_licence_number = UnicodeAttribute(null=True)
    vehicle_number = UnicodeAttribute(null=True)
    vehicle_type = UnicodeAttribute(null=True)
    vehicle_status = UnicodeAttribute(null=True)
    location_time = UTCDateTimeAttribute(null=True)
    latitude = NumberAttribute(attr_name='latitude')
    longitude = NumberAttribute(attr_name='longitude')
    address = UnicodeAttribute(null=True)
    is_active = BooleanAttribute(default=True)
Esempio n. 5
0
class UserModel(Model):
    class Meta:
        table_name = USERS_TABLE_NAME
        write_capacity_units = 100
        read_capacity_units = 100
        # host = "http://localhost:4569"

    userId = UnicodeAttribute(hash_key=True)
    email = UnicodeAttribute(null=True)
    name = UnicodeAttribute(null=True)
    slug = UnicodeAttribute(null=True)
    avatar = UnicodeAttribute(null=True)
    ideasMailSchedule = UnicodeAttribute(null=True, default="1,2,3,4,5,6,7")
    lastRequestedIdeaDate = UTCDateTimeAttribute(null=True)
    # sortKey = UnicodeAttribute(range_key=True)
    createdDate = UTCDateTimeAttribute(null=True)
    firstLogin = BooleanAttribute(null=True)

    ideaReminders = BooleanAttribute(null=True)
    hotStreaks = BooleanAttribute(null=True)
    dailyDigests = BooleanAttribute(null=True)
    weeklyDigests = BooleanAttribute(null=True)
    snoozeEmails = UTCDateTimeAttribute(null=True)
    unsubscribedAt = UTCDateTimeAttribute(null=True)
    emailToken = UnicodeAttribute(null=True)

    followersCount = NumberAttribute(default=0)
    ideasCreated = NumberAttribute(default=0)
    followeesCount = NumberAttribute(default=0)

    emailIndex = UserEmailIndex()
Esempio n. 6
0
class AttackModel(BaseModel):
    class Meta:
        table_name = os.environ.get('DYNAMODB_ATTACK_TABLE', 'ATTACKS')
        if 'ENV' in os.environ:
            host = 'http://localhost:8000'
        else:
            region = aws_region
            host = f'https://dynamodb.{aws_region}.amazonaws.com'

    id = UnicodeAttribute(range_key=True, null=False, default=str(uuid4()))
    fight_id = UnicodeAttribute(hash_key=True)
    attack_ts = UTCDateTimeAttribute()
    source_id = UnicodeAttribute()
    source_tp = UnicodeAttribute()
    target_id = UnicodeAttribute()
    target_tp = UnicodeAttribute()

    attack_amt = NumberAttribute(default=0)
    is_missed = BooleanAttribute(default=False)
    is_critical = BooleanAttribute(default=False)
    is_blocked = BooleanAttribute(default=False)
    block_amt = NumberAttribute(default=0)
    is_dodged = BooleanAttribute(default=0)
    t_curr_hp = NumberAttribute(default=0)
    t_prev_hp = NumberAttribute(default=0)

    def save(self, conditional_operator=None, **expected_values):
        self.id = str(uuid4())
        self.created_at = datetime.utcnow()
        self.updated_at = datetime.utcnow()
        super(AttackModel, self).save()
Esempio n. 7
0
class Server(Model):
    class Meta:
        if os.getenv("STAGE", "PRODUCTION") == "TESTING":
            host = "http://dynamodb:8000"
        table_name = "server"
        billing_mode = "PAY_PER_REQUEST"
        region = "us-west-2"

    server_index = ServerIndex()

    address = UnicodeAttribute(hash_key=True)
    game = UnicodeAttribute()

    protocol = NumberAttribute(default=0)

    status = JSONAttribute()
    players = JSONAttribute()
    player_count = NumberAttribute(default=0)

    active = BooleanAttribute(default=True)
    scraped = BooleanAttribute(default=False)

    first_seen = UTCDateTimeAttribute(default=datetime.utcnow())
    last_seen = UTCDateTimeAttribute(default=datetime.utcnow())

    country_code = UnicodeAttribute(default="ZZ")
Esempio n. 8
0
 def test_boolean_deserialize(self):
     """
     BooleanAttribute.deserialize
     """
     attr = BooleanAttribute()
     self.assertEqual(attr.deserialize('1'), True)
     self.assertEqual(attr.deserialize('0'), False)
Esempio n. 9
0
class ItemModel(BaseModel):
    class Meta:
        table_name = os.environ['DYNAMODB_TABLE']
        if 'ENV' in os.environ:
            host = 'http://localhost:8000'
        else:
            region = aws_region
            host = f'https://dynamodb.{aws_region}.amazonaws.com'

    id = UnicodeAttribute(hash_key=True, default=str(uuid4()))
    name = UnicodeAttribute()
    description = UnicodeAttribute(null=True)
    quality = NumberAttribute(default=1)
    quality_name = UnicodeAttribute(default=ItemQuality[1])
    slot = NumberAttribute()
    slot_name = UnicodeAttribute()
    damage = NumberAttribute(default=10)
    stamina = NumberAttribute(default=10)
    crit_chance = NumberAttribute(default=0.01)
    level = NumberAttribute(default=1)
    is_warrior = BooleanAttribute(default=False)
    is_sorcerer = BooleanAttribute(default=False)
    is_rogue = BooleanAttribute(default=False)
    is_archer = BooleanAttribute(default=False)
    player_class = NumberAttribute(default=0)

    player_class_index = PlayerClassViewIndex()
    level_index = LevelViewIndex()

    def save(self, conditional_operator=None, **expected_values):
        self.updated_at = datetime.utcnow()
        self.quality_name = ItemQuality[self.quality]
        self.slot_name = ItemSlot[self.slot]

        super(ItemModel, self).save()
Esempio n. 10
0
class ServiceModel(Model):
    """
    Service Model
    """
    class Meta:
        table_name = "service"
    name = UnicodeAttribute(hash_key=True)
    fqdn = UnicodeAttribute()
    healthcheck_path = UnicodeAttribute(default='/')
    healthcheck_interval = NumberAttribute(default=5000)
    healthcheck_rise = NumberAttribute(default=10)
    healthcheck_fall = NumberAttribute(default=3)
    connection_draining = NumberAttribute(default=20)
    failover_pool_fqdn = UnicodeAttribute(default="")
    failover_pool_use_https = BooleanAttribute(default=0)
    failover_pool_ssl_allow_self_signed_certs = BooleanAttribute(default=0)
    dns_resolver = UnicodeAttribute(default="")

    def as_dict(self):
        return {
            'name': self.name,
            'fqdn': self.fqdn,
            'healthcheck_interval': self.healthcheck_interval,
            'healthcheck_path': self.healthcheck_path,
            'healthcheck_rise': self.healthcheck_rise,
            'healthcheck_fall': self.healthcheck_fall,
            'connection_draining': self.connection_draining,
            'failover_pool_fqdn': self.failover_pool_fqdn,
            'failover_pool_use_https': self.failover_pool_use_https,
            'failover_pool_ssl_allow_self_signed_certs': self.failover_pool_ssl_allow_self_signed_certs,
            'dns_resolver': self.dns_resolver,
        }

    def __eq__(self, other):
        return self.__dict__ == other.__dict__
Esempio n. 11
0
class PredictionModel(Model):
    """DynamoDB table model relying on pynamodb."""
    class Meta:
        table_name = os.environ['DYNAMO_TABLE_NAME']
        region = os.environ['DYNAMO_REGION']
        write_capacity_units = os.environ['DYNAMO_WCU']
        read_capacity_units = os.environ['DYNAMO_RCU']

    id = UnicodeAttribute()
    age = NumberAttribute()
    gender = BooleanAttribute()
    osteoporosis = BooleanAttribute()
    work_activity_level = BooleanAttribute()
    tear_width = NumberAttribute()
    tear_retraction = NumberAttribute()
    full_thickness = BooleanAttribute()
    fatty_infiltration = BooleanAttribute()
    ip_address = UnicodeAttribute()
    date = UTCDateTimeAttribute()
    diebold_likelihood = NumberAttribute()
    kwon_likelihood = NumberAttribute()
    utah_likelihood = NumberAttribute()
    keener_likelihood = NumberAttribute()
    combined_likelihood = NumberAttribute()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def mint(self, ip_address):
        self.id = str(uuid.uuid4())
        self.ip_address = ip_address
        self.date = datetime.datetime.now()
Esempio n. 12
0
class EnemyRaceModel(BaseModel):
    class Meta:
        table_name = os.environ.get('EN_RACE_TABLE', 'ENEMYRACES')
        if 'ENV' in os.environ:
            host = 'http://localhost:8000'
        else:
            region = aws_region
            host = f'https://dynamodb.{aws_region}.amazonaws.com'

    en_race_id = NumberAttribute(hash_key=True, null=False)
    en_race_name = UnicodeAttribute(null=False)
    base_hp = NumberAttribute(default=0)
    can_block = BooleanAttribute(default=False)
    can_dodge = BooleanAttribute(default=False)

    block_pct = NumberAttribute(default=0.0)
    block_amt = NumberAttribute(default=0.0)
    dodge_pct = NumberAttribute(default=0.0)

    can_crit = BooleanAttribute(default=False)
    crit_chance = NumberAttribute(default=0)
    # base attack power
    base_ap = NumberAttribute(default=0)
    ap_mult = NumberAttribute(default=0)
    attack_speed = NumberAttribute(default=0)

    def save(self, conditional_operator=None, **expected_values):
        self.updated_at = datetime.utcnow()
        super(EnemyRaceModel, self).save()
Esempio n. 13
0
 def test_boolean_serialize(self):
     """
     BooleanAttribute.serialize
     """
     attr = BooleanAttribute()
     self.assertEqual(attr.serialize(True), json.dumps(1))
     self.assertEqual(attr.serialize(False), json.dumps(0))
     self.assertEqual(attr.serialize(None), None)
Esempio n. 14
0
 def test_boolean_serialize(self):
     """
     BooleanAttribute.serialize
     """
     attr = BooleanAttribute()
     assert attr.serialize(True) is True
     assert attr.serialize(False) is False
     assert attr.serialize(None) is None
Esempio n. 15
0
    class BAModel(Model):
        class Meta:
            table_name = 'migration_test_lba_to_ba_two_or_more_attrs'
            host = ddb_url

        id = UnicodeAttribute(hash_key=True)
        flag = BooleanAttribute(null=True)
        second_flag = BooleanAttribute(null=True)
Esempio n. 16
0
 def test_boolean_deserialize(self):
     """
     BooleanAttribute.deserialize
     """
     attr = BooleanAttribute()
     assert attr.deserialize('1') is True
     assert attr.deserialize('0') is True
     assert attr.deserialize(True) is True
     assert attr.deserialize(False) is False
Esempio n. 17
0
class OrganizationModel(GenericModel):
    class Meta(GenericMeta):
        table_name = os.getenv('TABLE_ORGANIZATIONS', 'd-organizations')

    columns = (
        ('id', UnicodeAttribute(hash_key=True)),
        # ('active', BooleanAttribute()),
        ('name', UnicodeAttribute()),
        ('classification', UnicodeAttribute(null=True)),
        ('logo', UnicodeAttribute(null=True)),
        ('description', UnicodeAttribute(null=True)),
        ('motto', UnicodeAttribute(null=True)),
        ('mission_statement', UnicodeAttribute(null=True)),
        ('founded', UnicodeAttribute(null=True)),
        ('ceo', UnicodeAttribute(null=True)),
        ('annual_net_income', NumberAttribute(null=True)),
        ('net_profit', NumberAttribute(null=True)),
        ('annual_sales_actual', NumberAttribute(null=True)),
        ('net_worth', NumberAttribute(null=True)),
        ('email', UnicodeAttribute()),
        ('address', UnicodeAttribute(null=True)),
        ('company_type', UnicodeAttribute(null=True)),
        ('duns_number', NumberAttribute(null=True)),
        ('num_employees_this_site', NumberAttribute(null=True)),
        ('num_employees_all_sites', NumberAttribute(null=True)),
        ('one_year_employee_growth', NumberAttribute(null=True)),
        ('company_website', UnicodeAttribute(null=True)),
        ('irs_ein', UnicodeAttribute(null=True)),
        ('latitude', NumberAttribute(null=True)),
        ('longitude', NumberAttribute(null=True)),
        ('location_type', UnicodeAttribute(null=True)),
        ('year_of_founding', NumberAttribute(null=True)),
        ('minority_or_women_owned', BooleanAttribute(null=True)),
        ('phone_number', UnicodeAttribute(null=True)),
        ('prescreen_score', UnicodeAttribute(null=True)),
        ('primary_industry', UnicodeAttribute(null=True)),
        ('primary_naics_code', UnicodeAttribute(null=True)),
        ('primary_sic_code', UnicodeAttribute(null=True)),
        ('subsidiary_status', BooleanAttribute(null=True)),
        ('tags', UnicodeSetAttribute(null=True)),
        ('examples', UnicodeSetAttribute(null=True)),
        ('sdg_keys', UnicodeSetAttribute(null=True)),
        ('similar_companies', UnicodeSetAttribute(null=True)),
    )
    for column in columns:
        locals()[column[0]] = column[1]

    @staticmethod
    def get_slug(name):
        """
        The slug is a URL-friendly identifier for an organization.

        Converts 'My Cool Company' into 'my-cool-company'
        """
        name = name.lower()
        name = re.sub(r'[\W_]$', '', name)
        return re.sub(r'[\W_]+', '-', name)
Esempio n. 18
0
class MyModel(Model):
    class Meta:
        table_name = "TestModel"
        host="http://localhost:8000"
    id = UnicodeAttribute(hash_key=True)
    #multi = MultiValue(null=True)
    multi1 = EnumAttribute(type_set={UnicodeAttribute(null=True), NumberAttribute(null=True)}, null=True)
    multi2 = EnumAttribute(type_set={BooleanAttribute(null=True), NumberAttribute(null=True)}, null=True)
    multi3 = EnumAttribute(type_set={BooleanAttribute(), UnicodeSetAttribute()}, null=True)
Esempio n. 19
0
    def test_boolean_attribute(self):
        """
        BooleanAttribute.default
        """
        attr = BooleanAttribute()
        assert attr is not None

        assert attr.attr_type == BOOLEAN
        attr = BooleanAttribute(default=True)
        assert attr.default is True
Esempio n. 20
0
    def test_boolean_attribute(self):
        """
        BooleanAttribute.default
        """
        attr = BooleanAttribute()
        self.assertIsNotNone(attr)

        self.assertEqual(attr.attr_type, NUMBER)
        attr = BooleanAttribute(default=True)
        self.assertEqual(attr.default, True)
Esempio n. 21
0
class LogMessage(Model):
    class Meta:
        table_name = 'hakkuu_message'

    guild = NumberAttribute(hash_key=True)
    snowflake = NumberAttribute(range_key=True)
    author = NumberAttribute()
    channel = NumberAttribute()
    revisions = ListAttribute(of=LogRevision)
    embeds = ListAttribute(of=LogEmbed)
    attachments = ListAttribute(of=LogAttachment)
    tts = BooleanAttribute(null=True)
    deleted = BooleanAttribute(null=True)
    deleted_by = BooleanAttribute(null=True)
Esempio n. 22
0
class Token(Model):
    class Meta:
        table_name = 'mm-token'

    token = UnicodeAttribute(hash_key=True)
    valid = BooleanAttribute(default=False)
    create_at = UTCDateTimeAttribute()
Esempio n. 23
0
class UserModel(Model):
    """
    A DynamoDB User
    """
    class Meta:
        table_name = "weibo-user"
        aws_access_key_id = config['aws_access_key_id']
        aws_secret_access_key = config['aws_secret_access_key']

    id  = UnicodeAttribute(hash_key=True)
    screen_name  = UnicodeAttribute(null=True)
    gender  = UnicodeAttribute(null=True)
    statuses_count  = NumberAttribute(null=True)
    followers_count  = NumberAttribute(null=True)
    follow_count  = NumberAttribute(null=True)
    registration_time = UnicodeAttribute(null=True)
    sunshine = UnicodeAttribute(null=True)
    birthday = UnicodeAttribute(null=True)
    location = UnicodeAttribute(null=True)
    education = UnicodeAttribute(null=True)
    company = UnicodeAttribute(null=True)
    description  = UnicodeAttribute(null=True)
    profile_url  = UnicodeAttribute(null=True)
    profile_image_url = UnicodeAttribute(null=True)
    avatar_hd  = UnicodeAttribute(null=True)
    urank  = NumberAttribute(null=True)
    mbrank  = NumberAttribute(null=True)
    verified  = BooleanAttribute(null=True)
    verified_type  = NumberAttribute(null=True)
    verified_reason  = UnicodeAttribute(null=True)
Esempio n. 24
0
class Page(Model):
    class Meta:
        table_name = DB
        region = 'us-west-2'

    site_id = UnicodeAttribute(hash_key=True)
    url = UnicodeAttribute(range_key=True)
    user = UnicodeAttribute()
    _type = UnicodeAttribute(attr_name="type", default='html')
    scraped = BooleanAttribute(default=False)
    doc_id = UnicodeAttribute(null=True)
    doc_title = UnicodeAttribute(null=True)
    obj_key = UnicodeAttribute(null=True)
    meta_obj_key = UnicodeAttribute(null=True)
    last_scraped_at = NumberAttribute(null=True)  # time-stamp
    user_site_index = UserSiteIndex()

    def to_dict(self):
        return dict(
            site_id=self.site_id,
            url=self.url,
            type=self._type,
            doc_id=self.doc_id,
            doc_title=self.doc_title,
            obj_key=self.obj_key,
            meta_obj_key=self.meta_obj_key,
            last_scraped_at=self.last_scraped_at

        )

    def to_json(self):
        return json.dumps(self.to_dict(), ensure_ascii=False)
Esempio n. 25
0
class Todo(Model):
    uid = UnicodeAttribute(hash_key=True, default=lambda: str(uuid.uuid4()))
    created = UTCDateTimeAttribute(default=datetime.datetime.now)
    started = BooleanAttribute(default=False)
    completed = BooleanAttribute(default=False)
    description = UnicodeAttribute()
    due_date = UTCDateTimeAttribute()

    class Meta:
        table_name = 'todos'
        region = Session().get_config_variable('region')

    @property
    def overdue(self):
        """ Returns a boolean indicating if the todo is overdue """
        return datetime.datetime.now(self.due_date.tzinfo) > self.due_date
Esempio n. 26
0
class LocationModel(BaseModel):
    class Meta:
        table_name = os.environ['DYNAMODB_TABLE']
        if 'ENV' in os.environ:
            host = f"http://localhost:8000"
        else:
            region = aws_region
            host = f'https://dynamodb.{aws_region}.amazonaws.com'

    id = UnicodeAttribute(default=str(uuid4()), hash_key=True)

    name = UnicodeAttribute()
    street_1 = UnicodeAttribute()
    street_2 = UnicodeAttribute(null=True)
    city = UnicodeAttribute()
    state = UnicodeAttribute()
    zip_code = UnicodeAttribute()
    country = UnicodeAttribute(default='US')
    type_id = NumberAttribute()
    loc_type = UnicodeAttribute(default='')
    is_deleted = BooleanAttribute(default=False)

    def save(self, conditional_operator=None, **excpected_values):
        self.loc_type = LocationTypes.get(self.type_id, 1)

        self.updated_at = datetime.utcnow()
        super(LocationModel, self).save()

    def __repr__(self):
        return f'<Site "id":{self.id}, "name":{self.name}, "type":{self.loc_type}/>'
class TodoModel(Model):
    class Meta:
        read_capacity_units = 1
        write_capacity_units = 1
        region = 'localhost'
        host = 'http://localhost:8000'

    todo_id = UnicodeAttribute(hash_key=True, null=False)
    text = UnicodeAttribute(null=False)
    checked = BooleanAttribute(null=False, default=False)
    created_at = UTCDateTimeAttribute(null=False, default=datetime.utcnow)
    updated_at = UTCDateTimeAttribute(null=False)

    def save(self, conditional_operator=None, **expected_values):
        self.updated_at = datetime.utcnow()
        super().save()

    def __iter__(self):
        for name, attr in self._get_attributes().items():
            yield name, attr.serialize(getattr(self, name))

    @staticmethod
    def setup_model(model, region, table_name, is_remote=False):
        model.Meta.table_name = table_name
        model.Meta.region = region
        if is_remote:
            model.Meta.host = 'https://dynamodb.{0}.amazonaws.com'.format(region)
Esempio n. 28
0
class BoatModel(Model):
    class Meta:
        table_name = os.environ['DYNAMODB_TABLE']
        if 'ENV' in os.environ:
            host = 'http://localhost:8000'
        else:
            region = 'us-east-1'

    id = UnicodeAttribute(hash_key=True, null=False)
    name = UnicodeAttribute(null=False)
    type = UnicodeAttribute(hash_key=False, null=False)
    length = NumberAttribute(hash_key=False,
                             range_key=False,
                             null=None,
                             default=0)
    at_sea = BooleanAttribute(hash_key=False,
                              range_key=False,
                              null=None,
                              default=True)
    e_type = EntityType()
    entity_type = UnicodeAttribute(default='boat')

    def save(self, conditional_operator=None, **expected_values):
        self.updatedAt = datetime.now()
        super(BoatModel, self).save()

    def __iter__(self):
        for name, attr in self._get_attributes().items():
            yield name, attr.serialize(getattr(self, name))
Esempio n. 29
0
class VPCModel(object):
    VpcId = UnicodeAttribute()
    State = UnicodeAttribute()
    CidrBlock = UnicodeAttribute()
    Tags = ListAttribute()
    IsDefault = BooleanAttribute()
    Name = UnicodeAttribute(null=True)
Esempio n. 30
0
class AgendaModel(Model):
    class Meta:
        table_name = os.environ['DYNAMODB_TABLE']
        if 'ENV' in os.environ:
            host = 'http://localhost:8000'
        else:
            region = 'us-west-2'
            host = 'https://dynamodb.us-west-2.amazonaws.com'

    agenda_id = UnicodeAttribute(hash_key=True, null=False)
    paciente_id = UnicodeAttribute(range_key=True, null=False)

    tipo_evento = UnicodeAttribute(null=False)
    fecha_evento = UnicodeAttribute(null=False)
    

    status = BooleanAttribute(null=False, default=True)

    create_at = UTCDateTimeAttribute(null=False, default=datetime.now())
    updated_at = UTCDateTimeAttribute(null=False)

    def save(self, conditional_operator=None, **expected_values):
        self.updated_at = datetime.now()
        super(AgendaModel, self).save()

    def __iter__(self):
        for name, attr in self._get_attributes().items():
            yield name, attr.serialize(getattr(self, name))
Esempio n. 31
0
class MensajeModel(Model):
    class Meta:
        table_name = os.environ['DYNAMODB_MENSAJE']
        if 'ENV' in os.environ:
            host = 'http://localhost:8000'
        else:
            region = 'us-west-2'
            host = 'https://dynamodb.us-west-2.amazonaws.com'

    mensaje_id = UnicodeAttribute(hash_key=True, null=False)

    nombre = UnicodeAttribute(null=False)
    correo = UnicodeAttribute(null=False)
    asunto = UnicodeAttribute(null=False)
    cuerpo = UnicodeAttribute(null=False)

    leido = BooleanAttribute(null=False, default=False)

    create_at = UTCDateTimeAttribute(null=False, default=datetime.now())
    updated_at = UTCDateTimeAttribute(null=False)

    def save(self, conditional_operator=None, **expected_values):
        self.updated_at = datetime.now()
        super(MensajeModel, self).save()

    def __iter__(self):
        for name, attr in self._get_attributes().items():
            yield name, attr.serialize(getattr(self, name))
Esempio n. 32
0
class worker_config(Model):
    class Meta:
        table_name = ''
        region = ''

    workerID = UnicodeAttribute(hash_key=True)
    lastIndex = NumberAttribute()
    lastUpdateTime = NumberAttribute()
    isActive = BooleanAttribute()
    pipelinePort = UnicodeAttribute()

    @staticmethod
    def connect_to_dynamodb(table_name, region, host=None):
        logger.info("Connecting to DynamoDB | host={} | table={}".format(
            host, table_name))

        try:
            worker_config.Meta.table_name = table_name
            worker_config.Meta.region = region
            if host:
                worker_config.Meta.host = host
            return True
        except (PynamoDBConnectionError, TableDoesNotExist, Exception) as exp:
            logger.exception(
                "Failed to connect to DynamoDB | Host={} | Table={}".format(
                    host, table_name))
            return False

    @staticmethod
    def get_record(worker_id):
        try:
            record = worker_config.get(hash_key=worker_id)
            return record
        except DoesNotExist:
            return 0