コード例 #1
0
class Event(db.Model):
    __tablename__ = 'event'
    id = db.Column("id", db.Integer, primary_key=True, autoincrement=True)
    name = db.Column("name", db.String(128), nullable=False)
    date = db.Column("date", db.Date, nullable=True)
    start_time = db.Column("start_time", db.DateTime, nullable=True)
    end_time = db.Column("end_time", db.DateTime, nullable=True)
    location = db.Column("location", db.String(1280), nullable=True)
    judge_list = db.Column("judge_list", db.ARRAY(db.Integer), nullable=True)
    school_list = db.Column("school_list", db.ARRAY(db.Integer), nullable=True)
    question_list = db.Column("question_list",
                              db.ARRAY(db.Integer),
                              nullable=True)

    # TODO: Check and update defaults
    def __init__(self,
                 name,
                 date=None,
                 start_time=None,
                 end_time=None,
                 location="",
                 judge_list=[],
                 school_list=[],
                 question_list=[]):
        self.name = name
        self.date = date
        self.start_time = start_time
        self.end_time = end_time
        self.location = location
        self.judge_list = judge_list
        self.school_list = school_list
        self.question_list = question_list

    # returns the JSON for a Judge class
    def to_json(self):
        return {
            'id': self.id,
            'name': self.name,
            'location': self.location,
            'date': self.date,
            'start_time': self.start_time,
            'end_time': self.end_time,
            'judge_list': self.judge_list,
            'school_list': self.school_list,
            'question_list': self.question_list
        }

    # sets the basic location for the Judge
    def set_location(self, name="", username="", location="AppJam+ Event"):
        self.name = name
        self.location = location

    def add_judge(self, judge_id):
        self.judge_list = self.judge_list + [judge_id]

    def add_school(self, school_id):
        self.school_list = self.school_list + [school_id]

    def add_question(self, question_id):
        self.question_list = self.question_list + [question_id]
コード例 #2
0
class Judge(db.Model):
    __tablename__ = 'judge'
    id = db.Column("id", db.Integer, primary_key=True, autoincrement=True)
    username = db.Column("username", db.String(128), nullable=False)
    password = db.Column("password", db.String(128), nullable=False)
    name = db.Column("name", db.String(128), nullable=False)
    job_title = db.Column("job_title", db.String(128), nullable=True)
    event_id = db.Column("event_id", db.Integer, nullable=False)
    team_list = db.Column("team_list", db.ARRAY(db.Integer), nullable=True)
    question_list = db.Column("question_list",
                              db.ARRAY(db.Integer),
                              nullable=True)

    # TODO: Remove event_id default value
    def __init__(self,
                 username,
                 event_id,
                 name,
                 password,
                 job_title="",
                 team_list=[],
                 question_list=[]):
        self.username = username
        self.name = name
        self.password = password
        self.job_title = job_title
        self.event_id = event_id
        self.team_list = team_list
        self.question_list = question_list

    # returns the JSON for a Judge class
    def to_json(self):
        return {
            'id': self.id,
            'username': self.username,
            'password': self.password,
            'name': self.name,
            'job_title': self.job_title,
            'event_id': self.event_id,
            'team_list': self.team_list,
            'question_list': self.question_list,
        }

    # sets the basic info for the Judge
    def set_info(self, name="", username="", job_title="AppJam+ Judge"):
        self.name = name
        self.username = username
        self.job_title = job_title

    def set_event(self, event_id):
        self.event_id = self.event_id

    def add_team(self, team_id):
        self.team_list = self.team_list + [team_id]

    def add_question(self, question_id):
        self.question_list = self.question_list + [question_id]
