Exemplo n.º 1
0
class Pin(TableTemplate, db.Model, CRUD):
    query_class = PinQuery

    id = db.Column(db.Integer, primary_key=True)
    geo = db.Column(Geometry(geometry_type='POINT', srid=4326))
    title = db.Column(db.String(50), nullable=False)
    short_title = db.Column(db.String(20), nullable=False)
    description = db.Column(db.String(256))
    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    pin_photo_id = db.Column(db.Integer, db.ForeignKey('file.id'), unique=True)

    #Relationships
    owner = db.relationship('User', backref=db.backref('pin'))
    pin_photo = db.relationship('File')

    #Seach Vector
    search_vector = db.Column(
        TSVectorType('title', 'description', 'short_title'))

    @hybrid_property
    def vote_score(self):
        if (self.votes):
            return sum((1 if vote.vote else -1) for vote in self.votes)
        else:
            return 0

    def load_hybrid_properties(self):
        self.vote_score
Exemplo n.º 2
0
class User(UserMixin, db.Model):
    """ Contains user information. """

    __tablename__ = "user"

    user_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    username = db.Column(db.String(100), nullable=False)
    first_name = db.Column(db.String(100), nullable=False)
    last_name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String, nullable=False)
    confirmed = db.Column(db.Boolean, default=False)
    location = db.Column(db.String(80), nullable=False)
    member_since = db.Column(db.DateTime(), default=datetime.utcnow)
    # avatar_hash = db.Column(db.String(32))
    age = db.Column(db.Integer, nullable=True)
    password = db.Column(db.String(128), nullable=False)
    followed = db.relationship('Relations',
                               foreign_keys=[Relations.follower_id],
                               backref=db.backref('follower', lazy='joined'),
                               lazy='dynamic',
                               cascade='all, delete-orphan')
    followers = db.relationship('Relations',
                                foreign_keys=[Relations.followed_id],
                                backref=db.backref('followed', lazy='joined'),
                                lazy='dynamic',
                                cascade='all, delete-orphan')
    comments = db.relationship('Comment', backref='user', lazy='dynamic')

    # Put name inside TSVectorType definition for it to be fulltext-indexed (searchable)
    search_vector = db.Column(TSVectorType('first_name', 'last_name'))

    def __repr__(self):

        return "<User user_id={} email={}>".format(self.user_id, self.email)
Exemplo n.º 3
0
class Restaurant(db.Model):
    """Restaurant on Breadcrumbs website."""

    __tablename__ = "restaurants"

    restaurant_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    city_id = db.Column(db.Integer,
                        db.ForeignKey('cities.city_id'),
                        nullable=False)
    name = db.Column(db.String(150), nullable=False)
    address = db.Column(db.String(150), nullable=False)
    phone = db.Column(db.String(20), nullable=True)
    image_url = db.Column(db.String(200), nullable=True)
    # Latitude and Longitude need to be Numeric, not Integer to have decimal places
    latitude = db.Column(db.Numeric, nullable=False)
    longitude = db.Column(db.Numeric, nullable=False)
    # Put restaurant name and address inside definition of TSVectorType to be fulltext-indexed (searchable)
    search_vector = db.Column(TSVectorType('name', 'address'))

    city = db.relationship("City", backref=db.backref("restaurants"))
    categories = db.relationship("Category",
                                 secondary="restaurantcategories",
                                 backref="restaurants")
    users = db.relationship("User", secondary="visits", backref="restaurants")

    def __repr__(self):
        """Provide helpful representation when printed."""

        return "<Restaurant restaurant_id=%s name=%s>" % (self.restaurant_id,
                                                          self.name)
Exemplo n.º 4
0
class Question(Post):

    __tablename__ = 'questions'

    title = Column(String, nullable=False)

    answers = relationship('Answer', cascade='all, delete-orphan')
    tags = relationship('Tag',
                        secondary=association_table,
                        backref='questions')

    user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
    user = relationship('User', backref='questions')

    # Search vector
    search_vector = Column(TSVectorType('title', 'body'))

    def to_dict(self):
        my_dict = Post.to_dict(self)
        my_dict.update({
            'title': self.title,
            'nb_answers': len(self.answers),
            'tags': [tag.label for tag in self.tags],
            'user': self.user.to_dict()
        })
        return my_dict
