Ejemplo n.º 1
0
class Classroom(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False)
    desc = db.Column(db.String(80), nullable=True)
    code = db.Column(db.String(CLASS_CODE_LENGTH), nullable=False, unique=True)

    teacher_id = db.Column(db.Integer, db.ForeignKey("teacher.id"))
    student_ids = db.Column(db.Integer, db.ForeignKey("student.id"))

    assignments = db.relationship("Assignment", backref="classroom", lazy=True)

    def __init__(self, name, desc, teacher):
        self.name = name
        self.desc = desc
        self.code = self.generate_class_code()
        self.teacher = teacher

    def generate_class_code(self):
        code = "".join(choices(ascii_letters, k=CLASS_CODE_LENGTH))
        while True:
            if Classroom.query.filter_by(code=code).first() is None:
                break
            code = "".join(choices(ascii_letters, k=CLASS_CODE_LENGTH))
        return code

    def enroll_student(self, student):
        self.students.append(student)

    def remove_student(self, student):
        if student in self.students:
            self.students.remove(student)
            return True
        return False
Ejemplo n.º 2
0
class Medicamento(db.Model):
    __tablename__ = "Medicamento"
    idMedicamento = db.Column(db.Integer, primary_key=True)
    nombre = db.Column(db.String(45), unique=True)
    cantidad = db.Column(db.Integer)
    porcion = db.Column(db.Float)
    descripcion = db.Column(db.String(250))
    fechaE = db.Column(db.Date)
    fechaV = db.Column(db.Date)
    idProveedor = db.Column('idProveedor', db.Integer,
                            db.ForeignKey("Proveedor.idProveedor"))
    idUsuario = db.Column('idUsuario', db.Integer,
                          db.ForeignKey("Usuario.idUsuario"))
    precio = db.Column(db.Float)
    imagen = db.Column(db.String(300))
    detallePedido = relationship("DetallePedido", backref="Medicamento")

    def __init__(self, idProveedor, idUsuario, nombre, cantidad, porcion,
                 descripcion, fechaE, fechaV, precio, imagen):
        self.idProveedor = idProveedor
        self.idUsuario = idUsuario
        self.nombre = nombre
        self.cantidad = cantidad
        self.porcion = porcion
        self.descripcion = descripcion
        self.fechaE = fechaE
        self.fechaV = fechaV
        self.precio = precio
        self.imagen = imagen

    def __repr__(self):
        return ''
Ejemplo n.º 3
0
class Project(db.Model):
    """Project Class contains link to the user that interact with this project,
        the top level tasks related to id"""
    id = db.Column(db.Integer, primary_key=True)
    changed_at = db.Column(
        db.DateTime(), default=datetime.now(), onupdate=datetime.now())
    name = db.Column(db.String(80))
    description = db.Column(db.String(250))
    tasks = db.relationship('Task', secondary=project_tasks, lazy='subquery',
                            backref=db.backref('project', lazy=True))
    users = db.relationship('User', secondary=project_users, lazy='subquery',
                            backref=db.backref('project', lazy=True))

    def add_task(self, name, description, end_time):
        """Adds a new Task to this Project"""
        self.tasks.append(
            Task(name=name, description=description, end_time=end_time)
        )
        db.session.update(self)
        db.session.commit()

    def add_user(self, em_usname):
        """Adds existing user to thihs project"""
        user = User.query.filter_by(email=em_usname).first()
        if not user:
            user = User.query.filter_by(username=em_usname).first()
        if user:
            self.users.append(user)
            db.session.update(self)
            db.session.commit()
        else:
            raise Exception()
Ejemplo n.º 4
0
class Question(db.Model):
    __tablename__ = 'questions'

    def __init__(self, title, text):
        self.title = title
        self.text = text

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), nullable=False)
    text = db.Column(db.String(500), nullable=False)
    timestamp = db.Column(db.DateTime(),
                          nullable=False,
                          server_default=func.now())

    topic_id = db.Column(db.Integer,
                         db.ForeignKey('topics.id'),
                         nullable=False)
    topic = db.relationship('Topic', uselist=False, back_populates='questions')

    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    user = db.relationship('User', back_populates='questions')

    answers = db.relationship('Answer',
                              back_populates='question',
                              order_by=Answer.id)

    def serialize(self):
        return {'id': self.id, 'title': self.title, 'text': self.text, \
            'timestampStr': self.timestamp.strftime('%d/%m/%Y, %H:%M:%S')}
