Пример #1
0
class Garage(appier.Model):

    identifier = appier.field(
        type = int,
        index = True,
        increment = True,
        default = True
    )

    identifier_safe = appier.field(
        type = int,
        index = True,
        increment = True,
        safe = True
    )

    name = appier.field()

    address = appier.field(
        type = appier.reference(
            "Address",
            name = "identifier"
        ),
        eager = True
    )
Пример #2
0
class EGroup(graphic.EGraphic):

    SIZE_ALIAS = dict(thumbnail=("70", ), large=("1000", ))

    name = appier.field()

    order = appier.field(type=int)
Пример #3
0
class DiagBase(appier.Model):

    id = appier.field(
        type = int,
        index = "all",
        increment = True,
        safe = True,
        description = "ID",
    )

    timestamp = appier.field(
        type = int,
        index = "all",
        safe = True,
        immutable = True,
        meta = "datetime"
    )

    def pre_create(self):
        appier.Model.pre_create(self)

        self.timestamp = time.time()

    @property
    def timestamp_d(self):
        if not self.timestamp: return self.timestamp
        return datetime.datetime.fromtimestamp(self.timestamp)
Пример #4
0
class Day(appier.Model):

    year = appier.field(
        type = int,
        index = "hashed"
    )

    month = appier.field(
        type = int,
        index = "hashed"
    )

    day = appier.field(
        type = int,
        index = "hashed",
        immutable = True
    )

    hour = appier.field(
        type = int,
        index = "hashed",
        immutable = True
    )

    timestamp = appier.field(
        type = int,
        index = "all",
        immutable = True
    )

    @classmethod
    def is_abstract(cls):
        return True
Пример #5
0
class Association(base.PushiBase):

    user_id = appier.field(
        index = True,
        description = "User ID"
    )

    mid = appier.field(
        index = True,
        description = "MID"
    )

    @classmethod
    def validate(cls):
        return super(Association, cls).validate() + [
            appier.not_null("user_id"),
            appier.not_empty("user_id"),

            appier.not_null("mid"),
            appier.not_empty("mid")
        ]

    @classmethod
    def list_names(cls):
        return ["user_id", "mid", "created"]
Пример #6
0
class EWishlistLine(base.EBase):

    quantity = appier.field(type=float)

    total = appier.field(type=float)

    product = appier.field(type=appier.reference("EProduct", name="id"))
Пример #7
0
class ECreditCard(base.EBase):

    card_name = appier.field()

    card_number = appier.field()

    expiration_year = appier.field(type=int)

    expiration_month = appier.field(type=int)

    security_code = appier.field()

    @classmethod
    def validate(cls):
        return super(ECreditCard, cls).validate() + [
            appier.not_null("card_name"),
            appier.not_empty("card_name"),
            appier.not_null("card_number"),
            appier.not_empty("card_number"),
            appier.not_null("expiration_month"),
            appier.gte("expiration_month", 1),
            appier.lte("expiration_month", 12),
            appier.not_null("expiration_year"),
            appier.not_null("security_code"),
            appier.not_empty("security_code")
        ]

    @classmethod
    def payment_types(cls):
        return ("visa", "mastercard", "american_express")
Пример #8
0
class Person(appier.Model):

    identifier = appier.field(type=int,
                              index=True,
                              increment=True,
                              default=True)

    name = appier.field()
Пример #9
0
class Web(base.PushiBase):

    url = appier.field(
        index = True,
        description = "URL",
        meta = "url"
    )

    event = appier.field(
        index = True
    )

    @classmethod
    def validate(cls):
        return super(Web, cls).validate() + [
            appier.not_null("url"),
            appier.not_empty("url"),

            appier.not_null("event"),
            appier.not_empty("event")
        ]

    @classmethod
    def list_names(cls):
        return ["url", "event"]

    def pre_update(self):
        base.PushiBase.pre_update(self)
        previous = self.__class__.get(id = self.id)
        self.state and self.state.web_handler.remove(
            previous.app_id,
            previous.url,
            previous.event
        )

    def post_create(self):
        base.PushiBase.pre_create(self)
        self.state and self.state.web_handler.add(
            self.app_id,
            self.url,
            self.event
        )

    def post_update(self):
        base.PushiBase.post_update(self)
        self.state and self.state.web_handler.add(
            self.app_id,
            self.url,
            self.event
        )

    def post_delete(self):
        base.PushiBase.post_delete(self)
        self.state and self.state.web_handler.remove(
            self.app_id,
            self.url,
            self.event
        )
