class User(db.Model):
    __tablename__ = 'Users'
    Id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    Name = db.Column(db.Text(), nullable=True)
    Email = db.Column(db.Text(), nullable=False)
    DisplayName = db.Column(db.Text(), nullable=True)
    FamilyName = db.Column(db.Text(), nullable=True)
    RegistrationDate = db.Column(db.DateTime(), nullable=False)
    LastVisit = db.Column(db.DateTime(), nullable=False)

    wished_markers = db.relationship('Marker',
                                     secondary=wishlist_markers,
                                     backref='wishers')
    owned_markers = db.relationship('Marker',
                                    secondary=my_markers,
                                    backref='owners')
    cart_markers = db.relationship('Cart', backref='user')

    def to_dict(self):
        data = {
            'id': self.Id,
            'email': self.Email,
            'name': self.Name,
            'display_name': self.DisplayName,
            'family_name': self.FamilyName,
            'registration_date': self.RegistrationDate,
            'last_visit': self.LastVisit
        }
        return data
class Store(db.Model):
    __tablename__ = 'Stores'
    Id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    Name = db.Column(db.Text(), nullable=False)
    Site = db.Column(db.Text(), nullable=False)
    Logo = db.Column(db.Text(), nullable=False)

    def to_dict(self):
        data = {
            'id': self.Id,
            'name': self.Name,
            'site': self.Site,
            'logo': self.Logo
        }
        return data
Exemplo n.º 3
0
class Organisation(Base):
    TYPE_CHOICE = [
        ('charity', 'Charity'),
        ('funder', 'Funder'),
        ('other', 'Other')
    ]

    name = db.Column(db.String(100), nullable=False)
    type = db.Column(ChoiceType(TYPE_CHOICE), nullable=False)
    address = db.Column(db.Text(180))

    created_by = db.Column(db.Integer, db.ForeignKey('user.id'))

    contacts = db.relationship('Contact', backref='organisation')
    activities = db.relationship('Activity', backref='contact_lookup')

    @staticmethod
    def create(**kwargs):
        o = Organisation(**kwargs)
        db.session.add(o)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
        return o
class Marker(db.Model):
    __tablename__ = 'Markers'
    Id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    Brand = db.Column(db.Text(), nullable=False)
    Series = db.Column(db.Text(), nullable=False)
    FullName = db.Column(db.Text(), nullable=False)
    ColorGroup = db.Column(db.Text(), nullable=True)
    ColorGroupFullName = db.Column(db.Text(), nullable=False)
    Hex = db.Column(db.Text(), nullable=False)
    ShortName = db.Column(db.Text(), nullable=False)

    carts = db.relationship('Cart', backref='marker')

    def __repr__(self):
        return self.Brand + self.Series + self.Hex

    def to_dict(self):
        data = {
            'id': self.Id,
            'full_name': self.FullName,
            'short_name': self.ShortName,
            'brand': self.Brand,
            'series': self.Series,
            'hex': self.Hex,
            'color_group_full_name': self.ColorGroupFullName,
            'color_group': self.ColorGroup
        }
        return data

    def by_brand_series_key(self):
        return self.Brand + self.Series
Exemplo n.º 5
0
class Comment(db.Model):
    __tablename__ = 'comment'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(1000))
    email = db.Column(db.String(1000))
    content = db.Column(db.Text())

    entity_id = db.Column(db.Integer, db.ForeignKey('entity.id'))

    def __str__(self):
        return self.name
Exemplo n.º 6
0
class Report(CRUDMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False, unique=False)
    rd_query = db.Column(db.Text(), nullable=True)
    created_ts = db.Column(db.DateTime(timezone=True),
                           default=datetime.datetime.utcnow)
    updated_ts = db.Column(db.DateTime(timezone=True),
                           default=datetime.datetime.utcnow)
    last_run = db.Column(db.DateTime(timezone=True),
                         default=datetime.datetime.utcnow)

    def __init__(self, rd_query=None, **kwargs):
        super(Report, self).__init__(**kwargs)
        if rd_query:
            self.rd_query = rd_query

    def __repr__(self):
        return '<Report #%s:%r>' % (self.id, self.name)
Exemplo n.º 7
0
class Organisation(Base):

    name = db.Column(db.String(100), nullable=False)
    address = db.Column(db.Text())

    created_by = db.Column(db.Integer,
                           db.ForeignKey('user.id', ondelete='cascade'))

    contacts = db.relationship('Contact', backref='organisation')
    activities = db.relationship('Activity', backref='contact_lookup')

    @staticmethod
    def create(**kwargs):
        o = Organisation(**kwargs)
        db.session.add(o)
        try:
            db.session.commit()
        except Exception as err:
            db.session.rollback()
            print('ERROR ERROR ERROR')
            print(err)
        return o