コード例 #3
0
class Team(db.Model):
    __tablename__ = 'team'
    id = db.Column("id", db.Integer, primary_key=True, autoincrement=True)
    name = db.Column("name", db.String(128), nullable=False)
    info = db.Column("info", db.String(1280), nullable=True)
    school_id = db.Column("school_id", db.Integer, nullable=False)
    student_list = db.Column("student_list",
                             db.ARRAY(db.Integer),
                             nullable=True)
    mentor_list = db.Column("mentor_list", db.ARRAY(db.Integer), nullable=True)
    question_list = db.Column("question_list",
                              db.ARRAY(db.Integer),
                              nullable=True)

    def __init__(self,
                 name,
                 school_id,
                 student_list=[],
                 mentor_list=[],
                 question_list=[],
                 info=""):
        self.name = name
        self.info = info
        self.school_id = school_id
        self.student_list = student_list
        self.mentor_list = mentor_list
        self.question_list = question_list

    # returns the JSON for a Judge class
    def to_json(self):
        return {
            'id': self.id,
            'name': self.name,
            'info': self.info,
            'school_id': self.school_id,
            'student_list': self.student_list,
            'mentor_list': self.mentor_list,
            'question_list': self.question_list,
        }

    def add_student(self, student_id):
        self.student_list = self.student_list + [student_id]

    def add_mentor(self, mentor_id):
        self.mentor_list = self.mentor_list + [mentor_id]

    def add_question(self, question_id):
        self.question_list = self.question_list + [question_id]

    def set_school(self, school_id):
        self.school_id = self.school_id
コード例 #4
0
class School(db.Model):
    __tablename__ = 'school'
    id = db.Column("id", db.Integer, primary_key=True, autoincrement=True)
    name = db.Column("name", db.String(128), nullable=False)
    info = db.Column("info", db.String(1280), nullable=True)
    event_id = db.Column("event_id", db.Integer, nullable=False)
    team_list = db.Column("team_list", db.ARRAY(db.Integer), nullable=True)

    def __init__(self, event_id, name, team_list=[], info=""):
        self.name = name
        self.info = info
        self.event_id = event_id
        self.team_list = team_list

    # returns the JSON for a Judge class
    def to_json(self):
        return {
            'id': self.id,
            'name': self.name,
            'info': self.info,
            'event_id': self.event_id,
            'team_list': self.team_list,
        }

    # sets the basic info for the Judge
    def set_info(self, name="", username="", info="AppJam+ School"):
        self.name = name
        self.info = info

    def add_team(self, team_id):
        self.team_list = self.team_list + [team_id]

    def set_event(self, event_id):
        self.event_id = self.event_id
コード例 #5
0
class ReproductionManagementModel(db.Model):
    __tablename__ = 'reproduction_management'
    reproduction_management_id = db.Column(db.Integer,
                                           primary_key=True,
                                           autoincrement=True)
    date_and_hour_of_management = db.Column(db.DateTime(timezone=True),
                                            nullable=False)
    bovine_id = db.Column(
        db.Integer, db.ForeignKey('dairy_cattle.bovine_id',
                                  ondelete='CASCADE'))
    bull_breed = db.Column(db.String, default="", nullable=False)
    reproduction_type = db.Column(db.String,
                                  default="natural_mount",
                                  nullable=False)
    # if reproduction type == insemination
    insemination_amount = db.Column(
        db.Integer,
        default=0,
        nullable=True,
    )
    insemination_period = db.Column('period_array',
                                    db.ARRAY(db.String),
                                    nullable=True)
    is_finished = db.Column(db.Boolean, default=False, nullable=False)

    def __init__(self, bovine_id, bull_breed, reproduction_type):
        self.date_and_hour_of_management = datetime.utcnow()
        self.bovine_id = bovine_id
        self.bull_breed = bull_breed
        self.reproduction_type = reproduction_type

    def to_json(self):
        reproduction_management = {
            'reproduction_management_id': self.reproduction_management_id,
            'date_and_hour_of_management': self.date_and_hour_of_management,
            'reproduction_type': self.reproduction_type,
            'bovine_id': self.bovine_id,
            'bull_breed': self.bull_breed,
            'is_finished': self.is_finished
        }
        if self.reproduction_type == 'insemination':
            reproduction_management[
                'insemination_amount'] = self.insemination_amount
            reproduction_management[
                'insemination_period'] = self.insemination_period
        return reproduction_management
