Example #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'}
Example #2
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)
Example #3
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"]}
Example #4
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"
Example #5
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}]}
Example #6
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)
Example #7
0
class Track(db.EmbeddedDocument):
    start = db.FloatField(required=True, null=False)
    end = db.FloatField()
    boxes = db.EmbeddedDocumentListField(Box, required=True)
    entity = db.ReferenceField(Entity)
Example #8
0
class Item(ModelMixin, db.EmbeddedDocument):
    skin = db.ReferenceField("Skin", required=True)
    creation_date = db.DateTimeField(required=True, default=datetime.now)