Пример #1
0
class SourceVideo(db.Document):
    source_url = db.StringField(required=True)
    reminiz_video = db.ReferenceField(Video, reverse_delete_rule=db.NULLIFY)
    offsets = db.DynamicField()
    hash = db.StringField(required=True)
    # Mongoengine will otherwise name the collection source_videos
    meta = {'collection': 'sourcevideo'}
Пример #2
0
class Photo(db.EmbeddedDocument):
    """
    фотография
    """
    file = db.StringField(verbose_name='Название файла')
    created = db.DateTimeField(verbose_name='Дата и время создания')
    device = db.StringField(verbose_name='Устройство')
Пример #3
0
class User(db.Document, UserMixin):
    """
    модель пользователя
    """
    email = db.StringField(max_length=50, verbose_name='E-mail', unique=True)
    password = db.StringField(verbose_name='Пароль')
    active = db.BooleanField(default=True)
    roles = db.ListField(db.ReferenceField(Role), default=[])

    @classmethod
    def authenticate(cls, email, password):
        user = cls.objects(email=email).first()

        if not bcrypt.verify(password, user.password):
            raise Exception('Invalid password')
        return user

    def save(self):
        if not self.id:
            self.password = bcrypt.hash(self.password)
            return super(User, self).save(self)
        else:
            return super(User, self).update(email=self.email,
                                            active=self.active,
                                            roles=self.roles)
Пример #4
0
class Role(db.Document, RoleMixin):
    """
    класс для фласк секьюрити
    """
    name = db.StringField(max_length=150,
                          verbose_name='Название роли',
                          unique=True)
    description = db.StringField(verbose_name='Описание')

    def __unicode__(self):
        return self.name
Пример #5
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"
Пример #6
0
class Entity(db.Document):
    """The corresponding collection is named 'entity' """
    name = db.StringField(required=True)
    image_url = db.StringField()
    # Social networks accounts
    accounts = db.DictField()

    infos = db.DynamicField()
    links = db.DictField()

    def __unicode__(self):
        return self.name

    meta = {'indexes': ['name']}
Пример #7
0
class Users(db.Document):
    user_name = db.StringField(required=True)
    password = db.StringField(required=True)
    email = db.EmailField(required=True, unique=True)

    def generate_pw_hash(self):
        self.password = generate_password_hash(password=self.password).decode('utf-8')

    # Use documentation from BCrypt for password hashing
    generate_pw_hash.__doc__ = generate_password_hash.__doc__

    def check_pw_hash(self, password: str) -> bool:
        return check_password_hash(pw_hash=self.password, password=password)

    # Use documentation from BCrypt for password hashing
    check_pw_hash.__doc__ = check_password_hash.__doc__
Пример #8
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()
Пример #9
0
class Blogs(db.Document):
    username = db.StringField(required=True)
    title = db.StringField(required=True)
    rating = db.IntField()
    content = db.StringField(required=True)
    imageURL = db.StringField()

    def to_json(self):
        return {
            "id": str(self.pk),
            "username": self.username,
            "title": self.title,
            "rating": self.rating,
            "content": self.content,
            "imageURL": self.imageURL,
            "status": 'success'
        }
Пример #10
0
class Video(db.Document):
    title = db.StringField(required=True, null=False)
    tracks = db.EmbeddedDocumentListField(Track)
    features = db.DynamicField()
    cuts = db.DynamicField()

    def __unicode__(self):
        return self.title
Пример #11
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}]}
Пример #12
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"]}
Пример #13
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()
Пример #14
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)
Пример #15
0
class Recipe(db.Document):
    url = db.StringField(required=True, unique=True)
    username = db.StringField(required=True)
    label = db.StringField(required=True)
    image = db.StringField(required=True)
Пример #16
0
class Skin(BaseSkin):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.app = Apps.csgo

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

    type = db.EnumField(Types)
    weapon = db.EnumField(Weapons)

    stat_trak = db.BooleanField()
    souvenir = db.BooleanField()
    quality = QualityField()
    rarity = db.EnumField(Rarities)
    market_hash_name = db.StringField()

    collection_ = db.EnumField(Collections, db_field="collection")
    description = db.DictField()

    meta = {
        "indexes": [
            "type",
            "weapon",
            "stat_trak",
            "souvenir",
            "quality",
            "rarity",
            "collection_",
            "market_hash_name",
            "$market_hash_name",
        ]
    }

    def save(self, *args, **kwargs):
        self.market_hash_name = self._get_market_hash_name()
        return super().save(*args, **kwargs)

    @property
    def fullname(self):
        return self.market_hash_name

    def _get_market_hash_name(self) -> str:
        res = self._get_partial_market_hash_name()
        if self.quality and self.quality != Qualities.vanilla:
            res += " (" + self.quality.value + ")"
        return res

    def _get_partial_market_hash_name(self) -> str:
        if self.type == Types.agents or self.type == Types.pins:
            return self.name
        elif self.type == Types.music_kits:
            prefix = "Music Kit"
            if self.stat_trak:
                prefix = "StatTrak™ " + prefix
            return f"{prefix} | {self.name}"
        elif self.type == Types.graffitis:
            return f"Sealed Graffiti | {self.name}"
        elif self.type == Types.stickers:
            return f"Sticker | {self.name}"
        elif self.type == Types.patches:
            return f"Patch | {self.name}"

        res = ""
        if self.weapon.category == WeaponCategories.knives:
            res += "★ "
        if self.souvenir:
            res += "Souvenir "
        elif self.stat_trak:
            res += "StatTrak™ "
        res += self.weapon.value
        if self.quality != Qualities.vanilla:
            res += " | " + self.name
        return res