예제 #1
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(80), unique=True, nullable=False)

    def __repr__(self):
        return '<User %r>' % self.user_id
예제 #2
0
class Objective(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    points = db.Column(db.Integer, nullable=False)
    description = db.Column(db.String, nullable=False)

    def __repr__(self):
        return f'<Objective "{self.description}" for {self.points} points>'
예제 #3
0
class Tag(db.Model):

    __tablename__ = "tags"

    tag_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    gratitude_id = db.Column(db.Integer,
                             db.ForeignKey('gratitudes.gratitude_id'),
                             nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.user_id'),
                        nullable=False)

    gratitude = db.relationship('Gratitude', backref='tags')
    user = db.relationship('User', backref="tags")

    @classmethod
    def add_new_tag(cls, gratitude_id, user_id):
        """Adds new tag to the db. """

        tag = Tag(gratitude_id=gratitude_id, user_id=user_id)

        db.session.add(tag)
        db.session.commit()

        return tag
예제 #4
0
class Course(db.Model):
    __tablename__ = 'course'
    Id = db.Column(db.VARCHAR(10), primary_key=True)
    Name = db.Column(db.VARCHAR(255))
    Modules = db.Column(db.VARCHAR(255))
    start_date = db.Column(db.DATETIME)
    end_date = db.Column(db.DATETIME)
예제 #5
0
class Chat(db.Model):
    """Almacén clave/valor para un chat concreto

    Note:
        Si se quiere guardar un valor para todos los chats, usar el valor Id=0

    El objetivo es poder guardar variables de estado de un chat (privado o grupo).Se almacena
    también la fecha de guardado o actualización.
    """
    __tablename__ = 'chat'
    id = db.Column(db.Integer, primary_key=True)
    chat = db.Column(db.BigInteger, nullable=False)
    key = db.Column(db.String(255), nullable=False)
    value = db.Column(db.Text, nullable=False)
    created_at = db.Column(db.DateTime, nullable=False)

    @staticmethod
    def set_config(chat, key, value):
        """Guarda un valor

        Args:
            :param chat: Id. del chat
            :param key: Clave del dato
            :param value: Valor del dato

        Returns:
            :return: Instancia de Chat con el valor almacenado
        """
        record = db.session.query(Chat).filter_by(chat=chat, key=key).first()

        if record is None:
            record = Chat(chat=chat,
                          key=key,
                          value=value,
                          created_at=datetime.now())
            db.session.add(record)
        else:
            record.value = value
            record.created_at = datetime.now()

        db.session.commit()
        db.session.close()

        return record

    @staticmethod
    def get_config(chat, key):
        """ Recupera un valor

        Args:
            :param chat: Id. del chat
            :param key: Clave del valor a recuperar

        Returns:
            :return: Instancia de Chat que coincide con la clave o None si no existe
        """
        record = db.session.query(Chat).filter_by(chat=chat, key=key).first()
        db.session.close()

        return record
예제 #6
0
class Note(db.Model):
    note_title = db.Column(db.String, primary_key=True)
    note = db.Column(db.String, nullable=False)
    book_id = db.Column(db.Integer,
                        db.ForeignKey('book.book_id'),
                        nullable=False)

    def __repr__(self):
        return '<Note %r : %r %r>' % (self.note_title, self.note, self.book_id)

    def to_dict(self):
        """
        Method to convert a Note object to a dict object representation
        :return: dict representation of a Note
        """
        a_dict = {
            'note_title': self.note_title,
            'note': self.note,
            'book_id': self.book_id
        }

        return a_dict

    def update(self, **kwargs):
        """
        Method to update a Note's attributes
        :param kwargs: A dict of valid key-value pairs
        :return: None
        """
        for key, value in kwargs.items():
            setattr(self, key, value)
예제 #7
0
class Note(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(60), nullable=False)
    notebook_id = db.Column(db.Integer,
                            db.ForeignKey("notebook.id"),
                            nullable=False)
    notebook = db.relationship("Notebook", back_populates="notes")
예제 #8
0
class Comment(db.Model):
    """Class for user comments on gratitudes."""

    __tablename__ = "comments"

    comment_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    gratitude_id = db.Column(db.Integer,
                             db.ForeignKey('gratitudes.gratitude_id'),
                             nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.user_id'),
                        nullable=False)

    gratitude = db.relationship('Gratitude', backref='comments')
    user = db.relationship('User', backref='users')

    @classmethod
    def add_new_comment(cls, text, gratitude_id, user_id):
        """Adds new comment to the db."""

        comment = Comment(text=text,
                          gratitude_id=gratitude_id,
                          user_id=user_id)

        db.session.add(comment)
        db.session.commit()

        return comment
예제 #9
0
class Transition(db.Model, TimestampMixin):
    __tablename__ = 'transitions'
    __table_args__ = {'sqlite_autoincrement': True}
    id = db.Column(db.BigInteger, primary_key=True)
    settlement_id = db.Column(db.BigInteger, db.ForeignKey('settlement.id'), nullable=False)
    product_id = db.Column(db.BigInteger, db.ForeignKey('product.id'), nullable=False)
    price = db.Column(db.Integer, nullable=False)
예제 #10
0
class Gratitude(db.Model):
    """Creating class for gratitude entries."""

    __tablename__ = "gratitudes"

    gratitude_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    entry_id = db.Column(db.Integer,
                         db.ForeignKey('entries.entry_id'),
                         nullable=False)

    entry = db.relationship('Entry', backref='gratitudes')

    @classmethod
    def add_new_gratitude(cls, text, entry_id):
        """Adds new gratitude to the db. """

        gratitude = Gratitude(text=text, entry_id=entry_id)

        db.session.add(gratitude)
        db.session.commit()

        return gratitude

    @classmethod
    def get_gratitudes_by_entry(cls, entry_id):
        """Returns all gratitudes associated with a given entry."""

        return Gratitude.query.filter_by(entry_id=entry_id).all()
예제 #11
0
파일: db.py 프로젝트: AlecJ/rpgmanager
class RPGManagerCampaign(db.Model):
    __tablename__ = 'rpg_manager_campaign'

    id = db.Column(db.Integer(), primary_key=True)
    room_code = db.Column(db.String(4), nullable=False, unique=True)

    players = db.relationship('RPGManagerCharacter',
                              backref='campaign',
                              order_by="RPGManagerCharacter.id.desc()")

    name = db.Column(db.String(100))
    region = db.Column(db.String(100))
    day = db.Column(db.Integer())
    party_level = db.Column(db.Integer())
    money_ratio = db.Column(db.Integer(), default=10)
    notes = db.Column(db.String(3000))
    created_time = db.Column(db.TIMESTAMP(timezone=True), nullable=False)
    last_read_time = db.Column(db.TIMESTAMP(timezone=True), nullable=False)

    def row_as_dict(self):
        return {
            "id": self.room_code,
            "name": self.name,
            "region": self.region,
            "day": self.day,
            "party_level": self.party_level,
            "money_ratio": self.money_ratio,
            "notes": self.notes,
            "characters": [player.row_as_dict() for player in self.players]
        }

    def __repr__(self):
        return "RPGManagerCampaign(id={}, room={}, name={})".format(
            self.id, self.room_code, self.name)
예제 #12
0
class ConcreteDimension(Dimension):
    id = db.Column(db.Integer, db.ForeignKey(Dimension.id), primary_key=True)

    __tablename__ = 'concrete_dimension'
    __mapper_args__ = {'polymorphic_identity': __tablename__}

    # columns
    name_translations = db.Column(MUTABLE_HSTORE)
    name = translation_hybrid(name_translations)
    original_language = db.Column(db.Enum(BabelLanguage), nullable=False)

    shadow = False

    def __init__(self, name: str, **kwargs):
        self.original_language = g._language
        super(ConcreteDimension, self).__init__(name=name, **kwargs)
        self.reference_id = SurveyBase.generate_reference_id(self)

    @staticmethod
    def from_shadow(shadow):
        d = ConcreteDimension("")
        d.name_translations = shadow.name_translations
        d.original_language = shadow.original_language
        d.randomize_question_order = shadow.randomize_question_order
        d.owners = shadow.owners
        d.reference_id = shadow.reference_id

        for s_question in shadow.questions:
            c_question = ConcreteQuestion.from_shadow(s_question)
            d.questions.append(c_question)

        return d
예제 #13
0
class Resultdb51job(db.Model):
    __tablename__ = 'resultdb_51job'

    taskid = db.Column(nullable=False, primary_key=True)
    url = db.Column(nullable=False)
    result = db.Column(nullable=False)
    updatetime = db.Column(nullable=False)
예제 #14
0
class telegramGroup(db.Model):
    __tablename__ = 'telegramGroup'
    __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4'}
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.VARCHAR(255))
    photo = db.Column(db.VARCHAR(255))
    username = db.Column(db.VARCHAR(255))
    date = db.Column(db.DateTime(6))

    def __init__(self, id, title, photo, username, date):
        self.id = id
        self.title = title
        self.photo = photo
        self.username = username
        self.date = date

    def __repr__(self):
        return "<teleGramGroup %r>" % self.username

    def to_json(self):
        item = self.__dict__
        if "_sa_instance_state" in item:
            del item["_sa_instance_state"]
        item['photo'] = 'http://localhost:5000/download?filepath=' + item[
            'photo']
        item['date'] = item['date'].strftime("%Y-%m-%d-%H")
        return item