Exemplo n.º 5
0
class Post(db.Model):
    def __repr__(self):
        return "<Post %r>" % self.title

    query_class = PostQuery

    id = db.Column(db.Integer, primary_key=True)
    _title = db.Column('title', db.UnicodeText)
    slug = db.Column(db.UnicodeText)
    body = db.Column(db.UnicodeText)
    timestamp = db.Column(db.DateTime)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    is_published = db.Column(db.Boolean)
    search_vector = db.Column(TSVectorType('title', 'body'))

    @hybrid_property
    def title(self):
        return self._title

    @title.setter
    def title(self, title):
        self._title = title
        self.slug = re.sub('[^\w]+', '-', self.title.lower())

    @hybrid_method
    def summary(self, n_words):
        # stripped = re.sub(r'[#>*-]', ' ', self.body)
        # return ' '.join(stripped.split()[:n_words]) + '...'
        stripped = self.body.split('.')
        return '. '.join(stripped[:n_words]) + ' ...'
Exemplo n.º 6
0
class ArxivModel(Base):

    __tablename__ = 'arxiv'

    id = Column(Integer, primary_key=True, autoincrement=True)
    version = Column(Integer)
    popularity = Column(Integer)
    title = Column(Unicode(800, collation=''))
    arxiv_url = Column(String(255), primary_key=True)
    pdf_url = Column(String(255))
    published_time = Column(DateTime())
    authors = Column(Unicode(800, collation=''))
    abstract = Column(Text(collation=''))
    journal_link = Column(Text(collation=''), nullable=True)
    tag = Column(String(255))
    introduction = Column(Text(collation=''))
    conclusion = Column(Text(collation=''))
    analyzed = Column(Boolean, server_default='false', default=False)

    # For full text search
    search_vector = Column(
        TSVectorType('title',
                     'abstract',
                     'authors',
                     weights={
                         'title': 'A',
                         'abstract': 'B',
                         'authors': 'C'
                     }))

    def __repr__(self):
        template = '<Arxiv(id="{0}", url="{1}")>'
        return str_repr(template.format(self.id, self.arxiv_url))
Exemplo n.º 7
0
class Page(db.Model):
    query_class = PageQuery
    __tablename__ = "pages"
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(500))
    text = db.Column(db.UnicodeText())
    html = db.Column(db.UnicodeText())
    url = db.Column(db.String(500), unique=True, nullable=False)
    search_vector = db.Column(TSVectorType('text'))

    def __repr__(self):
        """
        Return a string containing a printable
        representation of a Page object.
        ":return: str"
        """
        return 'Title: {}, url: {}'.format(unicode(self.title, "utf-8"),
                                           unicode(self.url, "utf-8"))

    @classmethod
    def get_all_entries(cls):
        """
        List all entries saved to database.
        :return: Page object
        """
        return Page.query.all()
Exemplo n.º 8
0
class Location(db.Model):
    query_class = LocationQuery
    __tablename__ = 'locations'
    id_num = db.Column(db.String(25), primary_key=True)
    currencies = db.Column(db.Text)
    latlng = db.Column(db.Text)
    capital = db.Column(db.String(50))
    population = db.Column(db.String(50))
    topLevelDomain = db.Column(db.Text)
    languages = db.Column(db.Text)
    name = db.Column(db.String(50))
    region = db.Column(db.String(25))

    search_vector = db.Column(TSVectorType('name', 'region', 'capital'))

    def to_json(self, list_view=False):
        json_location = {
            'id_num': self.id_num,
            'currencies': self.currencies,
            'latlng': self.latlng,
            'capital': self.capital,
            'population': self.population,
            'topLevelDomain': self.topLevelDomain,
            'languages': self.languages,
            'name': self.name,
            'region': self.region
        }

        return json_location

    def __repr__(self):
        return '<Location %s>' % self.id_num
Exemplo n.º 9
0
class Article(db.Model):
    query_class = ArticleQuery
    __tablename__ = 'articles'
    id_num = db.Column(db.String(25), primary_key=True)
    title = db.Column(db.Text)
    description = db.Column(db.Text)
    pubDate = db.Column(db.String(25))
    image_link = db.Column(db.Text)
    category = db.Column(db.Text)
    external_article_link = db.Column(db.Text)
    external_source_link = db.Column(db.Text)
    source_name = db.Column(db.Text)
    region = db.Column(db.String(25))

    search_vector = db.Column(TSVectorType('title', 'description'))

    def to_json(self, list_view=False):
        json_article = {
            'id_num': self.id_num,
            'title': self.title,
            'description': self.description,
            'pubDate': self.pubDate,
            'image_link': self.image_link,
            'category': self.category,
            'external_article_link': self.external_article_link,
            'external_source_link': self.external_source_link,
            'source_name': self.source_name,
            'region': self.region
        }

        return json_article

    def __repr__(self):
        return '<Article %s>' % self.id_num