Exemplo n.º 8
0
class Feature(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(64))
    description = db.Column(db.Text())
    client = db.Column(db.String(24))
    client_priority = db.Column(db.Integer())
    target_date = db.Column(db.DateTime())
    product_area = db.Column(db.String(24))

    def to_json(self):
        """Return object data in easily serializeable format"""
        return {
            'id': self.id,
            'title': self.title,
            'description': self.description,
            'client': self.client,
            'client_priority': self.client_priority,
            'target_date': dump_datetime(self.target_date),
            'product_area': self.product_area
        }

    def __repr__(self):
        return '<Feature {}>'.format(self.title)
Exemplo n.º 9
0
class Touch_store(db.Model):
    __tablename__ = 'touchs'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(300))
    message = db.Column(db.Text())
    hsize = db.Column(db.String(100))
    hcolor = db.Column(db.String(100))
    hbg = db.Column(db.String(100))
    tsize = db.Column(db.String(100))
    tcolor = db.Column(db.String(100))
    msize = db.Column(db.String(100))
    mcolor = db.Column(db.String(100))
    mbg = db.Column(db.String(100))
    audio = db.Column(db.String(100))
    hfont = db.Column(db.String(100))
    mfont = db.Column(db.String(100))
    tfont = db.Column(db.String(100))
    mduration = db.Column(db.String(100))
    bgcolor = db.Column(db.String(100))
    p = db.Column(db.Boolean)
    n = db.Column(db.Boolean)
    tmp = db.Column(db.Integer)
    akey = db.Column(db.Integer,
                     db.ForeignKey("media.id", ondelete='cascade'),
                     nullable=True)
    ikey = db.Column(db.Integer,
                     db.ForeignKey("media.id", ondelete='cascade'),
                     nullable=True)

    def __init__(self,
                 id=0,
                 title="Please select a task to pull a tick for",
                 hsize="500%",
                 hcolor="rgb(129, 200, 139)",
                 hbg="rgba(0, 0, 0, 0.50)",
                 tsize="400%",
                 mbg="rgba(0, 0, 0, 0.50)",
                 msize="400%",
                 mcolor="rgb(255, 255, 0)",
                 tcolor="btn-danger",
                 message="Ticket has been issued, pleas wait your turn",
                 audio="bell_sound.wav",
                 hfont="El Messiri",
                 mfont="Mada",
                 tfont="Amiri",
                 ikey=1,
                 tmp=2,
                 akey=5,
                 mduration="3000",
                 bgcolor="bg_dark.jpg",
                 p=False,
                 n=True):
        self.id = 0
        self.hfont = hfont
        self.mfont = mfont
        self.tfont = tfont
        self.mduration = mduration
        self.title = title
        self.message = message
        self.hsize = hsize
        self.hcolor = hcolor
        self.hbg = hbg
        self.tsize = tsize
        self.tcolor = tcolor
        self.msize = msize
        self.mcolor = mcolor
        self.mbg = mbg
        self.audio = audio
        self.bgcolor = bgcolor
        self.ikey = ikey
        self.akey = akey
        self.p = p
        self.n = n
        self.tmp = tmp
