Ejemplo n.º 1
0
class Ticket(app_db.Model):
    """
    status can be: open, assigned, reviewing, working, closed
    1->N relationship with TicketMessages represented by the ticket back reference
    close_date should be assigned when the status is set to closed
    last_status_date should be assigned immediate with the initial status of open
    submitted_by and assigned_to both represent User.ID fields
    """
    id = app_db.Column(app_db.Integer, primary_key=True)
    title = app_db.Column(app_db.String(75), nullable=False)
    summary = app_db.Column(app_db.Text, nullable=False)
    submitted_by = app_db.Column(app_db.Integer,
                                 app_db.ForeignKey('user.id'),
                                 nullable=False)
    assigned_to = app_db.Column(app_db.Integer,
                                app_db.ForeignKey('user.id'),
                                nullable=True)
    status = app_db.Column(app_db.String(10), nullable=False, default="open")
    create_date = app_db.Column(app_db.DateTime,
                                nullable=False,
                                default=datetime.utcnow)
    last_status_date = app_db.Column(app_db.DateTime,
                                     nullable=False,
                                     default=datetime.utcnow)
    close_date = app_db.Column(app_db.DateTime, nullable=True)
    messages = app_db.relationship('TicketMessage',
                                   backref=app_db.backref('ticket', lazy=True))
Ejemplo n.º 2
0
class TicketMessage(app_db.Model):
    id = app_db.Column(app_db.Integer, primary_key=True)
    message = app_db.Column(app_db.Text, nullable=False)
    user_id = app_db.Column(app_db.Integer,
                            app_db.ForeignKey('user.id'),
                            nullable=False)
    ticket_id = app_db.Column(app_db.Integer,
                              app_db.ForeignKey('ticket.id'),
                              nullable=True)
Ejemplo n.º 3
0
class ProductImages(app_db.Model):
    """
    Used to add a group of images to a product display.  A couple notes, the order_weight can be any number,
    the higher the number, the higher it is in the selection, so an image with a weight on 100 is selected
    before an image with a weight of 10 in the ordering.
    Also, the is_primary_image flag is used for the "primary" product display, e.g this is the image shown
    outside of the product page and as the main product display.  IF, because this can be done, multiple images
    have this flag set to true for a single product, it's sorted by order_weight and .first() to resolve the
    conflict silently.
    """
    id = app_db.Column(app_db.Integer, primary_key=True)
    product_image_id = app_db.Column(app_db.Integer,
                                     app_db.ForeignKey('productimage.id'),
                                     nullable=False)
    product_id = app_db.Column(app_db.Integer,
                               app_db.ForeignKey('product.id'),
                               nullable=False)
    is_primary_image = app_db.Column(app_db.Boolean,
                                     nullable=False,
                                     default=False)
    order_weight = app_db.Column(app_db.Integer, nullable=False, default=0)
Ejemplo n.º 4
0
class Review(app_db.Model):
    id = app_db.Column(app_db.Integer, primary_key=True)
    title = app_db.Column(app_db.String(120), nullable=False)
    content = app_db.Column(app_db.Text, nullable=False)
    user_id = app_db.Column(app_db.Integer,
                            app_db.ForeignKey('user.id'),
                            nullable=False)
    author = app_db.relationship('User',
                                 backref=app_db.backref('user', lazy=True))
    approved = app_db.Column(app_db.Boolean, nullable=False, default=False)
    create_date = app_db.Column(app_db.DateTime,
                                nullable=False,
                                default=datetime.utcnow)
Ejemplo n.º 5
0
class Product(app_db.Model):
    id = app_db.Column(app_db.Integer, primary_key=True)
    title = app_db.Column(app_db.String(120), nullable=False)
    description = app_db.Column(app_db.Text, nullable=False, default="No Description")
    quantity = app_db.Column(app_db.Integer, nullable=False, default=0)
    price = app_db.Column(app_db.Float, nullable=False, default=0.0)
    expect_stock_quantity = app_db.Column(app_db.Integer, nullable=False, default=0)
    flag_out_of_stock = app_db.Column(app_db.Boolean, nullable=False, default=False)
    expect_restock_date = app_db.Column(app_db.DateTime, nullable=True)
    category_id = app_db.Column(app_db.Integer, app_db.ForeignKey('product_category.id'), nullable=False)
    category = app_db.relationship('ProductCategory', backref=app_db.backref('product', lazy=True))

    def __repr__(self):
        return "<Product('{}', '{}', '{}')>".format(self.id, self.title, self.quantity)
