示例#1
0
class Users(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20))
    email = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(50))
    name = db.Column(db.String(250))
    birth_date = db.Column(db.Date())
    gender = db.Column(db.String(1))
    address = db.Column(db.String(250))
    push_notification_token = db.Column(db.Text(), nullable=True)
    type = db.Column(db.Integer, db.ForeignKey('user_type.id'))
    program_id = db.Column(db.Integer,
                           db.ForeignKey('program.id'),
                           nullable=True)
    image_path = db.Column(db.Text(), nullable=True)
    course_sections = db.relationship('CourseSectionStudents',
                                      cascade="save-update, merge, delete")

    def set_fields(self, fields):
        self.username = fields.get('username')
        self.email = fields.get('email')
        self.password = self.password if self.password else fields.get(
            'password')
        self.name = fields.get('name')
        self.gender = fields.get('gender')
        self.address = fields.get('address')
        self.birth_date = datetime.datetime.strptime(
            fields.get('birth_date'),
            "%m-%d-%Y").date() if fields.get('birth_date') else None
        self.program_id = fields.get('program_id')
        self.type = self.type if self.type else fields.get('type')

    def save_image(self, file):
        file_name, _format = str(file.filename).rsplit('.', 1)
        user_name, domain = str(self.email).split('@', maxsplit=1)

        if not _format in settings.ALLOWED_EXTENSIONS:
            _format = 'jpg'

        files = {'image_file': file}
        headers = {"enctype": "multipart/form-data"}

        r = requests.post(
            'http://eliakimdjango.pythonanywhere.com/save_profile_image',
            files={
                'file':
                (user_name + str(random.randint(1000, 10000)) + '.' + _format,
                 file, headers, {
                     'Expires': '0'
                 })
            },
            data={'old_file_path': self.image_path})
        # r = requests.post('http://127.0.0.1:2000/save_profile_image',
        #                   files={'file': (self.username + str(random.randint(1000, 10000)) + '.' + _format, file,
        #                                   headers, {'Expires': '0'})},
        #                   data={'old_file_path': self.image_path})
        if r.status_code == 200:
            self.image_path = r.json()['result']
            return True
