Exemplo n.º 1
0
class EmployeeMessages(Document):
    email_to = fields.ListField(fields.EmailField())
    name_to = fields.ListField(fields.StringField())
    email_from = fields.EmailField()
    name_from = fields.StringField()
    message = fields.StringField()
    file = fields.StringField()
Exemplo n.º 2
0
    class UserTest(db.DynamicDocument):
        username = fields.StringField(primary_key=True)
        email = fields.EmailField()
        password = fields.StringField()

        def to_json(self):
            return {'username': self.username, 'email': self.email}
Exemplo n.º 3
0
class User(UserMixin, Document):

    username = fields.StringField(unique=True, required=True)

    email = fields.EmailField(required=False)

    password = fields.StringField(required=True)

    api_key = fields.StringField()

    active = fields.BooleanField(default=True)

    slug = fields.StringField(unique=True, required=True)

    def _clean_api_key(self):
        if self.api_key:
            exist = User.objects(api_key=self.api_key,
                                 username__ne=self.username).first()
            if exist:
                message = _(
                    u"Conflict with api_key[%s]. Already exist") % value
                raise NotUniqueError(message)

    @classmethod
    def create_user(cls,
                    username=None,
                    password=None,
                    api_key=None,
                    update_if_exist=False):
        user = cls.objects(username__exact=username).first()

        if user:
            if not update_if_exist:
                return user

        user = user or cls(username=username)
        user.set_password(password)
        user.api_key = api_key
        return user.save()

    def clean(self):
        Document.clean(self)
        validators.clean_email_or_username(self.username,
                                           field_name="username",
                                           error_class=ValidationError)
        if self.api_key:
            self._clean_api_key()

    def save(self, **kwargs):
        self.slug = ModelSlug.unique_slug(User)(self.username)
        return Document.save(self, **kwargs)

    def __unicode__(self):
        return self.username

    meta = {
        'collection': 'user',
        'ordering': ['username'],
        'indexes': ['username', 'slug'],
    }
Exemplo n.º 4
0
class AdministradorField(EmbeddedDocument):
    NOMBRE = fields.StringField(required=True)
    TELEFONO = fields.StringField(required=True)
    CORREO = fields.EmailField()
    USUARIO_ID = fields.LazyReferenceField(Usuarios,
                                           passthrough=False,
                                           dbref=False)
Exemplo n.º 5
0
class User(Document):
    meta = {
        "indexes": [
            'email',
        ]
    }

    id = fields.UUIDField(primary_key=True, binary=False)
    username = fields.StringField(required=True, max_length=50)
    email = fields.EmailField(required=True, unique=True)
    password = fields.StringField(required=True)
    role = fields.StringField(default="user")
    active = fields.BooleanField(default=True)
    created_at = fields.DateTimeField(default=datetime.datetime.utcnow())
    modified_at = fields.DateTimeField(default=datetime.datetime.utcnow())

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

    def dict(self):
        return {
            'id': self.get_id(),
            'username': self.username,
            'email': self.email,
            'role': self.role,
            'active': self.active
        }
Exemplo n.º 6
0
class User(Document):
    """User Document"""
    full_name = fields.StringField(required=True)
    email = fields.EmailField(required=True, unique=True)
    created_at = fields.DateTimeField(default=datetime.now())

    meta = {'collection': 'Users'}
Exemplo n.º 7
0
class URL(BaseDocument):
    """Store All Urls"""

    #User.email - no direct reference
    author = fields.EmailField(required=True)

    #Original URL before convert
    origin = fields.StringField(required=True, unique=True)

    #TODO: ip_address author ?

    #Convert URL
    target = fields.StringField(required=True, unique=True)

    #status = fields.IntField(choices=constants.STATUS,
    #                         default=constants.STATUS_DRAFT,
    #                         required=True)

    #Original url Verified by robot
    last_verified = fields.DateTimeField()

    def save(self, **kwargs):
        self.target = encode_url(self.origin)
        return super().save(**kwargs)

    def __unicode__(self):
        return self.origin

    meta = {
        'collection': 'url',
        'indexes': ['origin',
                    'target'],  #TODO: dans les 2 sens pour query optimisé
    }
