class RSVP(db.Model): __tablename__ = 'rsvp' id = db.Column(db.Integer, primary_key=True) member = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False) event = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False) reply = db.Column(db.Integer, nullable=False) #0 No, 1 Yes, 2 Maybe comment = db.Column(db.Text)
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
class Platform(db.Model): __tablename__ = 'platforms' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255)) short = db.Column(db.String(10)) def __repr__(self): return '<Platform %s>' % self.short
class ProjectMembership(db.Model): __tablename__ = 'projectmembership' id = db.Column(db.Integer, primary_key=True) project = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=False) member = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False) add_date = db.Column(db.DateTime(timezone=True))
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
class Person(db.Model): query_class = PersonQuery __tablename__ = 'people' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255)) image = db.Column(db.String(255)) hometown = db.Column(db.String(255)) country = db.Column(db.String(255)) birth_date = db.Column(db.DateTime) death_date = db.Column(db.DateTime) deck = db.Column(db.Text) first_credited_game = db.Column(db.Integer, db.ForeignKey('games.id')) games = db.relationship('Game', secondary=person_game, backref='people') search_vector = db.Column(TSVectorType('name')) def to_json(self, list_view=False): json_person = { 'id': self.id, 'name': self.name, 'deck': self.deck, 'image': self.image, 'hometown': self.hometown, 'country': self.country, 'birth_date': self.birth_date, 'death_date': self.death_date, 'games_created': len(self.games) } if list_view: games = [] for game in self.games: details = {'id': game.id, 'name': game.name} games.append(details) json_person['games'] = games return json_person def __repr__(self): return '<Person %s>' % self.name
class Game(db.Model): query_class = GameQuery __tablename__ = 'games' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255)) deck = db.Column(db.Text) image = db.Column(db.String(255)) release_date = db.Column(db.DateTime) platforms = db.relationship('Platform', secondary=game_platform, backref=db.backref('games', lazy='dynamic')) search_vector = db.Column(TSVectorType('name')) def to_json(self): json_game = { 'id': self.id, 'name': self.name, 'deck': self.deck, 'image': self.image # 'release_date': self.release_date } developers = [] for dev in self.developers: details = {'id': dev.id, 'name': dev.name} developers.append(details) publishers = [] for pub in self.publishers: details = {'id': pub.id, 'name': pub.name} publishers.append(details) platforms = [] for plat in self.platforms: details = {'id': plat.id, 'name': plat.name, 'short': plat.short} platforms.append(details) json_game['developers'] = developers json_game['publishers'] = publishers json_game['platforms'] = platforms return json_game def __repr__(self): return '<Game %r>' % self.name
from loader import db from sqlalchemy_searchable import SearchQueryMixin from sqlalchemy_utils.types import TSVectorType from sqlalchemy_searchable import make_searchable from flask.ext.sqlalchemy import BaseQuery make_searchable() # Association tables for many-to-many relationships company_person = db.Table( 'company_person', db.Column('company_id', db.Integer, db.ForeignKey('companies.id')), db.Column('person_id', db.Integer, db.ForeignKey('people.id'))) developer_game = db.Table( 'developer_game', db.Column('company_id', db.Integer, db.ForeignKey('companies.id')), db.Column('game_id', db.Integer, db.ForeignKey('games.id'))) publisher_game = db.Table( 'publisher_game', db.Column('company_id', db.Integer, db.ForeignKey('companies.id')), db.Column('game_id', db.Integer, db.ForeignKey('games.id'))) person_game = db.Table( 'person_game', db.Column('person_id', db.Integer, db.ForeignKey('people.id')), db.Column('game_id', db.Integer, db.ForeignKey('games.id'))) game_platform = db.Table( 'game_platform', db.Column('game_id', db.Integer, db.ForeignKey('games.id')), db.Column('platform_id', db.Integer, db.ForeignKey('platforms.id')))
class Attendance(db.Model): __tablename__ = 'attendance' id = db.Column(db.Integer, primary_key=True) member = db.Column(db.Integer, db.ForeignKey('member.id')) event = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False) comment = db.Column(db.Text)
class Event(db.Model): __tablename__ = 'event' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Text, nullable=False) hosting_club = db.Column(db.Integer, db.ForeignKey('club.id')) presenter = db.Column(db.Text) picture = db.Column(db.Text) shorturl = db.Column(db.Text, unique=True) start_time = db.Column(db.DateTime(timezone=True)) end_time = db.Column(db.DateTime(timezone=True)) location = db.Column(db.Text) location_type = db.Column(db.Integer) contact_info = db.Column(db.Text) content_block_id = db.Column(db.Integer, db.ForeignKey('content.id')) rsvp_max_replies = db.Column(db.Integer) rsvp_allow_maybe = db.Column(db.Boolean, nullable=False) rsvp_allow_comments = db.Column(db.Boolean, nullable=False) rsvp_public_view = db.Column(db.Boolean, nullable=False) rsvp_send_reminder = db.Column(db.Boolean, nullable=False)
class Content(db.Model): __tablename__ = 'content' id = db.Column(db.Integer, primary_key=True) content_type = db.Column(db.Text, nullable=False) # html, markdown, none url = db.Column(db.Text) # Which url to expose and respond to render_template = db.Column( db.Text) # Which template to render it against, if any title = db.Column(db.Text) created_on = db.Column(db.DateTime(timezone=True)) created_by = db.Column(db.Integer, db.ForeignKey('member.id')) edited_on = db.Column(db.DateTime(timezone=True)) edited_by = db.Column(db.Integer, db.ForeignKey('member.id')) required_priv_level = db.Column( db.Integer, nullable=False) # 2 = officer, 1 = member, 0 = public show_in_nav = db.Column( db.Integer, nullable=False) # 0 = none, 1 = main nav menu, 2 = sub menu data_blob = db.Column(db.Text, nullable=False)
class Member(db.Model): __tablename__ = 'member' id = db.Column(db.Integer, primary_key=True) student_id = db.Column(db.CHAR(length=9), unique=True) primary_club = db.Column(db.Integer, db.ForeignKey('club.id'), nullable=False) assigned_team = db.Column(db.Integer) priv_level = db.Column( db.Integer, nullable=False ) # -2 officer, -1 admin, 0 member, 1 alumni, 2 associate pw_hash = db.Column(db.Text) pin_hash = db.Column(db.Text) name_first = db.Column(db.Text, nullable=False) name_middle = db.Column(db.Text, nullable=False) name_last = db.Column(db.Text, nullable=False) phone = db.Column(db.Text) texting_ok = db.Column(db.Boolean) email1 = db.Column(db.Text, unique=True, nullable=False) email2 = db.Column(db.Text, unique=True) picture = db.Column(db.Text) gender = db.Column(db.Text) acad_standing = db.Column(db.Text) acad_major = db.Column(db.Text) acad_minor = db.Column(db.Text) acad_conc = db.Column(db.Text) acad_grad_qtr = db.Column(db.Text) signup_date = db.Column(db.DateTime(timezone=False), nullable=False) paid_amount = db.Column(db.Numeric(precision=5, scale=2)) paid_date = db.Column(db.DateTime(timezone=False)) paid_until_date = db.Column(db.DateTime(timezone=False)) receipt_date = db.Column(db.DateTime(timezone=False)) badge_type = db.Column(db.Integer) shirt_size = db.Column(db.Text) shirt_received_date = db.Column(db.DateTime(timezone=False))
class Club(db.Model): __tablename__ = 'club' id = db.Column(db.Integer, primary_key=True) shortname = db.Column(db.Text, nullable=False) longname = db.Column(db.Text, nullable=False)
class Project(db.Model): __tablename__ = 'project' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Text, nullable=False) content_block_id = db.Column(db.Integer, db.ForeignKey('content.id')) leader = db.Column(db.Integer, db.ForeignKey('member.id'))
class Source(db.Model): query_class = SourceQuery __tablename__ = 'sources' id_num = db.Column(db.String(25), primary_key=True) id_name = db.Column(db.Text) language = db.Column(db.String(25)) description = db.Column(db.Text) smallLogoURL = db.Column(db.Text) mediumLogoURL = db.Column(db.Text) largeLogoURL = db.Column(db.Text) category = db.Column(db.String(25)) external_link = db.Column(db.Text) name = db.Column(db.String(25)) region = db.Column(db.String(25)) country = db.Column(db.String(25)) search_vector = db.Column(TSVectorType('name', 'description')) def to_json(self, list_view=False): json_location = { 'id_num': self.id_num, 'id_name': self.id_name, 'language': self.language, 'description': self.description, 'smallLogoURL': self.smallLogoURL, 'mediumLogoURL': self.mediumLogoURL, 'largeLogoURL': self.largeLogoURL, 'category': self.category, 'external_link': self.external_link, 'name': self.name, 'region': self.region, 'country': self.country } return json_location def __repr__(self): return '<Source %r>' % self.id_num
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