Exemplo n.º 10
0
class Charge(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  date = db.Column(db.DateTime)
  location = db.Column(db.String(MAX_STRING))
  description = db.Column(db.Text)
  classification = db.Column(db.String(MAX_STRING))

  celebrity_id = db.Column(db.Integer, db.ForeignKey('celebrity.id'))
  crime_id = db.Column(db.Integer, db.ForeignKey('crime.id'))
  
  crime = db.relationship('Crime')
  celebrity = db.relationship('Celebrity')

  search_vector = db.Column(TSVectorType('description', 'classification'))
  
  def __init__(self,
               celebrity,
               crime,
               date=None,
               location=None,
               description=None,
               classification=None):
    self.celebrity = celebrity
    self.crime = crime
    self.date = date
    self.location = location
    self.celebrity = celebrity
    self.crime = crime
    self.description = description
    self.classification = classification

  def __repr__(self):
    return '(Charge {num}: {celebrity}, {crime})'.format(
        self.id, self.crime, self.celebrity)
Exemplo n.º 11
0
class Celebrity(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(MAX_STRING))
  description = db.Column(db.Text)
  twitter_handle = db.Column(db.String(MAX_STRING))
  birthday = db.Column(db.DateTime)
  wiki_url = db.Column(db.String(MAX_STRING))
  imdb_url = db.Column(db.String(MAX_STRING))
  picture_url = db.Column(db.String(MAX_STRING))

  aliases = db.relationship('CelebrityAlias')
  crimes = db.relationship('Crime', secondary='charge')
  charges = db.relationship('Charge')

  search_vector = db.Column(TSVectorType('name', 'description', 'twitter_handle', 'wiki_url', 'imdb_url'))

  def __init__(self,
               name,
               description=None,
               twitter_handle=None,
               birthday=None,
               wiki_url=None,
               imdb_url=None,
               picture_url=None):
    self.name = name
    self.description = description
    self.twitter_handle=twitter_handle
    self.birthday = birthday
    self.wiki_url = wiki_url
    self.imdb_url = imdb_url
    self.picture_url = picture_url

  def __repr__(self):
    return '(Celebrity {num}: {name})'.format(name=self.name, num=self.id)
Exemplo n.º 12
0
class City(Base):
    __tablename__ = 'city'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(255))
    country = Column(String(255))
    location = Column(Geometry(geometry_type='POINT', srid=4326)) # SRID=4326;POINT(0.00 0.00)
    search_vector = Column(TSVectorType('name'))