예제 #15
0
class User(db.Model):
    __tablename__ = 'user'  # 指定对应数据库表user
    userName = db.Column(db.VARCHAR(20))
    password = db.Column(db.VARCHAR(20))
    phoneNumber = db.Column(db.VARCHAR(20), primary_key=True)
    headPortrait = db.Column(db.VARCHAR(100))

    # userID=db.Column(db.Integer)
    # TODO 添加邮箱、手机号属性
    def __init__(self, userName, password, phoneNumber, headPortrait):
        self.userName = userName
        self.password = password
        self.phoneNumber = phoneNumber
        self.headPortrait = headPortrait

    def __repr__(self):
        return '<User %r>' % self.userName

    def to_json(self):
        """将实例对象转化为json"""
        item = self.__dict__
        if "_sa_instance_state" in item:
            del item["_sa_instance_state"]
        item[
            'headPortrait'] = 'http://localhost:5000/download?filepath=' + item[
                'headPortrait']
        return item
class BookCopy(db.Model):
    book_copy_id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer,
                        db.ForeignKey('book.book_id'),
                        nullable=False)
    is_checked_out = db.Column(db.Boolean, nullable=False, default=False)

    def __repr__(self):
        return (
            "<BookCopy(book_copy_id='%s',book_id='%s',is_checked_out='%s'>" %
            (self.book_copy_id, self.book_id, self.is_checked_out))

    def to_dict(self):
        """
        Method to convert a book copy to a python dictionary data object
        :return: dict
        """
        print('Book Copy to_dict')
        copy_dict = {
            'book_copy_id': self.book_copy_id,
            'book_id': self.book_id,
            'is_checked_out': self.is_checked_out,
        }
        return copy_dict

    def update(self, **kwargs):
        """
        Method to update a book copy's attributes
        :param kwargs: A dict of valid key-value pairs
        :return: None
        """
        print('BookCopy.update()')
        for key, value in kwargs.items():
            setattr(self, key, value)