Exemplo n.º 8
0
class CcUserProfile(Document):

    user_auth_id = fields.IntField(required=False)
    first_name = fields.StringField(required=False)
    last_name = fields.StringField(required=False)
    mobile_no = fields.StringField(required=False)
    email = fields.EmailField(required=False)
    gender = fields.IntField(required=False)
    alternate_number = fields.StringField(required=False)
    is_profile_verified = fields.DynamicField(required=False)
    cc_src_type_id = fields.IntField(null=True, required=False)
    cc_project_id = fields.IntField(required=False)
    cc_default_profile = fields.BooleanField(required=False)
    profile_type = fields.IntField(required=False)
    profile_others_info = fields.DynamicField(required=False)
    profile_max_lock_limit = fields.IntField(required=False)
    is_profile_active = fields.BooleanField(required=False)
    country_id = fields.StringField(null=True, required=False)
    state_id = fields.StringField(null=True, required=False)
    city_id = fields.StringField(null=True, required=False)
    area_id = fields.IntField(null=True, required=False)
    cc_user_type_id = fields.IntField(null=True, required=False)
    is_active = fields.BooleanField(default=False, required=False)
    created_by = fields.IntField(required=False)
    created_at = fields.DateTimeField(required=False)
    updated_by = fields.IntField(required=False)
    updated_at = fields.DateTimeField(default=datetime.utcnow)

    def save(self, *args, **kwargs):
        # if not self.created_at:
        # 	self.created_at = datetime.utcnow()

        return super(CcUserProfile, self).save(*args, **kwargs)
Exemplo n.º 9
0
class RegularModel(Document):
    """
    A model class for testing regular flat fields.
    """
    str_field = fields.StringField()
    str_regex_field = fields.StringField(regex="^valid_regex")
    url_field = fields.URLField()
    email_field = fields.EmailField()
    int_field = fields.IntField()
    long_field = fields.LongField()
    float_field = fields.FloatField()
    boolean_field = fields.BooleanField()
    nullboolean_field = fields.BooleanField(null=True)
    date_field = fields.DateTimeField()
    complexdate_field = fields.ComplexDateTimeField()
    uuid_field = fields.UUIDField()
    id_field = fields.ObjectIdField()
    decimal_field = fields.DecimalField()

    custom_field = CustomField()

    # TODO
    # dynamic_field = fields.DynamicField()
    # bin_field = fields.BinaryField()
    # file_field = fields.FileField()
    # image_field = fields.ImageField()

    def method(self):
        return 'method'
Exemplo n.º 10
0
class VosaeUserSettings(EmbeddedDocument):
    """
    Settings related to a :class:`~core.models.VosaeUser`.
    """
    language_code = fields.StringField(choices=settings.LANGUAGES)
    gravatar_email = fields.EmailField()
    email_signature = fields.StringField(max_length=2048)
Exemplo n.º 11
0
class User(Document):
    """Defines a user model for the database

    Attributes:
        email: The unique email used to register the user
        hashed_password: The string representation of the user's hashed password
        date_registered: The date the user registered for an account
        email_verified: A flag to track whether the user has verified their email
    """
    email = fields.EmailField(unique=True, required=True)
    hashed_password = fields.StringField(required=True)
    date_registered = fields.DateField(
        default=datetime.now().strftime("%Y-%m-%d"))
    email_verified = fields.BooleanField(default=False)

    def check_user_provided_password(self, user_provided_password) -> bool:
        """Checks the validity of the user provided password

        Parameters:
            user_provided_password: password entered by the user

        Returns:
            Boolean value associated with validity of user provided password
        """
        return check_password_hash(self.hashed_password,
                                   user_provided_password)
Exemplo n.º 12
0
class Usuario(Document):
    usuario = fields.StringField(required=True, max_length=30)
    email = fields.EmailField(required=True, max_length=150)
    nombre = fields.StringField(max_length=50)
    password = fields.StringField(required=True, min_length=8)
    imagen = fields.URLField(required=False)
    descripcion = fields.StringField(max_length=500)
    listaSeguidores = fields.ListField(fields.ReferenceField('Usuario'))
    listaSeguidos = fields.ListField(fields.ReferenceField('Usuario'))
    listaPublicaciones = fields.ListField(fields.ReferenceField('Publicacion'))
    listaComentariosPublicaciones = fields.ListField(
        fields.ReferenceField('Publicacion'))
    listaGraffitisPublicaciones = fields.ListField(
        fields.ReferenceField('Publicacion'))

    def delete(self, *args, **kwargs):
        for publicacion in self.listaComentariosPublicaciones:
            comentarios = publicacion.listaComentarios
            for comentario in comentarios:
                if comentario.autor == self:
                    publicacion.__class__.objects.update(
                        pull__listaComentarios=comentario)

        for publicacion in self.listaGraffitisPublicaciones:
            graffitis = publicacion.listaGraffitis
            for graffiti in graffitis:
                if graffiti.autor == self:
                    publicacion.__class__.objects.update(
                        pull__listaGraffitis=graffiti)

        super().delete()
Exemplo n.º 13
0
class User(Document):
    email = fields.EmailField(unique=True)
    password = fields.StringField()
    name = fields.StringField()
    profile = fields.URLField()
    acquisition_date = fields.DateTimeField()
    last_login = fields.DateTimeField()
    boards = fields.ListField(fields.LazyReferenceField('Board'))