Ejemplo n.º 5
0
class Subject(db.Model):
    __tablename__ = 'subjects'

    def __init__(self, name, description, student_year_id, module_id):
        self.name = name
        self.description = description
        self.student_year_id = student_year_id
        self.module_id = module_id

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    description = db.Column(db.String(200))

    student_year_id = db.Column(db.Integer, db.ForeignKey('student_years.id'))
    student_year = db.relationship('StudentYear',
                                   uselist=False,
                                   back_populates='subject')

    # TODO jedan predmet moze na vise modula
    module_id = db.Column(db.Integer, db.ForeignKey('modules.id'))
    module = db.relationship('Module', uselist=False, back_populates='subject')

    topics = db.relationship('Topic', back_populates='subject')
    proffessors = db.relationship('User',
                                  secondary=ProffessorSubject,
                                  back_populates='subjects')
    consultations = db.relationship('Consultation', back_populates='subject')

    def serialize(self):
        return {'id': self.id, 'name': self.name, 'description': self.description, \
                'studentYearId': self.student_year_id, 'moduleId': self.module_id}
Ejemplo n.º 6
0
class Notification(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.ForeignKey('user.id', ondelete="SET NULL"))
    message = db.Column(db.String(300), nullable=False)
    notif_type = db.Column(db.String(1), nullable=False)
    link = db.Column(db.String(64), nullable=False)
    read = db.Column(db.Boolean, default=False, nullable=False)
    timestamp = db.Column(db.DateTime, nullable=False)
Ejemplo n.º 7
0
class Post(db.Model):
    pid = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.ForeignKey('user.id', ondelete="SET NULL"))
    lid = db.Column(db.ForeignKey('location.id'), nullable=False)
    time_posted = db.Column(db.DateTime, nullable=False)
    photo = db.Column(db.BINARY(16), nullable=False)
    caption = db.Column(db.String(300), nullable=False)
    hashtags = db.Column(db.String(200))
Ejemplo n.º 8
0
class SystemMergeField(db.Model):
    __tablename__ = "system_merge_field"
    id = db.Column(db.Integer, primary_key=True)
    tag = db.Column(db.String(50))
    name = db.Column(db.String(200))
    description = db.Column(db.Text, nullable=True)
    created = db.Column(db.DateTime)

    def __init__(self):
        self.created = datetime.datetime.now()
Ejemplo n.º 9
0
class GameLog(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    grid = db.Column(db.String(10000))
    paths = db.Column(db.String(1000))
    error_flag = db.Column(db.Boolean)
    req_time = db.Column(db.DateTime, default=datetime.datetime.now())
    res_duration = db.Column(db.Float)

    def __repr__(self):
        return '<Log %r>' % self.req_time.strftime("%d-%m-%Y (%H:%M:%S)")
Ejemplo n.º 10
0
class ListMergeField(db.Model):
    __tablename__ = "list_merge_field"
    id = db.Column(db.Integer, primary_key=True)
    list_id = db.Column(db.Integer, db.ForeignKey('list.id'))
    mailchimp_id = db.Column(db.Integer)
    tag = db.Column(db.String(20))
    name = db.Column(db.String(200))
    type = db.Column(db.String(20))
    required = db.Column(db.Boolean, default=True)
    default_value = db.Column(db.String(200), nullable=True)
    public = db.Column(db.Boolean, default=True)
    display_order = db.Column(db.Integer, default=0)
    choices = db.relationship("ListMergeFieldChoice",
                              lazy="dynamic",
                              cascade="all,delete")
    size = db.Column(db.Integer, default=0)
    default_country = db.Column(db.String(5), nullable=True)
    phone_format = db.Column(db.String(50), nullable=True)
    date_format = db.Column(db.String(50), nullable=True)

    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self):
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
class DataView_Open(db.Model):
    __tablename__ = "data_view_open"
    id = db.Column(db.Integer, primary_key=True)
    brand_id = db.Column(db.Integer, db.ForeignKey('brand.id'))
    campaign_id = db.Column(db.Integer, db.ForeignKey("campaign.id"))
    email_id = db.Column(db.String(50))
    email_address = db.Column(db.String(200))
    unique_email_id = db.Column(db.String(200))
    list_id = db.Column(db.Integer, db.ForeignKey("list.id"))
    event_date = db.Column(db.TIMESTAMP)
    campaign_title = db.Column(db.String(200), nullable=True)
Ejemplo n.º 12
0
class Town(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(500), unique=True)
    region = db.Column(db.String(500))

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

    def __repr__(self):
        return '<Town %r>' % self.name
