Exemplo n.º 1
0
class Price(ModelMixin, db.EmbeddedDocument):

    provider = db.EnumField(Providers, required=True)
    price = db.FloatField(required=True)
    creation_date = db.DateTimeField(required=True, default=datetime.now)
    update_date = db.DateTimeField(requured=True, default=datetime.now)

    meta = {"indexes": ["price"]}
Exemplo n.º 2
0
class List(ModelMixin, db.Document):
    user = db.ReferenceField("User", required=True)
    name = db.StringField(required=True)
    description = db.StringField()
    slug = db.StringField(required=True)
    creation_date = db.DateTimeField(required=True, default=datetime.now)
    update_date = db.DateTimeField(requured=True, default=datetime.now)

    item_containers = db.EmbeddedDocumentListField(ItemContainer)

    @classmethod
    def generate_slug(cls, user: str, name: str) -> str:
        return slugify(name) or "list"
Exemplo n.º 3
0
class User(ModelMixin, db.Document):

    steam_id = db.StringField(required=True, unique=True)
    username = db.StringField(required=True)
    creation_date = db.DateTimeField(required=True, default=datetime.now)
    last_login = db.DateTimeField(required=True, default=datetime.now)

    meta = {"indexes": ["steam_id"]}

    @property
    def jwt_identity(self):
        return str(self.id)

    def set_last_login(self):
        self.last_login = datetime.now()
        self.save()
Exemplo n.º 4
0
class Photo(db.EmbeddedDocument):
    """
    фотография
    """
    file = db.StringField(verbose_name='Название файла')
    created = db.DateTimeField(verbose_name='Дата и время создания')
    device = db.StringField(verbose_name='Устройство')
Exemplo n.º 5
0
class Redirect(ModelMixin, db.Document):

    skin = db.ReferenceField(Skin, required=True)
    provider = db.EnumField(Providers, required=True)

    tracker = db.StringField()

    creation_date = db.DateTimeField(required=True, default=datetime.now)

    meta = {"indexes": ["creation_date", "tracker"]}
Exemplo n.º 6
0
class Album(db.Document):
    """
    альбомы с фотографиями пользователя
    """
    user = db.ReferenceField(User, verbose_name='Пользователь')
    name = db.StringField(verbose_name='Название альбома')
    slug = db.StringField(verbose_name='Slug альбома')
    created = db.DateTimeField(default=datetime.now,
                               verbose_name='Дата и время создания')
    description = db.StringField(verbose_name='Описание альбома')
    photos = db.SortedListField(db.EmbeddedDocumentField(Photo),
                                verbose_name='Фотографии')

    def save(self):
        self.slug = slugify(self.name, to_lower=True)
        return super(Album, self).save(self)

    meta = {'indexes': [{'fields': ('user', 'name', 'slug'), 'unique': True}]}
Exemplo n.º 7
0
class Skin(ModelMixin, db.Document):

    app = db.EnumField(Apps, required=True)
    slug = db.StringField(required=True)

    name = db.StringField(required=True)
    image_url = db.URLField()
    creation_date = db.DateTimeField(required=True, default=datetime.now)

    prices = db.EmbeddedDocumentListField(Price)

    meta = {"indexes": ["app", "slug", "name"], "allow_inheritance": True}

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.slug = self.generate_slug()

    def __repr__(self) -> str:
        return f"<Skin id={self.id}, name={self.name}>"

    def __str__(self) -> str:
        return f"<Skin {self.id} - {self.name}>"

    @property
    def fullname(self) -> str:
        return self.name

    def generate_slug(self) -> str:
        return slugify(self.name)

    def add_price(self, provider: Providers, price: float):
        now = datetime.now()
        for price_ in self.prices:
            # very weird issue here when comparing enums directly instead of names
            # the result is sometimes False in a deamonized run when the values are actually the same...
            if price_.provider.name == provider.name:
                price_.price = price
                price_.update_date = now
                break
        else:
            self.prices.append(Price(price=price, provider=provider))
        self.save()
Exemplo n.º 8
0
class Contact(ModelMixin, db.Document):

    name = db.StringField()
    email = db.EmailField()
    message = db.StringField(required=True)
    user = db.ReferenceField(User)

    creation_date = db.DateTimeField(required=True, default=datetime.now)

    meta = {"indexes": ["creation_date"]}

    def send(self):
        msg = EmailMessage()
        msg.set_content(f'From: "{self.name}"<{self.email}>\n\n{self.message}')
        msg["Subject"] = "[LionSkins] Contact"
        msg["From"] = os.environ["CONTACT_FROM"]
        msg["To"] = os.environ["CONTACT_TO"]

        with smtplib.SMTP(os.environ["SMTP_HOSTNAME"],
                          os.environ["SMTP_PORT"]) as smtp:
            smtp.starttls()
            smtp.login(os.environ["SMTP_LOGIN"], os.environ["SMTP_PASSWORD"])
            smtp.send_message(msg)
Exemplo n.º 9
0
class Item(ModelMixin, db.EmbeddedDocument):
    skin = db.ReferenceField("Skin", required=True)
    creation_date = db.DateTimeField(required=True, default=datetime.now)