Exemplo n.º 14
0
class PropietarioField(EmbeddedDocument):
    NOMBRE = fields.StringField(required=True)
    CORREO = fields.EmailField()
    TIPO_DOCUMENTO = fields.StringField(required=True)
    DOCUMENTO = fields.StringField(required=True)
    USUARIO_ID = fields.LazyReferenceField('Usuarios',
                                           passthrough=False,
                                           dbref=False)
Exemplo n.º 15
0
class User(Document):

    username = fields.StringField(required=True)
    email = fields.EmailField(required=True, )
    firstname = fields.StringField(required=True)
    lastname = fields.StringField(required=True, null=True)
    status = fields.IntField(required=True, default=1)
    userdetails = ListField(EmbeddedDocumentField('UserDetails'))
Exemplo n.º 16
0
class ResetToken(BaseModel):
    user = fields.ReferenceField(User, required=True)
    email = fields.EmailField(unique=True, required=True)
    salt = fields.StringField(required=True)
    secret = fields.StringField(required=True)
    created_at = fields.IntField(required=True)
    # db collection
    meta = {"collection": "reset_tokens"}
Exemplo n.º 17
0
class Editor(Document):
    first_name = fields.StringField(max_length=250)
    last_name = fields.StringField(max_length=250)
    email = fields.EmailField(max_length=250)

    is_definer = fields.BooleanField(default=True)
    is_reviewer = fields.BooleanField(default=False)
    is_publisher = fields.BooleanField(default=False)
Exemplo n.º 18
0
class Shop(Document):
    name = fields.StringField()
    picture = fields.URLField()
    email = fields.EmailField()
    city = fields.StringField()
    location = fields.PointField()
    
    def __str__(self):
        return self.name
Exemplo n.º 19
0
class User(db.Document, BaseModelMixin):
    username = fields.StringField()
    _password = fields.StringField(db_field='password')
    email = fields.EmailField(unique=True)
    avatar = fields.StringField(default=None)
    position = fields.StringField()  # 职位
    department = fields.StringField()  # 部门
    phone = fields.StringField()

    equipment_num = fields.LongField(default=0)  # 装置数量
    device_num = fields.LongField(default=0)  # 设备数量
    interface_num = fields.LongField(default=0)  # 接口数量
    cable_num = fields.LongField(default=0)  # 线缆数量

    login_num = fields.LongField(default=0)
    search_num = fields.LongField(default=0)

    author_type = fields.IntField(default=0)
    author_editable = fields.BooleanField(default=True)
    deletable = fields.BooleanField(default=True)
    is_active = fields.BooleanField(default=True)
    token = fields.EmbeddedDocumentField(Token, default=None)

    is_anonymous = False

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

    @property
    def is_authenticated(self):
        return self.is_active and self.token is not None and self.token.expired_at > datetime.now(
        )

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, pwd):
        self._password = pbkdf2_sha256.hash(pwd)

    def check_password(self, pwd):
        return pbkdf2_sha256.verify(pwd, self._password)

    def refresh_token(self, token_expired_time):
        self.token.expired_at = datetime.now() + timedelta(
            seconds=token_expired_time)
        return self.save()

    def generate_token(self, token_expired_time):
        token = binascii.hexlify(
            os.urandom(20) + str(self.id).encode('utf-8')).decode()
        expired_at = datetime.now() + timedelta(seconds=token_expired_time)
        self.token = Token(value=token, expired_at=expired_at)
        self.login_num += 1
        self.save()
        return self.token.value
Exemplo n.º 20
0
class Companies(Document):
    """
    Schema to Document for Companies
    """
    name = fields.StringField(required=True)
    mail = fields.EmailField()
    cnpj = fields.StringField()

    meta = {'Companies': 'db_company'}
Exemplo n.º 21
0
class User(Document):
    username = fields.StringField(required=True, max_length=30, unique=True)
    email = fields.EmailField(required=True)
    name = fields.StringField(max_length=50)
    password = fields.StringField(required=True)
    bio = fields.StringField(max_length=100)
    
    # References
    reviews_made = fields.ListField(fields.ReferenceField('Spot'))
Exemplo n.º 22
0
class Employee(Document):
    name = fields.StringField(required=True, max_length=250)
    username = fields.StringField(max_length=250)
    email = fields.EmailField()
    emp_id = fields.IntField()
    designation = fields.EmbeddedDocumentField(Designation)
    file = fields.FileField()

    def __str__(self):
        return self.name