예제 #17
0
class Module(db.Model):
    __tablename__ = 'module'
    Id = db.Column(db.VARCHAR(10), primary_key=True)
    Name = db.Column(db.VARCHAR(255))
    start_date = db.Column(db.DATETIME)
    end_date = db.Column(db.DATETIME)
    teacher_id = db.Column(db.Integer)
예제 #18
0
class Vote(Base):
    account_id = db.Column(db.Integer,
                           db.ForeignKey('account.id'),
                           nullable=True)
    issue_id = db.Column(db.Integer, db.ForeignKey('issue.id'), nullable=True)

    cast = db.Column(db.Boolean)
예제 #19
0
class Attraction(db.Model):
    
    __tablename__ = 'attractions'
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    category = db.Column(db.String(255))
    description = db.Column(db.Text)
    address = db.Column(db.Text)
    transport = db.Column(db.Text)
    mrt = db.Column(db.String(255))
    latitude = db.Column(db.Float)
    longitude = db.Column(db.Float)
    images = db.Column(db.Text)
    
    db_attraction_booking = db.relationship("Booking", backref="attractions", lazy='dynamic')
    db_attraction_collection = db.relationship("Collection", backref="attractions", lazy='dynamic')
    
    
    def __init__(self, name, category, description, address, transport, mrt, latitude, longitude, images):
        self.name = name
        self.category = category
        self.description = description
        self.address = address
        self.transport = transport
        self.mrt = mrt
        self.latitude = latitude
        self.longitude = longitude
        self.images = images