Пример #10
0
class Person(appier.Model):

    identifier = appier.field(type=int,
                              index=True,
                              increment=True,
                              default=True)

    identifier_safe = appier.field(type=int,
                                   index=True,
                                   increment=True,
                                   safe=True)

    name = appier.field()

    age = appier.field(type=int)

    info = appier.field(type=dict)

    father = appier.field(
        type=appier.reference("Person", name="identifier", dumpall=True))

    brother = appier.field(type=appier.reference("Person", name="identifier"))

    car = appier.field(type=appier.reference("Car", name="identifier"),
                       eager=True)

    cats = appier.field(type=appier.references("Cat", name="identifier"))

    @classmethod
    def validate(cls):
        return super(Person, cls).validate() + [
            appier.not_null("name"),
            appier.not_empty("name"),
            appier.not_duplicate("name", cls._name())
        ]
Пример #11
0
class EPaymentMethod(base.EBase):

    type = appier.field()

    name = appier.field()

    @classmethod
    def ensure_method(cls, payment_method):
        pass

    def is_credit_card(self):
        return self.type == "credit_card"
Пример #12
0
class CounterFact(fact.Fact):
    """
    Counter fact that handles the cross operation counting, meaning
    that whenever there's a new cross action the counter value
    should be incremented.
    """

    counter = appier.field(
        type=int,
        initial=0,
        observations="""The integer counter value that should
        be incremented for every single interaction""")

    action = appier.field(index="hashed", immutable=True)
    """ The name of the action associated with the current counter
    should be as descriptive as possible """
    @classmethod
    def increment_s(cls,
                    app,
                    adapters=[],
                    current=None,
                    action="cross",
                    *args,
                    **kwargs):
        current = current or datetime.datetime.utcnow()

        fact = cls.get(app=app,
                       action=action,
                       year=current.year,
                       month=current.month,
                       day=current.day,
                       hour=current.hour,
                       raise_e=False)
        if not fact:
            fact = cls(app=app,
                       action=action,
                       year=current.year,
                       month=current.month,
                       day=current.day,
                       hour=current.hour)

        if not hasattr(fact, "counter"): fact.counter = 0
        fact.counter = fact.counter + 1
        fact.save()

        info = dict(action=action, count=fact.counter, app=app)

        for adapter in adapters:
            method = getattr(adapter, action)
            method(info=info, app=app, **kwargs)

        return info
Пример #13
0
class Cat(appier.Model):

    identifier = appier.field(type=int,
                              index=True,
                              increment=True,
                              default=True)

    identifier_safe = appier.field(type=int,
                                   index=True,
                                   increment=True,
                                   safe=True)

    name = appier.field()
Пример #14
0
class Address(appier.Model):

    identifier = appier.field(type=int,
                              index=True,
                              increment=True,
                              default=True)

    identifier_safe = appier.field(type=int,
                                   index=True,
                                   increment=True,
                                   safe=True)

    street = appier.field()
Пример #15
0
class EWishlist(base.EBase):

    currency = appier.field()

    total = appier.field(
        type = float
    )

    lines = appier.field(
        type = appier.references(
            "EWishlistLine",
            name = "id"
        )
    )
Пример #16
0
class ECountry(base.EBase):

    name = appier.field()

    country_code = appier.field()

    currency_code = appier.field()

    locale = appier.field()

    def get_currency(self):
        return currency.ECurrency(
            name = self.currency_code,
            currency_code = self.currency_code
        )
Пример #17
0
class Cat(appier.Model):

    identifier = appier.field(type=int,
                              index=True,
                              increment=True,
                              default=True)

    identifier_safe = appier.field(type=int,
                                   index=True,
                                   increment=True,
                                   safe=True)

    name = appier.field()

    friend = appier.field(type=appier.reference("Cat", name="identifier"))
Пример #18
0
class BDVoucher(voucher.EVoucher, bd_common.BDCommon):

    key = appier.field()

    @classmethod
    def _ident_name(cls):
        return "key"
Пример #19
0
class BDReferral(referral.EReferral, bd_common.BDCommon):

    name = appier.field()

    @classmethod
    def _ident_name(cls):
        return "name"