Exemplo n.º 13
0
class User(TableTemplate, db.Model, CRUD):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    nickname = db.Column(db.String(20), unique=True)
    password = db.Column(db.String(20), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    profile_photo_id = db.Column(db.Integer,
                                 db.ForeignKey('file.id'),
                                 unique=True)

    #Seach Vector
    search_vector = db.Column(TSVectorType('username', 'email', 'nickname'))

    #Relationships
    profile_photo = db.relationship('File')

    def get_email(self):
        return self.email

    #Functions reserved for login manager
    def is_active(self):
        return self.is_active

    def is_authenticated(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return unicode(self.id)
Exemplo n.º 14
0
class Pose(db.Model):
    query_class = PoseQuery
    __tablename__ = "poses"

    pose_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.Unicode(100), nullable=False, unique=True) # required and unique, SEARCHABLE
    sanskrit = db.Column(db.Unicode(100), nullable=True) # sanskrit name with accents (for displaying)
    sanskrit_unaccented = db.Column(db.Unicode(100), nullable=True) # sanskrti name w/o accents, SEARCHABLE
    description = db.Column(db.Unicode(2000)) # SEARCHABLE
    difficulty = db.Column(db.String(20), nullable=False)
    altnames = db.Column(db.Unicode(100), nullable=True) # SEARCHABLE
    benefit = db.Column(db.String(1000), nullable=True)
    img_url = db.Column(db.String(200), nullable=False)
    is_leftright = db.Column(db.Boolean, nullable=True) # boolean to indicate whether a pose has left/right version
    next_pose_str = db.Column(db.String(500), nullable=True) # next poses stored as a string for now
    prev_pose_str = db.Column(db.String(500), nullable=True) # previous poses stored as a string for now
    next_poses = db.Column(JSON, nullable=True) # next poses as a JSON {pose_id: weight, pose_id: weight, ....}

    search_vector = db.Column(TSVectorType('name','sanskrit_unaccented','altnames','description',
                                         catalog='pg_catalog.simple',
                                         weights={'name': 'A', 'altnames': 'B', 'sanskrit_unaccented': 'C', 'description':'D'}))
    pose_workout = db.relationship('PoseWorkout')
    pose_categories = db.relationship('PoseCategory')

    def getNextPose(self, next_poses=None):
        """
        Returns a Pose object that would follow based on
        choosing a pose from the original Pose object's next_poses attribute 
        OR it can take in a user specified next poses dictionary

        next_poses must be a dictionary = {id: weight, id: weight ...} 
        
        e.g. 
        Usage: warrior2.getNextPose() 
        Output: <Pose name="Warrior I">

        """

        if next_poses is None: # if no next poses are specified use the ones in the attribute for that pose
            next_poses = self.next_poses

        if next_poses: # if the next_poses exists for that pose (i.e. it's not an empty dictionary)
            pose_ids = []
            pose_weights = []
            for pose_id, weight in next_poses.items(): # next_poses = {id: weight, id: weight ...}
                pose_ids.append(int(pose_id))
                pose_weights.append(weight)

        else: # if no next poses exist then choose from some basic ones like Mountain, Down Dog
            pose_ids =[64,130,32] # ids for Down Dog, Mountain, and Corpse
            pose_weights = [2,2,1]

        next_pose_id = random.choices(pose_ids, pose_weights)[0] # random.choices returns a list

        return Pose.query.get(next_pose_id)

    def __repr__(self):
        """Print out the Pose object nicely"""
        return "<Pose pose_id={}, name={}>".format(self.pose_id, self.name)
Exemplo n.º 15
0
class Group(db.Model):
    query_class = GroupQuery
    __tablename__ = 'groups'

    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String,unique=True,nullable=False)
    members = db.relationship('User',secondary=members,backref=db.backref('group_users', lazy='dynamic'))
    group_posts = db.relationship('Post',secondary=group_posts,backref=db.backref('group_posts', lazy='dynamic',order_by=Post.time_posted))
    admins = db.relationship('User',secondary=admins,backref=db.backref('admin_users', lazy='dynamic'))
    banned_members = db.relationship('User',secondary=banned_members,backref=db.backref('group_banned_users', lazy='dynamic'))
    description = db.Column(db.String)
    private = db.Column(db.Boolean)
    search_vector = db.Column(TSVectorType('group_name', 'group_description'))

    def __init__(self,name,description,admin,private):
        self.name = name
        self.description = description
        self.admins.append(admin)
        self.private = private
        self.members.append(admin)

    def __repr__(self):
        return '<Group {0}>'.format(self.name)

    def is_member(self,user):
        if user in self.members:
            return True
        else:
            return False

    def is_admin(self,user):
        if user in self.admins:
            return True
        else:
            return False

    def join(self,user):
        self.members.append(user)
        db.session.commit()

    def leave(self,user):
        user = User.query.get(user)
        self.members.remove(user)
        db.session.commit()

    def make_admin(self,user):
        self.admins.append(user)
        db.session.commit()

    def add_post(self,post):
        self.group_posts.append(post)
        db.session.commit()

    def is_banned(self,user):
        if user in self.banned_members:
            return True
        else:
            return False
Exemplo n.º 16
0
class User(TableBase):
    # TODO: flesh this out and make it usable
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    name = Column(String(length=256))
    search_vector = Column(TSVectorType('name'))

    applications = relationship('Application', back_populates='author')
