Exemple #1
0
class Question(db.Model):
    __tablename__ = 'questions'

    id = db.Column(db.String(37), primary_key=True)
    body = db.Column(db.String(100), index=True, unique=True)
    optionOne = db.Column(db.String(30))
    optionTwo = db.Column(db.String(30))

    dislikes = db.Column(db.Integer, default=0)
    answeredOne = db.Column(db.Integer, default=0)
    answeredTwo = db.Column(db.Integer, default=0)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    author_id = db.Column(db.String(16), db.ForeignKey('users.ip'))

    totalViews = db.column_property(answeredOne + answeredTwo + dislikes)
    popularity = db.column_property(answeredOne + answeredTwo)

    viewed = db.relationship('User', secondary="middle")

    def __repr__(self):
        return '<Question {}>'.format(self.body)

    def prune(self):
        if self.answeredOne + self.answeredTwo < self.dislikes and self.totalViews > 10:
            return True
        if self.timestamp + timedelta(days=2) < datetime.utcnow():
            return True
        return False
Exemple #2
0
class db_Grocery(db.Model):
    """
    Create Groceries table
    """

    __tablename__ = 'groceryTable'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    category = db.Column(db.String(60))
    section = db.Column(db.String(60))
    subsection = db.Column(db.String(60))
    price = db.Column(db.Float)
    ounces = db.Column(db.Float)
    unit = db.Column(db.String(30))
    reported_price_per_unit = db.Column(db.String(30))
    brand = db.Column(db.String(80))
    date = db.Column(db.DateTime, default=False)
    price_density = db.column_property(price / ounces)
    store_id = db.Column(db.Integer, db.ForeignKey('storeTable.id'))
    url = db.Column(db.String(120))

    #TODO convert ids into values this will require pulling down the other tables, and somehow referencing them
    #column_sortable_list = ('acronym', 'definition', 'author.userLN')

    def __repr__(self):
        return '<Grocery: %s, Def: %s>' % (format(self.name), format(
            self.price))
Exemple #3
0
class Video(db.Model):
    __tablename__ = 'videos'

    name = db.Column(db.String, index=True, nullable=False)
    brand = db.Column(db.String, nullable=False)
    published = db.Column(db.Date, nullable=False)

    count = db.column_property(
        db.select([db.func.count(View.id)
                   ]).where(db.text('views.video_id=videos.id')))
Exemple #4
0
class User(BaseModel, UserMixin):
    first_name = db.Column(db.String(50), nullable=False)
    last_name = db.Column(db.String(50), nullable=False)
    full_name = db.column_property(first_name + " " + last_name)
    email = db.Column(db.String(70), nullable=False, unique=True)
    password = db.Column(db.String(102), nullable=False)
    note = db.Column(db.Text, nullable=True)

    def __repr__(self):
        return "User({})".format(self.email)

    def generate_password_hash(self, password):
        self.password = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password, password)
Exemple #5
0
class User(db.Model):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(128), nullable=False)
    # JACKSON CREATED BELOW THREE LINE
    uid = db.Column(db.String(128), nullable=False)
    first_name = db.Column(db.String(128), nullable=False)
    last_name = db.Column(db.String(128), nullable=False)
    items = db.relationship('Item', backref='user', lazy=True)
    full_name = db.column_property(first_name + " " + last_name)

    def __init__(self, email, uid, first_name, last_name):
        self.email = email
        # JACKSON CREATED BELOW THREE LINE
        self.uid = uid
        self.first_name = first_name
        self.last_name = last_name
class User(db.Model, UserMixin):
    __tablename__ = 'Users'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), unique=True)
    password = db.Column(db.String(120), index=True)
    first_name = db.Column(db.String(120))
    last_name = db.Column(db.String(120))
    fullname = db.column_property(last_name + ", " + first_name)
    role = db.Column(db.Integer, default=0)
    verified = db.Column(db.Integer)
    department = db.Column(db.Integer, db.ForeignKey(Department.id))

    def __init__(self,
                 username=None,
                 email=None,
                 password=None,
                 first_name=None,
                 last_name=None,
                 department=None,
                 role=0,
                 verified=0):
        self.username = username
        self.email = email
        self.password = password
        self.first_name = first_name
        self.last_name = last_name
        self.role = role
        self.verified = verified
        self.department = department

    def is_admin(self):
        return self.role == 1

    def __repr__(self):
        return 'User %s email %s first %slast %s department %s ' % (
            self.username, self.email, self.first_name, self.last_name,
            self.department)
Exemple #7
0
class Tag(db.Model, dbFunctions):
    __tablename__ = "tags"
    query_class = TagQuery

    id = db.Column(db.Integer, primary_key=True)
    slug = db.Column(db.String(80), unique=True)
    posts = db.dynamic_loader(Post,
                              secondary=post_tags,
                              query_class=PostQuery,
                              cascade="all, delete")
    #posts = db.relationship(Post, secondary='post_tags', lazy='dynamic',
    #                        backref=db.backref('tags', lazy='dynamic'), cascade="all, delete")

    _name = db.Column("name", db.String(80), unique=True)

    def __str__(self):
        return self.name

    def _get_name(self):
        return self._name

    def _set_name(self, name):
        self._name = name.lower().strip()
        self.slug = slugify(name)

    name = db.synonym("_name", descriptor=property(_get_name, _set_name))

    @cached_property
    def url(self):
        return url_for("home.tag", slug=self.slug)

    num_posts = db.column_property(
        db.select([db.func.count(post_tags.c.post_id)]).\
            where(db.and_(post_tags.c.tag_id==id,
                          Post.id==post_tags.c.post_id,
                          Post.access==Post.PUBLIC)).as_scalar())