Пример #20
0
class APN(base.PushiBase):

    token = appier.field(index=True)

    event = appier.field(index=True)

    @classmethod
    def validate(cls):
        return super(APN, cls).validate() + [
            appier.not_null("token"),
            appier.not_empty("token"),
            appier.not_null("event"),
            appier.not_empty("event")
        ]

    @classmethod
    def list_names(cls):
        return ["token", "event"]

    @classmethod
    def _underscore(cls, plural=True):
        return "apns" if plural else "apn"

    @classmethod
    def _readable(cls, plural=False):
        return "APNs" if plural else "APN"

    def pre_update(self):
        base.PushiBase.pre_update(self)
        previous = self.__class__.get(id=self.id)
        self.state and self.state.apn_handler.remove(
            previous.app_id, previous.token, previous.event)

    def post_create(self):
        base.PushiBase.pre_create(self)
        self.state and self.state.apn_handler.add(self.app_id, self.token,
                                                  self.event)

    def post_update(self):
        base.PushiBase.post_update(self)
        self.state and self.state.apn_handler.add(self.app_id, self.token,
                                                  self.event)

    def post_delete(self):
        base.PushiBase.post_delete(self)
        self.state and self.state.apn_handler.remove(self.app_id, self.token,
                                                     self.event)
Пример #21
0
class EBag(base.EBase):

    currency = appier.field()

    total = appier.field(
        type = float
    )

    lines = appier.field(
        type = appier.references(
            "EBagLine",
            name = "id"
        )
    )

    @property
    def quantity(self):
        return sum([line.quantity for line in self.lines])
Пример #22
0
class Car(appier.Model):

    identifier = appier.field(
        type = int,
        index = True,
        increment = True,
        default = True
    )

    identifier_safe = appier.field(
        type = int,
        index = True,
        increment = True,
        safe = True
    )

    name = appier.field()

    brand = appier.field()

    variant = appier.field()

    garage = appier.field(
        type = appier.reference(
            "Garage",
            name = "identifier"
        ),
        eager = True
    )
Пример #23
0
class CrosslineBase(appier_extras.admin.Base):

    app = appier.field(index="hashed")

    @classmethod
    def is_abstract(cls):
        return True

    @appier.operation(name="Set App", parameters=(("App", "app", str), ))
    def set_app_s(self, app=None):
        app = app or None
        self.app = app
        self.save()
Пример #24
0
class Action(base.CrosslineBase):

    timestamp = appier.field(
        type = int,
        index = "all",
        safe = True,
        immutable = True,
        meta = "datetime",
        observations = """The snapshot timestamp for when
        the current action has occurred"""
    )

    info = appier.field(
        type = dict,
        immutable = True,
        observations = """Extra information associated with
        the action that can be used as a storage media"""
    )

    @classmethod
    def list_names(cls):
        return ["timestamp", "app"]

    @classmethod
    def order_name(cls):
        return ["id", -1]

    @classmethod
    def is_abstract(cls):
        return True

    @classmethod
    def get_by_entity(cls, entity, *args, **kwargs):
        return cls.get_e(entity = entity, *args, **kwargs)

    def pre_create(self):
        base.CrosslineBase.pre_create(self)
        if not hasattr(self, "timestamp") or not self.timestamp:
            self.timestamp = int(time.time())
Пример #25
0
class Subscription(base.PushiBase):

    user_id = appier.field(index=True, description="User ID")

    event = appier.field(index=True)

    @classmethod
    def validate(cls):
        return super(Subscription, cls).validate() + [
            appier.not_null("user_id"),
            appier.not_empty("user_id"),
            appier.not_null("event"),
            appier.not_empty("event")
        ]

    @classmethod
    def list_names(cls):
        return ["user_id", "event"]

    def pre_update(self):
        base.PushiBase.pre_update(self)
        previous = self.__class__.get(id=self.id)
        self.state and self.state.remove_alias(
            previous.app_key, "personal-" + previous.user_id, previous.event)

    def post_create(self):
        base.PushiBase.pre_create(self)
        self.state and self.state.add_alias(
            self.app_key, "personal-" + self.user_id, self.event)

    def post_update(self):
        base.PushiBase.post_update(self)
        self.state and self.state.add_alias(
            self.app_key, "personal-" + self.user_id, self.event)

    def post_delete(self):
        base.PushiBase.post_delete(self)
        self.state and self.state.remove_alias(
            self.app_key, "personal-" + self.user_id, self.event)