コード例 #6
0
class Task(db.Model):

    __tablename__ = "tasks"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    creator = db.Column(db.String(128), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False)
    updated_at = db.Column(db.DateTime, nullable=False)
    updated_locally_at = db.Column(db.DateTime,
                                   nullable=True,
                                   onupdate=datetime.now)
    url = db.Column(db.String(128), nullable=False)
    title = db.Column(db.String(255), nullable=True)
    due_date = db.Column(db.DateTime, nullable=True)
    task_type = db.Column(db.String(128), nullable=True)
    category = db.Column(db.String(128), nullable=True)
    maintainer = db.Column(db.String(128), nullable=True)
    language = db.Column(db.String(128), nullable=True)
    customer_count = db.Column(db.Integer, nullable=True)
    estimated_customer_points = db.Column(db.Integer, nullable=True)
    estimated_points = db.Column(db.Integer, nullable=True)
    impact = db.Column(db.Float, nullable=True)
    confidence = db.Column(db.Float, nullable=True)
    reach = db.Column(db.Float, nullable=True)
    effort = db.Column(db.Float, nullable=True)
    rice_total = db.Column(db.Float, nullable=True)
    date_multiplier = db.Column(db.Integer, nullable=True)
    labels = db.Column(db.ARRAY(db.String(255)), nullable=True)
    num_of_comments = db.Column(db.Integer, nullable=True)
    num_of_reactions = db.Column(db.Integer, nullable=True)

    def __init__(self,
                 creator,
                 url,
                 created_at=datetime.utcnow(),
                 updated_at=datetime.utcnow(),
                 updated_locally_at=None,
                 title="",
                 due_date=None,
                 task_type="",
                 category="",
                 maintainer=None,
                 language=None,
                 customer_count=1,
                 estimated_customer_points=None,
                 estimated_points=None,
                 impact=0,
                 reach=0,
                 effort=0,
                 confidence=0,
                 labels=None,
                 date_multiplier=1,
                 num_of_comments=0,
                 num_of_reactions=0,
                 rice_total=0):
        self.creator = creator
        self.url = url
        self.title = title
        self.created_at = created_at
        self.updated_at = updated_at
        self.updated_locally_at = updated_locally_at
        self.due_date = due_date
        self.task_type = task_type
        self.category = category
        self.maintainer = maintainer
        self.labels = labels
        self.language = language
        self.customer_count = customer_count
        self.estimated_customer_points = estimated_customer_points
        self.estimated_points = estimated_points
        self.impact = impact
        self.confidence = confidence
        self.reach = reach
        self.effort = effort
        self.days_to_due = self.calculateDaysToDue(due_date)
        self.date_multiplier = date_multiplier
        self.rice_total = rice_total
        self.num_of_comments = num_of_comments
        self.num_of_reactions = num_of_reactions

    # Get the number of days to due date
    def calculateDaysToDue(self, due_date):
        ''' The Due date should be in the format MM/DD/YYYY '''
        if due_date and isinstance(due_date, datetime):
            return (due_date - datetime.today()).days
        return None

    def to_json(self):
        return {
            'id': self.id,
            'category': self.category,
            'confidence': self.confidence,
            'creator': self.creator,
            'created_at': self.created_at,
            'updated_at': self.updated_at,
            'updated_locally_at': self.updated_locally_at,
            'customer_count': self.customer_count,
            'date_multiplier': self.date_multiplier,
            'days_to_due': self.calculateDaysToDue(self.due_date),
            'due_date': self.due_date,
            'effort': self.effort,
            'estimated_customer_points': self.estimated_customer_points,
            'estimated_points': self.estimated_points,
            'impact': self.impact,
            'labels': self.labels,
            'language': self.language,
            'maintainer': self.maintainer,
            'num_of_comments': self.num_of_comments,
            'num_of_reactions': self.num_of_reactions,
            'reach': self.reach,
            'rice_total': self.rice_total,
            'task_type': self.task_type,
            'title': self.title,
            'url': self.url
        }