Exemplo n.º 17
0
class Company(db.Model):
    """
    This model is used to represent Company entries in our database.
    Attributes:
    ID - ID of the company. This variable self-increments.

    Name - The name of the company.

    Num_developed - The number of games this company has developed.

    Image_url - The company logo from the IGDB API.

    Num_published - The number of games this company has published.

    Avg_rating - The average rating of all the games this company is associated with.

    Year_founded - The year this company was founded.

    Games - The games associated with this company. This data is retrieved using
        the association table.
    """
    query_class = CompanyQuery
    __tablename__ = 'companies'
    company_id = db.Column(db.Integer, primary_key=True, autoincrement=False)
    name = db.Column(db.String(50), unique=True)
    num_developed = db.Column(db.Integer)
    num_published = db.Column(db.Integer)
    image_url = db.Column(db.String(255))
    avg_rating = db.Column(db.Float)
    year_founded = db.Column(db.Integer, db.ForeignKey('years.year_id'))
    search_vector = db.Column(TSVectorType('name'))
    associated_games = db.relationship(
        "Game",
        secondary=association_table_game_company,
        backref=db.backref('companies'))

    def __init__(self,
                 company_id,
                 name=None,
                 num_developed=0,
                 image_url="",
                 num_published=0,
                 avg_rating=0.0,
                 year_founded=None,
                 search_vector=None):
        self.company_id = company_id
        self.name = name
        self.num_developed = num_developed
        self.image_url = image_url
        self.num_published = num_published
        self.avg_rating = avg_rating
        self.year_founded = year_founded
        self.search_vector = search_vector

    def __repr__(self):
        return '<Company: %r>' % (self.name)
Exemplo n.º 18
0
        class TextItem(self.Base):
            __tablename__ = 'textitem'

            id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)

            name = sa.Column(sa.Unicode(255))

            search_vector = sa.Column(TSVectorType('name', 'content'))

            content = sa.Column(sa.UnicodeText)