示例#2
0
class Search(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    q = db.Column(db.String(1023), nullable=False, default=True)
    center = db.Column(db.String(127), nullable=True)
    description = db.Column(db.Text(16383), nullable=True)
    description_508 = db.Column(db.Text(16383), nullable=True)
    location = db.Column(db.String(127), nullable=True)
    media_type = db.Column(db.String(127), nullable=True)
    nasa_id = db.Column(db.String(127), nullable=True)
    photographer = db.Column(db.String(127), nullable=True)
    secondary_creator = db.Column(db.String(127), nullable=True)
    title = db.Column(db.String(1023), nullable=True)
    year_start = db.Column(db.Integer, nullable=True)
    year_end = db.Column(db.Integer, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
    timestamp = db.Column(db.DateTime, nullable=False, default=datetime.now())
示例#3
0
class WallMessages(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    date = db.Column(db.Integer)
    sender = db.Column(db.Integer, db.ForeignKey("users.id"))
    destination = db.Column(db.Integer,
                            db.ForeignKey("user_type_destinations.id"))
    param_value = db.Column(db.Integer())
    message = db.Column(db.Text())

    def set_fields(self, fields):
        self.date = fields['date']
        self.sender = fields['sender']
        self.destination = fields['user_type_destination_id']
        self.param_value = fields['parameter']
        self.message = format_urls_in_text(fields['message'])

    def get_sender(self):
        return Users.query.filter_by(id=self.sender).all()

    def get_destinations(self):
        _dict = {}
        query = UserTypeDestinations.query.filter_by(
            id=self.destination).first().users_query
        query = str(query).replace('$', str(self.param_value))
        exec(query, _dict)
        return _dict['users']
示例#4
0
class UserTypeDestinations(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50))
    param_values_service = db.Column(db.String(250))
    users_query  = db.Column(db.Text())
    group = db.Column(db.Text())
    group_module = db.Column(db.String(250))
    user_type_destinations_user_types = db.relationship('UserTypeDestinationsUserType', cascade="save-update, merge, delete")


    def set_fields(self, fields):
        self.name = fields['name']
        self.param_values_service = fields['param_values_service']
        self.users_query = fields['users_query']
        self.group = fields['group']
        self.group_module = fields['group_module']
示例#5
0
class StreamResult(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(1023), nullable=True)
    center = db.Column(db.String(127), nullable=True)
    last_updated = db.Column(db.DateTime, nullable=True, default=datetime.now())
    thumb_img = db.Column(db.String(1023), nullable=False)
    description = db.Column(db.Text(16383), nullable=True)
    nasa_id = db.Column(db.String(1023), nullable=False, unique=True)
示例#6
0
class Segmentation(db.Model):
    __tablename__ = "segmentation"

    id = db.Column("id", db.Integer(), primary_key=True)

    data_id = db.Column(
        "data_id", db.Integer(), db.ForeignKey("data.id"), nullable=False
    )

    start_time = db.Column("start_time", db.Float(), nullable=False)

    end_time = db.Column("end_time", db.Float(), nullable=False)

    transcription = db.Column("transcription", db.Text(), nullable=True)

    created_at = db.Column(
        "created_at", db.DateTime(), nullable=False, default=db.func.now()
    )

    last_modified = db.Column(
        "last_modified",
        db.DateTime(),
        nullable=False,
        default=db.func.now(),
        onupdate=db.func.utc_timestamp(),
    )

    values = db.relationship(
        "LabelValue", secondary=annotation_table, back_populates="segmentations",
    )

    def set_start_time(self, start_time):
        self.start_time = start_time

    def set_end_time(self, end_time):
        self.end_time = end_time

    def set_transcription(self, transcription):
        self.transcription = transcription

    def to_dict(self):
        return {
            "start_time": self.start_time,
            "end_time": self.end_time,
            "transcription": self.transcription,
            "created_at": self.created_at,
            "last_modified": self.last_modified,
        }
示例#7
0
class BlogPost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(128), unique=True)
    slug = db.Column(db.String(128), unique=True, index=True)

    content = db.Column(db.Text())
    created = db.Column(db.DateTime,
                        server_default=db.func.now(),
                        onupdate=db.func.now())
    modified = db.Column(db.DateTime, server_default=db.func.now())

    category_id = db.Column(db.Integer,
                            db.ForeignKey('blog_category.id'),
                            index=True)
    category = db.relationship(lambda: BlogCategory,
                               backref=db.backref('posts', lazy='dynamic'))

    excerpt = db.Column(db.Text, nullable=True)

    tags = db.Column(ARRAY(db.String(64)), nullable=True, index=True)

    def __repr__(self):
        return self.title
示例#8
0
class Data(db.Model):
    __tablename__ = "data"

    id = db.Column("id", db.Integer(), primary_key=True)

    project_id = db.Column(
        "project_id", db.Integer(), db.ForeignKey("project.id"), nullable=False
    )

    assigned_user_id = db.Column(
        "assigned_user_id", db.Integer(), db.ForeignKey("user.id"), nullable=False
    )

    filename = db.Column("filename", db.String(100), nullable=False, unique=True)

    original_filename = db.Column("original_filename", db.String(100), nullable=False)

    reference_transcription = db.Column(
        "reference_transcription", db.Text(), nullable=True
    )

    is_marked_for_review = db.Column(
        "is_marked_for_review", db.Boolean(), nullable=False, default=False
    )

    created_at = db.Column(
        "created_at", db.DateTime(), nullable=False, default=db.func.now()
    )

    last_modified = db.Column(
        "last_modified",
        db.DateTime(),
        nullable=False,
        default=db.func.now(),
        onupdate=db.func.utc_timestamp(),
    )

    project = db.relationship("Project")
    assigned_user = db.relationship("User")
    segmentations = db.relationship("Segmentation", backref="Data")

    def update_marked_review(self, marked_review):
        self.is_marked_for_review = marked_review

    def set_segmentations(self, segmentations):
        self.segmentations = segmentations

    def to_dict(self):
        return {
            "original_filename": self.original_filename,
            "filename": self.filename,
            "url": f"/audios/{self.filename}",
            "reference_transcription": self.reference_transcription,
            "is_marked_for_review": self.is_marked_for_review,
            "created_at": self.created_at,
            "last_modified": self.last_modified,
            "assigned_user": {
                "id": self.assigned_user_id,
                "username": self.assigned_user.username,
                "role": self.assigned_user.role.role,
            },
        }