class EveCharacter(Model, TimeMixin): __tablename__ = 'characters' character_id = Column(db.String(254), primary_key=True) character_name = Column(db.String(254)) corporation_id = ReferenceCol('corporations', pk_name='corporation_id', nullable=True) corporation = relationship('EveCorporationInfo', backref='characters', foreign_keys=[corporation_id]) api_id = ReferenceCol('api_key_pairs', pk_name='api_id', nullable=True) api = relationship('EveApiKeyPair', backref='characters', foreign_keys=[api_id]) user_id = ReferenceCol('users', nullable=True) user = relationship('User', backref='characters', foreign_keys=[user_id]) skillpoints = Column(db.Integer, nullable=True) previous_users = db.relationship('User', secondary=previous_chars, backref=db.backref('previous_chars', lazy='dynamic'), lazy='dynamic') def __str__(self): return self.character_name
class EveCharacter(Model): __tablename__ = 'characters' character_id = Column(db.String(254), unique=True, primary_key=True) character_name = Column(db.String(254)) corporation_id = ReferenceCol('corporations', pk_name='corporation_id', nullable=True) corporation = relationship('EveCorporationInfo', backref='characters') alliance_id = ReferenceCol('alliances', pk_name='alliance_id', nullable=True) alliance = relationship('EveAllianceInfo', backref='characters') api_id = ReferenceCol('api_key_pairs', pk_name='api_id', nullable=True) api = relationship('EveApiKeyPair', backref='characters') user_id = ReferenceCol('users', nullable=True) user = relationship('User', backref='characters') skillpoints = Column(db.Integer, nullable=True) # def __init__(self, character_id, character_name, corporation_id, **kwargs): # db.Model.__init__(self, character_id=character_id, character_name=character_name, corporation_id=corporation_id, **kwargs) #hr_applications = db.relationship('HrApplications', backref='person', lazy='dynamic') #hr_comments = db.relationship('Comments', backref='person', lazy='dynamic') def __str__(self): return self.character_name
class Role(SurrogatePK, Model, RoleMixin): __tablename__ = 'roles' name = Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __repr__(self): return '<Role({name})>'.format(name=self.name)
class User(SurrogatePK, Model, UserMixin): __tablename__ = 'users' email = Column(db.String(80), unique=True, nullable=False) #: The hashed password password = Column(db.String(128), nullable=True) created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow) active = Column(db.Boolean(), default=False) is_admin = Column(db.Boolean(), default=False) confirmed_at = Column(db.DateTime, nullable=True) last_login_at = Column(db.DateTime()) current_login_at = Column(db.DateTime()) last_login_ip = Column(db.String(100)) current_login_ip = Column(db.String(100)) login_count = Column(db.Integer) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'), lazy='dynamic') main_character_id = ReferenceCol('characters', pk_name='character_id', nullable=True) main_character = relationship('EveCharacter', backref='user_main_character', foreign_keys=[main_character_id]) def set_password(self, password): self.password = encrypt_password(password) self.save() def check_password(self, value): return verify_and_update_password(value, self) @classmethod def create(self, **kwargs): """Create a new record and save it the database.""" instance = self(**kwargs) if kwargs['password']: instance.password = encrypt_password(kwargs['password']) return instance.save() @property def get_ips(self): return self.last_login_ip.split(', ') + self.current_login_ip.split( ', ') def __repr__(self): return '<User({name})>'.format(name=self.email) def __str__(self): return self.email
class EveAllianceInfo(Model): __tablename__ = 'alliances' alliance_id = Column(db.String(254), primary_key=True) alliance_name = Column(db.String(254)) alliance_ticker = Column(db.String(254)) executor_corp_id = Column(db.String(254)) is_blue = Column(db.Boolean, default=False) member_count = Column(db.Integer) def __str__(self): return self.alliance_name
class RolePair(SurrogatePK, Model): __tablename__ = 'role_pair' member_role_id = ReferenceCol('roles', nullable=True) leader_role_id = ReferenceCol('roles', nullable=True) name = Column(db.String(80), unique=True) description = db.Column(db.String(255)) member_role = relationship('Role', foreign_keys=[member_role_id], backref='member_pairs') reviewer_user = relationship('Role', foreign_keys=[leader_role_id], backref='leader_pairs') def __repr__(self): return '<RolePair({name})>'.format(name=self.name)
class Role(SurrogatePK, Model, RoleMixin): __tablename__ = 'roles' name = Column(db.String(80), unique=True) description = db.Column(db.String(255)) #user_id = ReferenceCol('users', nullable=True) #user = relationship('User', backref='roles') # def __init__(self, name, **kwargs): # db.Model.__init__(self, name=name, **kwargs) def __repr__(self): return '<Role({name})>'.format(name=self.name)
class EveAllianceInfo(Model): __tablename__ = 'alliances' alliance_id = Column(db.String(254), unique=True, primary_key=True) alliance_name = Column(db.String(254)) alliance_ticker = Column(db.String(254)) executor_corp_id = Column(db.String(254)) is_blue = Column(db.Boolean, default=False) member_count = Column(db.Integer) # def __init__(self, alliance_id, alliance_name, alliance_ticker, executor_corp_id, **kwargs): # db.Model.__init__(self, alliance_id=alliance_id, alliance_name=alliance_name, alliance_ticker=alliance_ticker, **kwargs) def __str__(self): return self.alliance_name
class EveCorporationInfo(Model): __tablename__ = 'corporations' corporation_id = Column(db.String(254), unique=True, primary_key=True) corporation_name = Column(db.String(254)) corporation_ticker = Column(db.String(254)) member_count = Column(db.Integer) is_blue = Column(db.Boolean, default=False) alliance_id = ReferenceCol('alliances', pk_name='alliance_id', nullable=True) alliance = relationship('EveAllianceInfo', backref='corporations') # def __init__(self, corporation_id, corporation_name, corporation_ticker, member_count=member_count, **kwargs): # db.Model.__init__(self, corporation_id=corporation_id, corporation_name=corporation_name, corporation_ticker=corporation_ticker, **kwargs) def __str__(self): return self.corporation_name
class EveCorporationInfo(Model): __tablename__ = 'corporations' corporation_id = Column(db.String(254), primary_key=True) corporation_name = Column(db.String(254)) corporation_ticker = Column(db.String(254)) member_count = Column(db.Integer) is_blue = Column(db.Boolean, default=False) alliance_id = ReferenceCol('alliances', pk_name='alliance_id', nullable=True) alliance = relationship('EveAllianceInfo', backref='corporations', foreign_keys=[alliance_id]) def __str__(self): return self.corporation_name
class EveApiKeyPair(Model): __tablename__ = 'api_key_pairs' api_id = Column(db.String(254), primary_key=True) api_key = Column(db.String(254)) last_update_time = Column(db.DateTime(), nullable=True) last_scraped_time = Column(db.DateTime(), nullable=True, default=dt.date(day=1, month=1, year=1980)) user_id = ReferenceCol('users', nullable=True) user = relationship('User', backref='api_keys', foreign_keys=[user_id]) valid = Column(db.Boolean, default=True) def __str__(self): return self.api_id
class EveApiKeyPair(Model): __tablename__ = 'api_key_pairs' api_id = Column(db.String(254), unique=True, primary_key=True) api_key = Column(db.String(254)) last_update_time = Column(db.DateTime(), nullable=True) user_id = ReferenceCol('users', nullable=True) user = relationship('User', backref='api_keys') valid = Column(db.Boolean, default=True) # def __init__(self, api_id, api_key, user_id, **kwargs): # db.Model.__init__(self, api_id=api_id, api_key=api_key, user_id=user_id, **kwargs) def __str__(self): return self.api_id
class User(SurrogatePK, Model, UserMixin): __tablename__ = 'users' username = Column(db.String(80), unique=True, nullable=True) email = Column(db.String(80), unique=True, nullable=False) #: The hashed password password = Column(db.String(128), nullable=True) created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow) active = Column(db.Boolean(), default=False) is_admin = Column(db.Boolean(), default=False) confirmed_at = Column(db.DateTime, nullable=True) last_login_at = Column(db.DateTime()) current_login_at = Column(db.DateTime()) last_login_ip = Column(db.String(100)) current_login_ip = Column(db.String(100)) login_count = Column(db.Integer) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) # def __init__(self, username, email, password=None, **kwargs): # db.Model.__init__(self, username=username, email=email, **kwargs) # if password: # self.set_password(password) # else: # self.password = None def set_password(self, password): self.password = bcrypt.generate_password_hash(password) def check_password(self, value): return bcrypt.check_password_hash(self.password, value) @property def full_name(self): return "{0} {1}".format(self.first_name, self.last_name) # def __repr__(self): # return '<User({username!r})>'.format(username=self.username) def __repr__(self): return '<User({name})>'.format(name=self.email)
@property def get_ips(self): return self.last_login_ip.split(', ') + self.current_login_ip.split( ', ') def __repr__(self): return '<User({name})>'.format(name=self.email) def __str__(self): return self.email previous_chars = db.Table( 'previous_chars', db.Column('user_id', db.Integer(), db.ForeignKey('users.id')), db.Column('character_id', db.String(254), db.ForeignKey('characters.character_id'))) class EveCharacter(Model, TimeMixin): __tablename__ = 'characters' character_id = Column(db.String(254), primary_key=True) character_name = Column(db.String(254)) corporation_id = ReferenceCol('corporations', pk_name='corporation_id', nullable=True) corporation = relationship('EveCorporationInfo', backref='characters', foreign_keys=[corporation_id])
# import flask_whooshalchemy as whooshalchemy # from sqlalchemy_searchable import make_searchable # from sqlalchemy_utils.types import TSVectorType, ScalarListType # # from sqlalchemy_searchable import SearchQueryMixin from flask_sqlalchemy import BaseQuery # from sqlalchemy.dialects import postgresql import datetime # make_searchable() character_apps = db.Table('app_characters', db.Column('app_id', db.Integer(), db.ForeignKey('hr_applications.id')), db.Column('character_id', db.String(), db.ForeignKey('characters.character_id'))) class HrApplication(SurrogatePK, TimeMixin, Model): # query_class = HrApplicationQuery __tablename__ = 'hr_applications' __searchable__ = ['thesis', 'how_long', 'notable_accomplishments', 'corporation_history', 'why_leaving', 'what_know', 'what_expect', 'bought_characters', 'why_interested',
class HrApplication(SurrogatePK, Model): __tablename__ = 'hr_applications' __searchable__ = [ 'thesis', 'how_long', 'notable_accomplishments', 'corporation_history', 'why_leaving', 'what_know', 'what_expect', 'bought_characters', 'why_interested', 'find_out', 'favorite_role', 'main_character_name' ] main_character_name = Column(db.Text, nullable=True) alt_application = Column(db.Boolean, default=False) characters = db.relationship('EveCharacter', secondary=character_apps, backref=db.backref('alt_apps', lazy='dynamic')) thesis = Column(db.Text, nullable=True) how_long = Column(db.Text, nullable=True) notable_accomplishments = Column(db.Text, nullable=True) corporation_history = Column(db.Text, nullable=True) why_leaving = Column(db.Text, nullable=True) what_know = Column(db.Text, nullable=True) what_expect = Column(db.Text, nullable=True) bought_characters = Column(db.Text, nullable=True) why_interested = Column(db.Text, nullable=True) goon_interaction = Column(db.Text, nullable=True) friends = Column(db.Text, nullable=True) scale = Column(db.Text, nullable=True) #reason_for_joining = Column(db.Text, nullable=True) find_out = Column(db.Text, nullable=True) favorite_role = Column(db.Text, nullable=True) last_update_time = Column(db.DateTime(), nullable=True) user_id = ReferenceCol('users', nullable=True) reviewer_user_id = ReferenceCol('users', nullable=True) last_user_id = ReferenceCol('users', nullable=True) approved_denied = Column(db.String(10), default="Pending") hidden = Column(db.Boolean, nullable=True, default=False) user = relationship('User', foreign_keys=[user_id], backref='hr_applications') reviewer_user = relationship('User', foreign_keys=[reviewer_user_id], backref='hr_applications_reviewed') last_action_user = relationship('User', foreign_keys=[last_user_id], backref='hr_applications_touched') # def __str__(self): # return self.user.auth_info + " - Application" def __str__(self): return '<Application %r>' % self.user.auth_info