Пример #26
0
class App(base.PushiBase):

    name = appier.field(index=True, default=True)

    ident = appier.field(index=True, safe=True, immutable=True)

    key = appier.field(index=True, safe=True, immutable=True)

    secret = appier.field(index=True, safe=True, immutable=True)

    apn_sandbox = appier.field(
        type=bool,
        description="APN Sandbox",
        observations="""Indicates if the APN context is sandbox or
        production related, should be in sync with Apple Development configuration"""
    )

    apn_key = appier.field(
        meta="longtext",
        description="APN Key",
        observations="""The private key in PEM format to be used
        in messages to be sent using APN (Apple Push Notifications)""")

    apn_cer = appier.field(
        meta="longtext",
        description="APN Cer",
        observations="""The certificate in PEM format to be used
        in messages to be sent using APN (Apple Push Notifications)""")

    @classmethod
    def validate(cls):
        return super(App, cls).validate() + [
            appier.not_null("name"),
            appier.not_empty("name"),
            appier.not_duplicate("name", cls._name())
        ]

    @classmethod
    def list_names(cls):
        return ["name", "ident", "apn_sandbox"]

    def pre_create(self):
        base.PushiBase.pre_create(self)

        ident = appier.legacy.bytes(str(uuid.uuid4()))
        key = appier.legacy.bytes(str((uuid.uuid4())))
        secret = appier.legacy.bytes(str(uuid.uuid4()))

        self.ident = hashlib.sha256(ident).hexdigest()
        self.key = hashlib.sha256(key).hexdigest()
        self.secret = hashlib.sha256(secret).hexdigest()

        self.instance = self.ident
Пример #27
0
class BalanceFact(fact.Fact):

    btc = appier.field(type=float, description="BTC")

    eth = appier.field(type=float, description="ETH")

    usd = appier.field(type=float, description="USD")

    eur = appier.field(type=float, description="EUR")

    @classmethod
    def list_names(cls):
        return super(BalanceFact, cls).list_names() + ["btc", "eth", "usd"]

    @classmethod
    def from_remote(cls):
        instance = super(BalanceFact, cls).from_remote()
        balance = cls.get_balance_g()
        instance.btc = balance["BTC"]
        instance.eth = balance["ETH"]
        instance.usd = balance["USD"]
        instance.eur = balance["EUR"]
        return instance
Пример #28
0
class EnterAction(action.Action):

    entity = appier.field(
        type = appier.reference(
            entity.Entity,
            name = "identifier"
        ),
        observations = """The entity that has just entered
        a certain area of coverage"""
    )

    @classmethod
    def list_names(cls):
        return ["timestamp", "entity", "app"]

    @classmethod
    def latest(cls, identifier):
        return cls.get(
            entity = identifier,
            sort = [("timestamp", -1), ("id", -1)],
            raise_e = False
        )

    @classmethod
    def last(cls, identifier, limit = 2):
        return cls.find(
            entity = identifier,
            sort = [("timestamp", -1), ("id", -1)],
            limit = limit
        )

    @classmethod
    def enter_s(
        cls,
        identifier,
        timestamp = None,
        info = None,
        key = None,
        verify = False
    ):
        info = info or dict()
        if verify: entity.Entity.verify_g(identifier, key)
        enter = cls(
            entity = identifier,
            timestamp = timestamp,
            info = info
        )
        enter.save()
        return enter
Пример #29
0
class BDAddress(address.EAddress, bd_common.BDCommon):

    key = appier.field()

    @bd_common.handle_error
    def create_s(self):
        api = self._get_api()
        self.approve(type="new")
        address = self.unwrap(default=True)
        address = api.create_address(address)
        address = BDAddress(address)
        return address

    @classmethod
    def _ident_name(cls):
        return "key"
Пример #30
0
class SomeModel(base.RipeSkeletonBase):

    field = appier.field(
        index = True,
        observations = """This is a description of the field"""
    )

    @classmethod
    def validate(cls):
        return super(SomeModel, cls).validate() + [
            appier.not_null("field"),
            appier.not_empty("field")
        ]

    @classmethod
    def list_names(cls):
        return ["field"]