예제 #20
0
class Horario(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    horario_escolar_id = db.Column(db.Integer,
                                   db.ForeignKey("horario_escolar.id"),
                                   nullable=False)

    def __init__(self, horario_escolar_id):
        self.horario_escolar_id = horario_escolar_id
예제 #21
0
class Room_User(db.Model):
    __tablename__ = 'room'
    room_id = db.Column(db.Integer)
    user_id = db.Column(db.Integer)

    def __init__(self, room_id, user_id):
        self.room_id = room_id
        self.user_id = user_id
예제 #22
0
class Question(Base):
    text = db.Column(db.String(128), nullable=False)

    issue_id = db.Column(db.Integer, db.ForeignKey('issue.id'), nullable=True)
    answer_id = db.Column(db.Integer, db.ForeignKey('answer.id'), nullable=True)

    options = db.relationship("Option")
    responses = db.relationship("Response")
예제 #23
0
class Answer(Base):
    text = db.Column(db.String(128), nullable=False)

    # currently one-to-one with question, possibly should be many-to-many with question?
    issue_id = db.Column(db.Integer, db.ForeignKey('issue.id'), nullable=True)
    option_id = db.Column(db.Integer,
                          db.ForeignKey('option.id'),
                          nullable=True)
예제 #24
0
class Settlement(db.Model, TimestampMixin):
    __tablename__ = 'settlement'
    __table_args__ = {'sqlite_autoincrement': True}
    id = db.Column(db.BigInteger, primary_key=True)
    gift_code_id = db.Column(db.BigInteger,
                             db.ForeignKey('gift_code.id'),
                             nullable=False)
    transition = db.relationship('Transition')
예제 #25
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return '<Category %r>' % self.name
예제 #26
0
class Member(db.Model):
    __tablename__ = 'Member'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(50), nullable=False)
    time = db.Column(db.DateTime,
                     default=datetime.datetime.now,
                     nullable=False)
예제 #27
0
class OAuth2AuthorizationCode(db.Model, SerializerMixin,
                              OAuth2AuthorizationCodeMixin):
    __tablename__ = "oauth2_code"

    id = db.Column(db.String, primary_key=True)
    user_id = db.Column(db.String, db.ForeignKey("users.id",
                                                 ondelete="CASCADE"))

    user = db.relationship("User")
예제 #28
0
class Todo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    task = db.Column(db.String(50))

    def __init__(self, task):
        self.task = task

    def __repr__(self):
        return '<Todo %r>' % self.task
예제 #29
0
class User(Base):
    __tablename__ = 'user'

    Id = Column(db.Integer, primary_key=True)
    email = db.Column(db.VARCHAR(255))
    password = db.Column(db.VARCHAR(255))
    role = db.Column(db.Integer)
    student_id = db.Column(db.Integer)
    teacher_id = db.Column(db.Integer)
예제 #30
0
class Respuesta(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    sugerencia_id = db.Column(db.Integer,
                              db.ForeignKey("sugerencia.id"),
                              nullable=False)
    contenido = db.Column(db.String(500), nullable=False)

    def __init__(self, sugerencia_id, contenido):
        self.sugerencia_id = sugerencia_id
        self.contenido = contenido