コード例 #7
0
class User(db.Model):
    __tablename__ = "users"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    simple_user_id = db.Column(db.BigInteger,
                               db.ForeignKey("simple_users.id"),
                               nullable=False)
    username = db.Column(db.String(30),
                         index=True,
                         unique=True,
                         nullable=False)
    email = db.Column(db.String(128), index=True, unique=True, nullable=False)
    password_hash = db.Column(db.String(255), nullable=False)
    # ip = db.Column(
    #     db.String(15), index=True, nullable=False
    # )
    subscribed = db.Column(db.Boolean, default=True, nullable=False)
    terms_and_conditions = db.Column(db.Boolean, default=False, nullable=False)
    verified = db.Column(db.Boolean, default=False, nullable=False)
    firstname = db.Column(db.String(128), nullable=False)
    middlename = db.Column(db.String(128), nullable=True)
    lastname = db.Column(db.String(128), nullable=False)
    main_address_id = db.Column(db.BigInteger,
                                db.ForeignKey("addresses.id"),
                                nullable=False)
    # TODO: check null address
    # addresses = db.relationship(
    #     "Address", primaryjoin="and_(User.main_address_id==Address.id)",
    #     "Address",
    #     primaryjoin="and_(User.main_address_id==Address.id)",
    #     back_populates="user",
    # )
    addresses = db.relationship("Address",
                                secondary="user_addresses",
                                backref="users",
                                lazy=True)
    # addresses = association_proxy(
    #     "user_addresses",
    #     "address",
    #     creator=lambda address: UserAddress(address=address)
    # )
    address_history = db.Column(db.ARRAY(db.BigInteger),
                                default=[],
                                nullable=False)
    # address_history = db.relationship(
    #     "Address", secondary="user_address_history", backref="user", lazy=True
    # )
    phone = db.Column(db.String(20), unique=True, nullable=True)
    birthday = db.Column(db.DateTime, nullable=False)
    online = db.Column(db.Boolean, default=True, nullable=False)
    last_signin = db.Column(db.DateTime,
                            default=datetime.utcnow,
                            nullable=False)
    last_signout = db.Column(db.DateTime,
                             default=datetime.utcnow,
                             nullable=False)
    created_at = db.Column(db.DateTime,
                           index=True,
                           default=datetime.utcnow,
                           nullable=True)
    deleted = db.Column(db.Boolean, default=False, nullable=False)
    deleted_at = db.Column(db.DateTime, index=True, nullable=True)
    unsubscribed_at = db.Column(db.DateTime, index=True, nullable=True)

    def set_password_hash(self, password):
        # self.password_hash = bcrypt.generate_password_hash(password)
        self.password_hash = argon2.generate_password_hash(
            password,
            # current_app.config.get("BCRYPT_LOG_ROUNDS")
        )

    def encode_auth_token(self, user_id):
        """
        Generates the auth token.
        """
        try:
            payload = {
                'exp':
                datetime.utcnow() +
                timedelta(days=current_app.config.get("TOKEN_EXPIRATION_DAYS"),
                          seconds=current_app.config.get(
                              "TOKEN_EXPIRATION_SECONDS")),
                'iat':
                datetime.utcnow(),
                'sub':
                user_id
            }
            return jwt.encode(payload,
                              current_app.config.get("SECRET_KEY"),
                              algorithm="HS256")
        except Exception as e:
            return e

    @staticmethod
    def decode_auth_token(auth_token):
        """
        Decodes the auth token - :param auth_token: - :return: integer|string
        """
        try:
            payload = jwt.decode(auth_token,
                                 current_app.config.get("SECRET_KEY"))
            return payload['sub']
        except jwt.ExpiredSignatureError:
            return "Signature expired. Please sign in again."
        except jwt.InvalidTokenError:
            return "Invalid token. Please sign in again."

    def __repr__(self):
        return f"<User {self.username}>"

    def to_dict(self):
        return {
            "id": self.id,
            "simple_user_id": self.simple_user_id,
            "username": self.username,
            "email": self.email,
            # TODO: hash password
            "password_hash": self.password_hash,
            "subscribed": self.subscribed,
            "terms_and_conditions": self.terms_and_conditions,
            "verified": self.verified,
            "firstname": self.firstname,
            "middlename": self.middlename,
            "lastname": self.lastname,
            "main_address_id": self.main_address_id,
            "addresses": [address.to_dict() for address in self.addresses],
            "address_history": self.address_history,
            # "address_history": [address.to_dict() for address in self.address_history],
            "phone": self.phone,
            "birthday": str(self.birthday),
            "online": self.online,
            "last_signin": str(self.last_signin),
            "last_signout": str(self.last_signout),
            "created_at": str(self.created_at),
            "deleted": self.deleted,
            "deleted_at": str(self.deleted_at)
        }