Ejemplo n.º 13
0
class SegmentCondition(db.Model):
    __tablename__ = "segment_condition"
    id = db.Column(db.Integer, primary_key=True)
    segment_id = db.Column(db.Integer, db.ForeignKey("segment.id"))
    type = db.Column(db.String(50))
    op = db.Column(db.String(50))
    field = db.Column(db.String(100))
    value = db.Column(db.String(200))
    created = db.Column(db.DateTime)

    def __init__(self):
        self.created = datetime.datetime.now()
class ExportField(db.Model):
    __tablename__ = "export_field"
    id = db.Column(db.Integer, primary_key=True)
    export_definition_id = db.Column(db.Integer, db.ForeignKey("export_definition.id"))
    field_name = db.Column(db.String(200))
    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self):
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
Ejemplo n.º 15
0
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(500))
    town = db.Column(db.Integer, db.ForeignKey('town.id'))
    status = db.Column(db.String(500), default='alive')

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

    def __repr__(self):
        return '<Person %r>' % self.name
class TemplateCategory(db.Model):
    __tablename__ = "template_category"
    id = db.Column(db.Integer, primary_key=True)
    brand_id = db.Column(db.Integer, db.ForeignKey("brand.id"))
    folder_id = db.Column(db.Integer, db.ForeignKey("folder.id"))
    name = db.Column(db.String(200))
    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self):
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
Ejemplo n.º 17
0
class ImportFieldMapping(db.Model):
    __tablename__ = "import_field_mapping"
    id = db.Column(db.Integer, primary_key=True)
    import_definition_id = db.Column(db.Integer, db.ForeignKey("import_definition.id"))
    source_field = db.Column(db.String(100))
    destination_field = db.Column(db.String(100))
    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self):
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
Ejemplo n.º 18
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    email = db.Column(db.String(120), unique=True)
    # privacy should only ever be "everyone" or "friends"
    privacy = db.Column(db.String(20))

    def __init__(self, username, email, privacy):
        self.username = username
        self.email = email
        self.privacy = privacy

    def __repr__(self):
        return '<User %r>' % self.username
Ejemplo n.º 19
0
class Estado(db.Model):
    __tablename__ = 'Estado'
    idEstado = db.Column(db.Integer, primary_key=True)
    nombreEstado = db.Column(db.String(20))
    numEstado = db.Column(db.Integer)
    zona = db.Column(db.String(10))
    usuario = relationship("Usuario", backref="Estado")

    def __init__(self, nombreEstado, numEstado, zona):
        self.nombreEstado = nombreEstado
        self.numEstado = numEstado
        self.zona = zona

    def __repr__(self):
        return ''
Ejemplo n.º 20
0
class Proveedor(db.Model):
    __tablename__ = 'Proveedor'
    idProveedor = db.Column(db.Integer, primary_key=True)
    nombre = db.Column(db.String(20), unique=True)
    rfc = db.Column(db.String(13))
    telefono = db.Column(db.String(10))
    medcamento = relationship("Medicamento", backref="Proveedor")

    def __init__(self, nombre, rfc, telefono):
        self.nombre = nombre
        self.rfc = rfc
        self.telefono = telefono

    def __repr__(self):
        return ''
class VariateCampaignCombination(db.Model):
    __tablename__ = "variate_campaign_combination"
    id = db.Column(db.Integer, primary_key=True)
    variate_campaign_id = db.Column(db.Integer, db.ForeignKey("variate_campaign.id"))
    mailchimp_id = db.Column(db.String(50))
    email_id = db.Column(db.Integer, db.ForeignKey("email.id"))
    send_time = db.Column(db.TIMESTAMP, nullable=True)
    subject_line = db.Column(db.String(200))
    from_name = db.Column(db.String(200))
    reply_to = db.Column(db.String(200))
    recipients = db.Column(db.Integer)
    created = db.Column(db.DateTime)

    def __init__(self):
        self.created = datetime.datetime.now()
Ejemplo n.º 22
0
class Task(db.Model):
    __tablename__ = 'task'

    """Task class contains subTasks"""
    id = db.Column(db.Integer, primary_key=True)
    changed_at = db.Column(
        db.DateTime(), default=datetime.now(), onupdate=datetime.now())
    name = db.Column(db.String(80))
    description = db.Column(db.String(80))
    end_time = db.Column(db.Date())
    supertask = db.Column(db.Integer, db.ForeignKey('task.id'))
    tasks = db.relationship('Task', cascade="all", backref=db.backref(
        "parent", remote_side='Task.id'))
    questionnaires = db.relationship(
        'Questionnaire', backref='taks', lazy=True)