Exemplo n.º 23
0
class User(Document):
    name = fields.EmbeddedDocumentField(Name)
    email = fields.EmailField(null=False, required=True)
    password = fields.StringField(null=False, required=True)
    gender = fields.StringField(null=False)
    license_no = fields.StringField(null=False)
    mobile_no = fields.StringField(null=False, max_length=10, required=True)
    token = fields.StringField()
    created_at = fields.DateTimeField(default=datetime.datetime.utcnow)
    updated_at = fields.DateTimeField(default=datetime.datetime.utcnow)
Exemplo n.º 24
0
class Cart(Document):
    slug = fields.StringField(required=True, max_length=128)
    user = fields.EmailField(max_length=128)
    products = fields.EmbeddedDocumentListField(Product)
    vouchers = fields.EmbeddedDocumentListField(Voucher)
    coupons = fields.EmbeddedDocumentListField(Coupon)

    date_updated = fields.DateTimeField(default=datetime.datetime.utcnow)

    meta = {'allow_inheritance': False}
Exemplo n.º 25
0
class Applies(Document):
    name = fields.StringField(required=True, max_length=50)
    company = fields.StringField(required=True)
    email = fields.EmailField(required=True)
    telf = fields.StringField(required=False,
                              min_length=9,
                              max_length=9,
                              null=True,
                              blank=True)
    content = fields.StringField(required=False, null=True, blank=True)
class Member(Document):
    creation_datetime = fields.DateTimeField(default=Utils().now())
    email = fields.EmailField()
    entrance_list = fields.ListField(
        field=fields.EmbeddedDocumentField(Entrance))
    first_name = fields.StringField()
    last_name = fields.StringField()
    # registration_number = fields.IntField(required=True)
    subscription_list = fields.ListField(
        fields.EmbeddedDocumentField(Subscription))
Exemplo n.º 27
0
class Shops(Document):
    meta = {'db_alias': 'shops', 'collection': 'shops'}

    name = fields.StringField()
    picture = fields.URLField()
    email = fields.EmailField()
    city = fields.StringField()
    location = fields.PointField()

    def __str__(self):
        return self.name
Exemplo n.º 28
0
class SimpleDoc(Document):
    f_str = fields.StringField()
    f_url = fields.URLField()
    f_eml = fields.EmailField()
    f_int = fields.IntField()
    f_lng = fields.LongField()
    f_flt = fields.FloatField()
    f_dec = fields.DecimalField()
    f_bool = fields.BooleanField()
    f_dt = fields.DateTimeField()
    f_oid = fields.ObjectIdField()
    f_uuid = fields.UUIDField()
Exemplo n.º 29
0
        class TestDocument(Document):
            string_field = fields.StringField(
                verbose_name='A string',
                regex=r'[\w]+',
                max_length=100,
                min_length=10,
                help_text='Fill in a string',
            )

            url_field = fields.URLField(
                verbose_name='An URL',
                help_text='Fill in an URL',
            )

            email_field = fields.EmailField(
                verbose_name='An e-mail address',
                regex=r'.*',
                max_length=101,
                min_length=11,
                help_text='Fill in an e-mail address',
            )

            int_field = fields.IntField(
                verbose_name='An int',
                min_value=1,
                max_value=102,
                help_text='Fill in an int',
            )

            float_field = fields.FloatField(
                verbose_name='A float',
                min_value=2,
                max_value=103,
                help_text='Fill in a float',
            )

            decimal_field = fields.DecimalField(
                verbose_name='A decimal',
                min_value=3,
                max_value=104,
                help_text='Fill in a decimal',
            )

            datetime_field = fields.DateTimeField(
                verbose_name='A datetime',
                help_text='Fill in a datetime',
            )

            boolean_field = fields.BooleanField(
                verbose_name='A bool',
                help_text='Yes or no?',
            )
Exemplo n.º 30
0
class Admin(Document):
    first_name = fields.StringField()
    last_name = fields.StringField()

    email = fields.EmailField()
    username = fields.StringField()
    password = fields.StringField()

    active = fields.BooleanField()

    created_at = fields.DateTimeField(required=False)
    updated_at = fields.DateTimeField(required=False)

    meta = {"collection": "admins", "ordering": ["-created_at"]}

    @classmethod
    def set_timings(cls, sender, document, **kwargs):
        """
        Set Created At On Save
        :return:
        """
        if 'created_at' not in kwargs and not document.created_at:
            document.created_at = datetime.datetime.utcnow()

        document.updated_at = datetime.datetime.utcnow()

    @classmethod
    def get_by_activation(cls, active=True):
        """
        Return Query With Active Status
        :param active:
        :return:
        """
        return cls.objects(active=active)

    @classmethod
    def get_by_username(cls, username):
        """
        Return Single User By Username
        :param username:
        :return:
        """
        return cls.objects(username=username).first()

    @classmethod
    def get_by_email(cls, email):
        """
        Return Single User By Email
        :param email:
        :return:
        """
        return cls.objects(email=email).first()