Example #1
0
class BillDetailModel(db.Model):
    __tablename__ = 'bill_detail'

    id = db.Column(db.Integer, primary_key=True, server_default=db.text("nextval('bill_detail_id_seq'::regclass)"))
    bill_id = db.Column(db.Integer, nullable=False)
    product_id = db.Column(db.Integer, nullable=False)
    count = db.Column(db.Integer, nullable=False)
Example #2
0
class PointToMoneyModel(db.Model):
    __tablename__ = 'point_to_money'

    id = db.Column(
        db.Integer,
        primary_key=True,
        server_default=db.text("nextval('point_to_money_id_seq'::regclass)"))
    start_date = db.Column(db.Date, nullable=True)
    end_date = db.Column(db.Date, nullable=True)
    rate_to_money = db.Column(db.Float(53), nullable=True)
class TypeMemberModel(db.Model):
    __tablename__ = 'type_member'

    id = db.Column(
        db.Integer,
        primary_key=True,
        server_default=db.text("nextval('type_member_id_seq'::regclass)"))
    name_member = db.Column(db.String, nullable=False)
    price = db.Column(db.Integer, nullable=True)
    date_created = db.Column(db.Date, nullable=False)
    status = db.Column(db.Integer, nullable=True)
Example #4
0
class BillModel(db.Model):
    __tablename__ = 'bill'

    id = db.Column(db.Integer,
                   primary_key=True,
                   server_default=db.text("nextval('bill_id_seq'::regclass)"))
    user_id = db.Column(db.Integer, nullable=False)
    money_bill = db.Column(db.Float(53), nullable=False)
    date_created = db.Column(db.Date, nullable=False)
    conversion_point = db.Column(db.Integer, nullable=True)
    conversion_point_last = db.Column(db.Integer, nullable=True)
    ship_money = db.Column(db.Float(53), nullable=True)
Example #5
0
class ProductModel(db.Model):
    __tablename__ = 'product'

    id = db.Column(
        db.Integer,
        primary_key=True,
        server_default=db.text("nextval('product_id_seq'::regclass)"))
    product_name = db.Column(db.String, nullable=False)
    product_price = db.Column(db.Float(53), nullable=False)
    count = db.Column(db.Integer, nullable=False)
    description = db.Column(db.Text, nullable=False)
    photo = db.Column(db.Text, nullable=False)
Example #6
0
class Person(db.Model):
    """
    api.person SQLAlchemy model
    """
    __tablename__ = "person"
    __table_args__ = {'schema': 'api'}
    id = db.Column(UUID(as_uuid=True), primary_key=True, server_default=db.text("uuid_generate_v4()"))
    first_name = db.Column(db.String)
    middle_name = db.Column(db.String)
    last_name = db.Column(db.String)
    email = db.Column(db.String)
    age = db.Column(db.Integer)
    meta_create_ts = db.Column(
        db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
    )
    version = db.Column(db.Integer)
Example #7
0
class UserModel(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer,
                   primary_key=True,
                   server_default=db.text("nextval('user_id_seq'::regclass)"))
    username = db.Column(db.String, nullable=False)
    password = db.Column(db.String, nullable=False)
    fullname = db.Column(db.String, nullable=True)
    role = db.Column(db.Integer, nullable=True)
    danger = db.Column(db.Boolean, nullable=True)
    dob = db.Column(db.Date, nullable=True)
    address = db.Column(db.String, nullable=True)
    phone_number = db.Column(db.String, nullable=True)
    email = db.Column(db.String, nullable=True)
    point = db.Column(db.Integer, nullable=True)
    status = db.Column(db.Integer, nullable=True)
    member_id = db.Column(db.Integer, nullable=True)
class Project(db.Model):
    __tablename__ = 'Projects'

    proj_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    owner = db.Column(db.Integer, db.ForeignKey("Users.id"), nullable=False)
    start_day = db.Column(db.TIMESTAMP(timezone=True), nullable=False)
    tot_days = db.Column(db.Integer, nullable=False)
    plan = db.Column(db.String(5000), nullable=False)
    created_time = db.Column(db.TIMESTAMP(timezone=True),
                             nullable=False,
                             server_default=func.now())
    update_time = db.Column(db.TIMESTAMP(timezone=True),
                            nullable=False,
                            server_default=func.now(),
                            onupdate=func.current_timestamp())
    is_public = db.Column(db.Boolean,
                          server_default=db.text('FALSE'),
                          nullable=False)

    def __init__(self, name, owner, start_day, tot_days, one_day_plan_list):
        self.name = name
        self.owner = owner
        self.start_day = start_day
        self.tot_days = tot_days
        self.plan = json.dumps([p.to_dict() for p in one_day_plan_list],
                               default=json_default_handler)

    def to_dict(self):
        return dict(
            proj_id=self.proj_id,
            name=self.name,
            owner=self.owner,
            start_day=self.start_day,
            tot_days=self.tot_days,
            plan=json.loads(self.plan),
            created_time=self.created_time,
            update_time=self.update_time,
            is_public=self.is_public,
            like_num=self.count_like_num(),
        )

    def count_like_num(self):
        return FavoriteProject.query.filter_by(proj_id=self.proj_id).count()

    def get_all_spots(self):
        plan = json.loads(self.plan)
        spot_ids = set()
        for day_dict in plan:
            for spot_dict in day_dict['arrange']:
                spot_ids.add(spot_dict['spot_id'])
        return list(spot_ids)

    class OneDayPlan:
        def __init__(self):
            self.start_time = '08:00:00'
            self._arrange = []

        def add_spot(self, spot, during_min):
            self._arrange.append({
                'spot_id': spot.id,
                'during': during_min,
            })

        def to_dict(self):
            return dict(
                start_time=self.start_time,
                arrange=self._arrange,
            )

        @classmethod
        def from_dict(cls, d):
            obj = Project.OneDayPlan()
            obj.start_time = d['start_time']
            obj._arrange = d['arrange']
            return obj