Exemplo n.º 19
0
class Agurate_Farmers_Farm(db.Model):
    __tablename__ = 'agurate_farmers_farm'

    id = db.Column(db.Integer, primary_key= True)
    farmer_code = db.Column(db.String, db.ForeignKey('agurate_farmers.farmer_code'), nullable=False)
    farm_code = db.Column(db.String, db.ForeignKey('agurate_farms.farm_code'), index=True, nullable=False)
    created_at = db.Column(db.DateTime, server_default=db.func.current_timestamp())
    updated_at = db.Column(db.DateTime,server_default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
    document_token = db.Column(db.Text)
    search_vector = db.Column(TSVectorType('document_token'))
Exemplo n.º 20
0
class Application(TableBase):
    # TODO: Currently ignoring but should maybe handle:
    # capabilities, changelog, compatibility, images, links?,
    # screenshots, companion apps
    __tablename__ = 'application'

    id = Column(Integer, primary_key=True)
    guid = Column(GUID)
    author_id = Column(Integer, ForeignKey('user.id'), nullable=False)
    title = Column(String(length=256))
    description = Column(String)
    hearts = Column(Integer, default=0)
    source = Column(String(length=256))
    create_ts = Column(ArrowType, default=arrow.utcnow)
    publish_ts = Column(ArrowType, default=arrow.utcnow)
    search_vector = Column(TSVectorType('title', 'description'))

    author = relationship('User', back_populates='applications')
    collections = relationship('Collection',
                               secondary=ApplicationCollection,
                               back_populates='applications')
    files = relationship('File', back_populates='application')

    @validates('title', 'source')
    def validate_code(self, key, value):
        max_len = getattr(self.__class__, key).prop.columns[0].type.length
        if value and len(value) > max_len:
            return value[:max_len]
        return value

    def to_json(self):
        return {
            'id': self.id,
            'title': self.title,
            'description': self.description,
            # TODO: flesh these out
            'hearts': self.hearts,
            'companions': {
                'android': None,
                'ios': None
            },
            'list_image': {
                '80x80': '',
                '144x144': ''
            },
            'screenshot_hardware': 'basalt',
            'screenshot_images': [{
                '0x0': ''
            }],
            'icon_image': {
                '28x28': '',
                '48x48': ''
            },
            'capabilities': []
        }
Exemplo n.º 21
0
class Review(Base):
    __tablename__ = 'review'
    id = Column(Integer, primary_key=True)
    product_id = Column(String, ForeignKey('product.id'))    
    voter_helpful = Column(Integer)
    voter_total = Column(Integer)
    text = Column(Text)
    summary = Column(String)
    rating = Column(Float)
    date_posted = Column(DateTime)
    search_vector = Column(TSVectorType('text', 'summary'))
Exemplo n.º 22
0
class Agurate_Seedling_Price(db.Model):
    __tablename__ = 'agurate_seedling_price'

    id = db.Column(db.Integer, primary_key=True)
    farmer_code = db.Column(db.String(100), nullable=False)
    crop_variety_code = db.Column(db.String(100), db.ForeignKey('agurate_crop_varieties.crop_variety_code'), nullable=False)
    price = db.Column(db.Numeric, nullable=False)
    created_at = db.Column(db.DateTime, server_default=db.func.current_timestamp())
    updated_at = db.Column(db.DateTime, server_default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
    document_token = db.Column(db.Text)
    search_vector = db.Column(TSVectorType('document_token'))
Exemplo n.º 23
0
class Company(db.Model):
    query_class = CompanyQuery
    __tablename__ = 'companies'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    image = db.Column(db.String(255))
    city = db.Column(db.String(255))
    country = db.Column(db.String(255))
    deck = db.Column(db.Text)
    date_founded = db.Column(db.DateTime)
    people = db.relationship('Person',
                             secondary=company_person,
                             backref='companies')
    developed_games = db.relationship('Game',
                                      secondary=developer_game,
                                      backref='developers')
    published_games = db.relationship('Game',
                                      secondary=publisher_game,
                                      backref='publishers')
    search_vector = db.Column(TSVectorType('name'))

    def to_json(self, list_view=False):
        json_company = {
            'id': self.id,
            'name': self.name,
            'deck': self.deck,
            'image': self.image,
            'city': self.city,
            'country': self.country,
            'date_founded': self.date_founded
        }
        if list_view:
            dev_games = []
            for game in self.developed_games:
                details = {'id': game.id, 'name': game.name}
                dev_games.append(details)
            pub_games = []
            for game in self.published_games:
                details = {'id': game.id, 'name': game.name}
                pub_games.append(details)
            people = []
            people_cache = []  # removes duplicates
            for person in self.people:
                if person.id not in people_cache:
                    details = {'id': person.id, 'name': person.name}
                    people.append(details)
                    people_cache.append(person.id)
            json_company['developed_games'] = dev_games
            json_company['published_games'] = pub_games
            json_company['people'] = people
        return json_company

    def __repr__(self):
        return '<Company %s>' % self.name
Exemplo n.º 24
0
class Tag(Base):

    __tablename__ = 'tags'

    label = Column(String(25), primary_key=True, nullable=False)

    # Search vector
    search_vector = Column(TSVectorType('label'))

    def to_dict(self):

        return {'label': self.label}
Exemplo n.º 25
0
class Agurate_Farmer_Log(db.Model):
    __tablename__= 'agurate_farmer_logs'
    id= db.Column(db.Integer, primary_key=True)
    farmer= db.Column(db.String(100), nullable=False)
    type = db.Column(db.String(50), nullable=False)
    note = db.Column(db.Text)
    status = db.Column(db.String(100), nullable=False)
    employee = db.Column(db.String(100), nullable=False)
    created_at = db.Column(db.DateTime, server_default=db.func.current_timestamp())
    updated_at = db.Column(db.DateTime,server_default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
    document_token = db.Column(db.Text)
    search_vector = db.Column(TSVectorType('document_token'))
Exemplo n.º 26
0
class Character(db.Model, Base):
    """
    DC characters with attributes title, hero/villain alias, an image,
    their alignment, and other information
    """
    __tablename__ = 'characters'
    query_class = CharacterQuery
    title = db.Column(db.String(50), primary_key=True)
    image = db.Column(db.String(250))
    universes = db.Column(ARRAY(db.String(100)))
    gender = db.Column(db.String(50))
    aliases = db.Column(ARRAY(db.String(100)))
    creators = db.Column(ARRAY(db.String(100)))
    identity = db.Column(db.String(50))
    real_name = db.Column(db.String(50))
    debut = db.Column(db.String(50))
    affiliation = db.Column(ARRAY(db.String(100)))
    alignment = db.Column(db.String(50))
    category = db.Column(db.String(50))
    search_vector = db.Column(
        TSVectorType('title', 'image', 'universes', 'gender', 'aliases',
                     'creators', 'identity', 'real_name', 'debut',
                     'affiliation', 'alignment', 'category'))

    def __init__(self,
                 title="",
                 alias=[],
                 image="",
                 alignment="",
                 creators=[],
                 identity="",
                 real_name="",
                 universe=[],
                 status="",
                 gender="",
                 debut="",
                 aliases=[],
                 affiliation=[]):
        """
        Initialize the character
        """
        self.title = title
        self.aliases = aliases
        self.image = image
        self.alignment = alignment
        self.creators = creators
        self.identity = identity
        self.real_name = real_name
        self.universes = universe
        self.gender = gender
        self.debut = debut
        self.affiliation = affiliation
Exemplo n.º 27
0
class City(Base):
    __tablename__ = "cities"

    city_id = DColumn(Integer, primary_key=True)
    name = DColumn(String)
    population = DColumn(Integer)
    city_picture_link = DColumn(String)
    state = DColumn(String, ForeignKey("regions.state"))
    artists = relationship('Artist',
                           secondary=cities_artists,
                           back_populates='cities')

    search_vector = Column(TSVectorType('name', 'state'))
Exemplo n.º 28
0
class Agurate_Farm_Property(db.Model):
    __tablename__ = 'agurate_farms_properties'
    id = db.Column(db.Integer, primary_key=True)
    farm_code = db.Column(db.String(256), db.ForeignKey('agurate_farms.farm_code'), nullable=False)
    property_code= db.Column(db.String(100), nullable=False, index=True)
    property_value = db.Column(db.String, nullable=False)
    group = db.Column(db.String)
    created_at = db.Column(db.DateTime, server_default=db.func.current_timestamp())
    updated_at = db.Column(db.DateTime,server_default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
    document_token = db.Column(db.Text)
    search_vector = db.Column(TSVectorType('document_token'))
    def __repr__(self):
        return '' %self.farm_code % self.property_code
Exemplo n.º 29
0
class Agurate_Crop_Variety_Property(db.Model):
    __tablename__ = 'agurate_crop_variety_properties'
    id = db.Column(db.Integer, primary_key=True)
    crop_variety_code = db.Column(db.String(256), db.ForeignKey('agurate_crop_varieties.crop_variety_code'),nullable=False)

    entity = db.Column(db.String(256), nullable=False)
    attribute = db.Column(db.String(100))
    value = db.Column(db.String(100))
    note = db.Column(db.Text)
    created_at = db.Column(db.DateTime, server_default=db.func.current_timestamp())
    updated_at = db.Column(db.DateTime,server_default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())
    document_token = db.Column(db.Text)
    search_vector = db.Column(TSVectorType('document_token'))
Exemplo n.º 30
0
class Restaurant(db.Model):
    query_class = RestaurantQuery
    __tablename__ = "restaurants"

    try:
        if int(os.environ['TESTING']) == 1:
            id = db.Column(db.Integer, primary_key=True)
    except KeyError:
        id = db.Column(UUIDType(binary=False), primary_key=True)
    name = db.Column(db.String, nullable=False)
    date = db.Column(db.Date, nullable=False)
    category = db.Column(db.String, nullable=True)
    images = db.Column(db.PickleType, nullable=True)
    dishes = db.relationship('Dish',
                             cascade="all, delete, delete-orphan",
                             backref='restaurant')
    tags = db.Column(db.String, nullable=True)
    editors = db.relationship('User',
                              backref='restaurant',
                              secondary=restaurants_users)
    locations = db.relationship('Location', backref='restaurant')
    last_edited = db.Column(db.Integer, nullable=False)
    try:
        if int(os.environ['TESTING']) == 1:
            last_editor = db.Column(db.Integer)
    except KeyError:
        last_editor = db.Column(UUIDType)
    search_vector = db.Column(TSVectorType('name',
                                           'category',
                                           'tags',
                                           weights={'name': 'A',
                                                    'category': 'C',
                                                    'tags': 'B'}))

    def __init__(self, name, category, tags, user_id):
        if app.config['TESTING'] != True:
            self.id = uuid.uuid4()
        self.name = name
        self.date = datetime.utcnow()
        self.category = category
        self.images = []
        self.tags = tags
        if user_id is None:
            self.editors = []
        else:
            self.editors.append(User.query.get(user_id))
        self.last_edited = int(time())

    def __repr__(self):
        return '<Restaurant {}>'.format(self.id)