Ejemplo n.º 23
0
class FormFieldOption(db.Model):
    __tablename__ = "form_field_option"
    id = db.Column(db.Integer, primary_key=True)
    form_field_id = db.Column(db.Integer, db.ForeignKey("form_field.id"))
    value = db.Column(db.String(200))
    label = db.Column(db.String(200))

    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self):
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
Ejemplo n.º 24
0
class ListMergeFieldChoice(db.Model):
    __tablename__ = "list_merge_field_choice"
    id = db.Column(db.Integer, primary_key=True)
    list_merge_field_id = db.Column(db.Integer,
                                    db.ForeignKey("list_merge_field.id"))
    choice = db.Column(db.String(200))
    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self, choice=None):
        if choice != None:
            self.choice = choice
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
Ejemplo n.º 25
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), unique=True)
    name = db.Column(db.String(80), unique=True)
    password = db.Column(db.String(200), unique=False)

    def __init__(self, name, email, password):
        self.email = email.lower()
        self.name = name.lower()
        self.password = hash_password(password)

    def verify_password(self, password):
        return hash_password(password) == self.password

    def __repr__(self):
        return "<User {0} ({1})>".format(self.name, self.email)
Ejemplo n.º 26
0
class Race(db.Model):
    __tablename__ = 'races'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True, nullable=False)
    description = db.Column(db.Text)
    created_at = db.Column(db.DateTime,
                           default=datetime.datetime.utcnow,
                           nullable=False)
    updated_at = db.Column(db.DateTime)
    # This is the connection for many to many relationship between race and units
    units = db.relationship('Unit',
                            secondary=race_units,
                            backref=db.backref('race', lazy='dynamic'))

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

    @property
    def serialize(self):
        """Return object data in easily serializable format"""
        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'units': self.units,
            'created_at': dump_datetime(self.created_at)
        }

    def __repr__(self):
        return '<Race %r>' % self.name
class TrackedCampaignVariateDetail(db.Model):
    __tablename__ = "tracking_variate_detail"
    id = db.Column(db.Integer, primary_key=True)
    tracking_id = db.Column(db.Integer, db.ForeignKey("tracking.id"))
    email_name = db.Column(db.String(200))
    email_id = db.Column(db.Integer, db.ForeignKey("email.id"))
    send_time = db.Column(db.TIMESTAMP, nullable=True)
    subject_line = db.Column(db.String(200))
    from_name = db.Column(db.String(200))
    reply_to = db.Column(db.String(200))
    recipients = db.Column(db.Integer)
    is_winner = db.Column(db.Boolean, default=False)
    created = db.Column(db.DateTime)

    def __init__(self):
        self.created = datetime.datetime.now()
Ejemplo n.º 28
0
class ListSubscriberMergeField(db.Model):
    __tablename__ = "list_subscriber_merge_field"
    id = db.Column(db.Integer, primary_key=True)
    list_subscriber_id = db.Column(db.Integer,
                                   db.ForeignKey('list_subscriber.id'))
    list_merge_field_id = db.Column(
        db.Integer, db.ForeignKey('list_merge_field.id', ondelete='CASCADE'))
    value = db.Column(db.String(200))

    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self):
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
Ejemplo n.º 29
0
class ToolSetting(db.Model):
    __tablename__ = "tool_setting"
    __table_args__ = {'useexisting': True}
    id = db.Column(db.Integer, primary_key=True)
    tool_id = db.Column(db.Integer, db.ForeignKey("tool.id"))
    key = db.Column(db.String(200))
    value = db.Column(db.String(200))
    created = db.Column(db.DateTime)
    created_by = db.Column(db.String(10))
    updated = db.Column(db.DateTime)
    updated_by = db.Column(db.String(10))

    def __init__(self, key=None, value=None):
        self.key = key
        self.value = value
        self.created = datetime.datetime.now()
        self.updated = datetime.datetime.now()
Ejemplo n.º 30
0
class Cliente(db.Model):
    __tablename__ = 'Cliente'
    idCliente = db.Column(db.Integer, primary_key=True)
    idUsuario = db.Column(db.Integer, db.ForeignKey("Usuario.idUsuario"))
    rfc = db.Column(db.String(13))
    direccion = db.Column(db.String(30))
    nombreEstablecimiento = db.Column(db.String(30))
    pedido = relationship("Pedido", backref="Usuario")

    def __init__(self, idUsuario, rfc, direccion, nombre, apellidoP):
        self.idUsuario = idUsuario
        self.rfc = rfc
        self.direccion = direccion
        self.nombreEstablecimiento = nombre

    def __repr__(self):
        return ''