Exemplo n.º 10
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True)
    email = db.Column(db.String(120), unique=True)
    pw_hash = db.Column(db.String(480))
    avatar_hash = db.Column(db.String(32))
    name = db.Column(db.String(240), default='')
    created_on = db.Column(db.DateTime, default=datetime.datetime.now)
    confirmed = db.Column(db.Boolean, default=False)
    location = db.Column(db.String(64))
    about_me = db.Column(db.Text())
    last_seen = db.Column(db.DateTime(), default=datetime.datetime.now)

    posts = db.relationship('Post', backref='author', lazy='dynamic')
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)
        if self.email is not None and self.avatar_hash is None:
            self.avatar_hash = hashlib.md5(
                self.email.encode('utf-8')).hexdigest()

        if self.role is None:
            if self.email == current_app.config['FLASKY_ADMIN']:
                self.role = Role.query.filter_by(permissions=0xff).first()
            if self.role is None:
                self.role = Role.query.filter_by(default=True).first()

    def __repr__(self):
        if self.name:
            return '<User %r>' % (self.name, )
        else:
            return '<User %r>' % (self.username, )

    @property
    def password(self):
        raise AttributeError('password is not a readable attribute')

    @password.setter
    def password(self, password):
        self.pw_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.pw_hash, password)

    # def is_authenticated(self):
    #     return True
    #
    # def is_active(self):
    #     return True
    #
    # def is_anonymous(self):
    #     return False
    #
    # def get_id(self):
    #     return self.id

    def can(self, permissions):
        return self.role is not None and \
            (self.role.permissions & permissions) == permissions

    def is_administrator(self):
        return self.can(Permission.ADMINISTER)

    def generate_confirmation_token(self, expiration=3600):
        s = Serializer(current_app.config['SECRET_KEY'], expiration)
        return s.dumps({'confirm': self.id})

    def confirm(self, token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False
        if data.get('confirm') != self.id:
            return False
        self.confirmed = True
        db.session.add(self)
        db.session.commit()
        return True

    def ping(self):
        self.last_seen = datetime.datetime.utcnow()
        db.session.add(self)

    def change_email(self, new_email, token):
        if self.confirm(token):
            self.email = new_email
            self.avatar_hash = hashlib.md5(
                self.email.encode('utf-8')).hexdigest()
            db.session.add(self)
            return True
        return False

    def gravatar(self, size=100, default='identicon', rating='g'):
        if request.is_secure:
            url = 'https://secure.gravatar.com/avatar'
        else:
            url = 'http://www.gravatar.com/avatar'
        hash = self.avatar_hash or hashlib.md5(
            self.email.encode('utf-8')).hexdigest()
        return '{url}/{hash}?s={size}&d={default}&r={rating}'.format(
            url=url, hash=hash, size=size, default=default, rating=rating)

    @staticmethod
    def generate_fake(count=100):
        from sqlalchemy.exc import IntegrityError
        from random import seed
        import forgery_py
        seed()
        for i in range(count):
            u = User(email=forgery_py.internet.email_address(),
                     username=forgery_py.internet.user_name(True),
                     password=forgery_py.lorem_ipsum.word(),
                     confirmed=True,
                     name=forgery_py.name.full_name(),
                     location=forgery_py.address.city(),
                     about_me=forgery_py.lorem_ipsum.sentence(),
                     member_since=forgery_py.date.date(True))
            db.session.add(u)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()

    def follow(self, user):
        pass

    def unfollow(self, user):
        pass

    def is_following(self, user):
        return False

    def is_followed_by(self, user):
        return False
Exemplo n.º 11
0
class Group(BaseModel):
    __tablename__ = 'group'
    name = db.Column(db.String(255), unique=True, index=True)
    description = db.Column(db.Text(), index=True)
Exemplo n.º 12
0
class Ticket(Base):

    subject = db.Column(db.String(250),
                        nullable=False,
                        info={"label": "Subject"})
    description = db.Column(db.Text(),
                            nullable=False,
                            info={"label": "Description"})
    severity = db.Column(db.String(250),
                         nullable=False,
                         info={"label": "Severity"})
    status = db.Column(db.String(250),
                       nullable=False,
                       info={"label": "Status"})
    close_date = db.Column(AwareDateTime(), onupdate=tzware_datetime)
    created_by = db.Column(db.Integer,
                           db.ForeignKey('user.id', ondelete='cascade'))
    org_id = db.Column(db.Integer,
                       db.ForeignKey('organisation.id', ondelete='cascade'))
    org_name = db.Column(db.String(250), nullable=False)
    org_address = db.Column(db.Text(), nullable=False)
    contact_id = db.Column(db.Integer,
                           db.ForeignKey('contact.id', ondelete='cascade'))
    contact_name = db.Column(db.String(250),
                             nullable=False,
                             info={"label": "Full Name"})
    contact_email = db.Column(EmailType,
                              nullable=False,
                              info={"label": "Email"})
    contact_phone = db.Column(db.String(250),
                              nullable=False,
                              info={"label": "Phone"})

    activities = db.relationship('Activity', backref='ticket')

    def short(self):
        return {
            'id': self.id,
            'date_created': self.date_created,
            'date_modified': self.date_modified,
            'subject': self.subject,
            'severity': self.severity,
            'status': self.status,
            'closed_date': self.close_date
        }

    def long(self):
        return {
            'id': self.id,
            'date_created': self.date_created,
            'date_modified': self.date_modified,
            'subject': self.subject,
            'description': self.description,
            'severity': self.severity,
            'status': self.status,
            'closed_date': self.close_date,
            'created_by': self.created_by,
            'org_id': self.org_id,
            'contact_id': self.contact_id
        }

    @staticmethod
    def create(**kwargs):
        t = Ticket(**kwargs)
        db.session.add(t)
        try:
            db.session.commit()
        except Exception as err:
            db.session.rollback()
            print('ERROR ERROR ERROR')
            print(err)
        return t

    @classmethod
    def search(cls, query):
        """
        Search a resource by 1 or more fields.

        :param query: Search query
        :type query: str
        :return: SQLAlchemy filter
        """
        if not query:
            return ''

        search_query = f'%{query}%'
        search_chain = (Ticket.subject.ilike(search_query),
                        Ticket.description.ilike(search_query),
                        Ticket.status.ilike(search_query),
                        Ticket.severity.ilike(search_query))

        return or_(*search_chain)