Ejemplo n.º 6
0
class CustomerOrder(app_db.Model):
    """
    status can be: open, reviewing, working, shipped, closed
    """
    id = app_db.Column(app_db.Integer, primary_key=True)
    user_id = app_db.Column(app_db.Integer,
                            app_db.ForeignKey('user.id'),
                            nullable=False)
    create_date = app_db.Column(app_db.DateTime,
                                nullable=False,
                                default=datetime.utcnow)
    status = app_db.Column(app_db.String(10), nullable=False, default="open")
    last_status_date = app_db.Column(app_db.DateTime,
                                     nullable=False,
                                     default=datetime.utcnow)
    full_filled_date = app_db.Column(app_db.DateTime, nullable=True)
    shipped_date = app_db.Column(app_db.DateTime, nullable=True)
Ejemplo n.º 7
0
from datetime import datetime
from productsite.database import app_db
#  from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
#  from flask import current_app

cart = app_db.Table('cart',
                    app_db.Column('product_id', app_db.Integer, app_db.ForeignKey('product.id'), primary_key=True),
                    app_db.Column('user_id', app_db.Integer, app_db.ForeignKey('user.id'), primary_key=True),
                    app_db.Column('quantity', app_db.Integer, nullable=False, default=1)
                    )

rating = app_db.Table('rating',
                      app_db.Column('user_id', app_db.Integer, app_db.ForeignKey('user.id'), primary_key=True),
                      app_db.Column('product_id', app_db.Integer, app_db.ForeignKey('product.id'), primary_key=True),
                      app_db.Column('rating', app_db.Integer, nullable=False, default=3),
                      )


class Product(app_db.Model):
    id = app_db.Column(app_db.Integer, primary_key=True)
    title = app_db.Column(app_db.String(120), nullable=False)
    description = app_db.Column(app_db.Text, nullable=False, default="No Description")
    quantity = app_db.Column(app_db.Integer, nullable=False, default=0)
    price = app_db.Column(app_db.Float, nullable=False, default=0.0)
    expect_stock_quantity = app_db.Column(app_db.Integer, nullable=False, default=0)
    flag_out_of_stock = app_db.Column(app_db.Boolean, nullable=False, default=False)
    expect_restock_date = app_db.Column(app_db.DateTime, nullable=True)
    category_id = app_db.Column(app_db.Integer, app_db.ForeignKey('product_category.id'), nullable=False)
    category = app_db.relationship('ProductCategory', backref=app_db.backref('product', lazy=True))

    def __repr__(self):
Ejemplo n.º 8
0
from datetime import datetime
from productsite import app_login_manager
from productsite.database import app_db
from flask_login import UserMixin


@app_login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))

uac = app_db.Table('user_access_control',
                   app_db.Column('user_id', app_db.Integer, app_db.ForeignKey('user.id'), primary_key=True),
                   app_db.Column('user_access_routes_id', app_db.Integer, app_db.ForeignKey('user_access_routes.id'),
                                 primary_key=True)
                   )


class User(app_db.Model, UserMixin):
    """
    User account model
    """
    id = app_db.Column(app_db.Integer, primary_key=True)
    email = app_db.Column(app_db.String(120), unique=True, nullable=False)
    first_name = app_db.Column(app_db.String(120), unique=True, nullable=False)
    last_name = app_db.Column(app_db.String(120), unique=True, nullable=False)
    password = app_db.Column(app_db.String(60), nullable=False)
    verified_email = app_db.Column(app_db.Boolean, nullable=False, default=False)
    create_date = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow)
    flag_admin = app_db.Column(app_db.Boolean, nullable=False, default=False)
    flag_cs = app_db.Column(app_db.Boolean, nullable=False, default=False)
    uac = app_db.relationship('UserAccessRoutes', secondary=uac, lazy='subquery',
Ejemplo n.º 9
0
from datetime import datetime
from productsite.database import app_db

order_part = app_db.Table(
    'order_part',
    app_db.Column('product_id',
                  app_db.Integer,
                  app_db.ForeignKey('product.id'),
                  primary_key=True),
    app_db.Column('order_id',
                  app_db.Integer,
                  app_db.ForeignKey('customer_order.id'),
                  primary_key=True),
    app_db.Column('quantity', app_db.Integer, nullable=False, default=1))


class CustomerOrder(app_db.Model):
    """
    status can be: open, reviewing, working, shipped, closed
    """
    id = app_db.Column(app_db.Integer, primary_key=True)
    user_id = app_db.Column(app_db.Integer,
                            app_db.ForeignKey('user.id'),
                            nullable=False)
    create_date = app_db.Column(app_db.DateTime,
                                nullable=False,
                                default=datetime.utcnow)
    status = app_db.Column(app_db.String(10), nullable=False, default="open")
    last_status_date = app_db.Column(app_db.DateTime,
                                     nullable=False,
                                     default=datetime.utcnow)