Ejemplo n.º 1
0
class Approval(db.Model):
    __tablename__ = 'approvals'

    term_id = db.Column(db.Integer, nullable=False, primary_key=True)
    section_id = db.Column(db.Integer, nullable=False, primary_key=True)
    approved_by_uid = db.Column(db.String, nullable=False, primary_key=True)
    approver_type = db.Column(approver_type, nullable=False)
    cross_listed_section_ids = db.Column(ARRAY(db.Integer))
    room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'), nullable=False)
    publish_type = db.Column(publish_type, nullable=False)
    recording_type = db.Column(recording_type, nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)

    def __init__(
        self,
        term_id,
        section_id,
        approved_by_uid,
        approver_type_,
        cross_listed_section_ids,
        room_id,
        publish_type_,
        recording_type_,
    ):
        self.term_id = term_id
        self.section_id = section_id
        self.approved_by_uid = approved_by_uid
        self.approver_type = approver_type_
        self.cross_listed_section_ids = cross_listed_section_ids
        self.room_id = room_id
        self.publish_type = publish_type_
        self.recording_type = recording_type_

    def __repr__(self):
        return f"""<Approval
                    term_id={self.term_id},
                    section_id={self.section_id},
                    approved_by_uid={self.approved_by_uid},
                    approver_type={self.approver_type},
                    cross_listed_section_ids={self.cross_listed_section_ids}
                    publish_type={self.publish_type},
                    recording_type={self.recording_type},
                    room_id={self.room_id},
                    created_at={self.created_at}>
                """

    @classmethod
    def create(
        cls,
        term_id,
        section_id,
        approved_by_uid,
        approver_type_,
        cross_listed_section_ids,
        publish_type_,
        recording_type_,
        room_id,
    ):
        approval = cls(
            term_id=term_id,
            section_id=section_id,
            approved_by_uid=approved_by_uid,
            approver_type_=approver_type_,
            cross_listed_section_ids=cross_listed_section_ids,
            publish_type_=publish_type_,
            recording_type_=recording_type_,
            room_id=room_id,
        )
        db.session.add(approval)
        std_commit()
        return approval

    @classmethod
    def get_approval(cls, approved_by_uid, section_id, term_id):
        return cls.query.filter_by(approved_by_uid=approved_by_uid,
                                   section_id=section_id,
                                   term_id=term_id).first()

    @classmethod
    def get_approvals_per_section_ids(cls, section_ids, term_id):
        criteria = and_(cls.section_id.in_(section_ids),
                        cls.term_id == term_id)
        return cls.query.filter(criteria).order_by(cls.created_at).all()

    @classmethod
    def get_approvals_per_term(cls, term_id):
        return cls.query.filter_by(term_id=int(term_id)).order_by(
            cls.section_id, cls.created_at).all()

    def to_api_json(self):
        return {
            'approvedBy': get_calnet_user_for_uid(app, self.approved_by_uid),
            'wasApprovedByAdmin': self.approver_type == 'admin',
            'createdAt': to_isoformat(self.created_at),
            'crossListedSectionIds': self.cross_listed_section_ids,
            'publishType': self.publish_type,
            'publishTypeName': NAMES_PER_PUBLISH_TYPE[self.publish_type],
            'recordingType': self.recording_type,
            'recordingTypeName': NAMES_PER_RECORDING_TYPE[self.recording_type],
            'room': Room.get_room(self.room_id).to_api_json()
            if self.room_id else None,
            'sectionId': self.section_id,
            'termId': self.term_id,
        }
Ejemplo n.º 2
0
class Approval(db.Model):
    __tablename__ = 'approvals'

    id = db.Column(db.Integer, nullable=False, primary_key=True)  # noqa: A003
    approved_by_uid = db.Column(db.String, nullable=False)
    approver_type = db.Column(approver_type, nullable=False)
    course_display_name = db.Column(db.String, nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    deleted_at = db.Column(db.DateTime, nullable=True)
    publish_type = db.Column(publish_type, nullable=False)
    recording_type = db.Column(recording_type, nullable=False)
    room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'), nullable=False)
    section_id = db.Column(db.Integer, nullable=False)
    term_id = db.Column(db.Integer, nullable=False)

    def __init__(
        self,
        approved_by_uid,
        approver_type_,
        course_display_name,
        publish_type_,
        recording_type_,
        room_id,
        section_id,
        term_id,
    ):
        self.approved_by_uid = approved_by_uid
        self.approver_type = approver_type_
        self.course_display_name = course_display_name
        self.publish_type = publish_type_
        self.recording_type = recording_type_
        self.room_id = room_id
        self.section_id = section_id
        self.term_id = term_id

    def __repr__(self):
        return f"""<Approval
                    id={self.id},
                    approved_by_uid={self.approved_by_uid},
                    approver_type={self.approver_type},
                    course_display_name={self.course_display_name},
                    created_at={self.created_at},
                    publish_type={self.publish_type},
                    recording_type={self.recording_type},
                    room_id={self.room_id},
                    section_id={self.section_id},
                    term_id={self.term_id}>
                """

    @classmethod
    def create(
        cls,
        approved_by_uid,
        approver_type_,
        course_display_name,
        publish_type_,
        recording_type_,
        room_id,
        section_id,
        term_id,
    ):
        approval = cls(
            approved_by_uid=approved_by_uid,
            approver_type_=approver_type_,
            course_display_name=course_display_name,
            publish_type_=publish_type_,
            recording_type_=recording_type_,
            room_id=room_id,
            section_id=section_id,
            term_id=term_id,
        )
        db.session.add(approval)
        std_commit()
        return approval

    @classmethod
    def get_approval(cls, approved_by_uid, section_id, term_id):
        return cls.query.filter_by(approved_by_uid=approved_by_uid,
                                   section_id=section_id,
                                   term_id=term_id,
                                   deleted_at=None).first()

    @classmethod
    def get_approvals(cls, section_id, term_id):
        return cls.query.filter_by(section_id=section_id,
                                   term_id=term_id,
                                   deleted_at=None).all()

    @classmethod
    def get_approvals_per_section_ids(cls, section_ids, term_id):
        criteria = and_(cls.section_id.in_(section_ids),
                        cls.term_id == term_id,
                        cls.deleted_at == None)  # noqa: E711
        return cls.query.filter(criteria).order_by(cls.created_at).all()

    @classmethod
    def get_approvals_per_term(cls, term_id):
        return cls.query.filter_by(term_id=int(term_id),
                                   deleted_at=None).order_by(
                                       cls.section_id, cls.created_at).all()

    @classmethod
    def delete(cls, section_id, term_id):
        sql = """UPDATE approvals SET deleted_at = now()
            WHERE term_id = :term_id AND section_id = :section_id AND deleted_at IS NULL"""
        db.session.execute(
            text(sql),
            {
                'section_id': section_id,
                'term_id': term_id,
            },
        )

    def to_api_json(self, rooms_by_id=None):
        room_feed = None
        if self.room_id:
            if rooms_by_id:
                room_feed = rooms_by_id.get(self.room_id, None).to_api_json()
            else:
                room_feed = Room.get_room(self.room_id).to_api_json()
        return {
            'approvedBy': self.approved_by_uid,
            'courseDisplayName': self.course_display_name,
            'createdAt': to_isoformat(self.created_at),
            'publishType': self.publish_type,
            'publishTypeName': NAMES_PER_PUBLISH_TYPE[self.publish_type],
            'recordingType': self.recording_type,
            'recordingTypeName': NAMES_PER_RECORDING_TYPE[self.recording_type],
            'room': room_feed,
            'sectionId': self.section_id,
            'termId': self.term_id,
            'wasApprovedByAdmin': self.approver_type == 'admin',
        }
Ejemplo n.º 3
0
class Scheduled(db.Model):
    __tablename__ = 'scheduled'

    id = db.Column(db.Integer, nullable=False, primary_key=True)  # noqa: A003
    section_id = db.Column(db.Integer, nullable=False)
    term_id = db.Column(db.Integer, nullable=False)
    alerts = db.Column(ARRAY(email_template_type))
    instructor_uids = db.Column(ARRAY(db.String(80)), nullable=False)
    kaltura_schedule_id = db.Column(db.Integer, nullable=False)
    meeting_days = db.Column(db.String, nullable=False)
    meeting_end_date = db.Column(db.DateTime, nullable=False)
    meeting_end_time = db.Column(db.String, nullable=False)
    meeting_start_date = db.Column(db.DateTime, nullable=False)
    meeting_start_time = db.Column(db.String, nullable=False)
    publish_type = db.Column(publish_type, nullable=False)
    recording_type = db.Column(recording_type, nullable=False)
    room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    deleted_at = db.Column(db.DateTime, nullable=True)

    def __init__(
        self,
        section_id,
        term_id,
        instructor_uids,
        kaltura_schedule_id,
        meeting_days,
        meeting_end_date,
        meeting_end_time,
        meeting_start_date,
        meeting_start_time,
        publish_type_,
        recording_type_,
        room_id,
    ):
        self.section_id = section_id
        self.term_id = term_id
        self.instructor_uids = instructor_uids
        self.kaltura_schedule_id = kaltura_schedule_id
        self.meeting_days = meeting_days
        self.meeting_end_date = meeting_end_date
        self.meeting_end_time = meeting_end_time
        self.meeting_start_date = meeting_start_date
        self.meeting_start_time = meeting_start_time
        self.publish_type = publish_type_
        self.recording_type = recording_type_
        self.room_id = room_id

    def __repr__(self):
        return f"""<Scheduled
                    id={self.id},
                    section_id={self.section_id},
                    term_id={self.term_id},
                    alerts={', '.join(self.alerts or [])},
                    instructor_uids={', '.join(self.instructor_uids)},
                    kaltura_schedule_id={self.kaltura_schedule_id}
                    meeting_days={self.meeting_days},
                    meeting_end_date={self.meeting_end_date},
                    meeting_end_time={self.meeting_end_time},
                    meeting_start_date={self.meeting_start_date},
                    meeting_start_time={self.meeting_start_time},
                    publish_type={self.publish_type},
                    recording_type={self.recording_type},
                    room_id={self.room_id},
                    created_at={self.created_at}>
                """

    @classmethod
    def create(
        cls,
        section_id,
        term_id,
        instructor_uids,
        kaltura_schedule_id,
        meeting_days,
        meeting_end_date,
        meeting_end_time,
        meeting_start_date,
        meeting_start_time,
        publish_type_,
        recording_type_,
        room_id,
    ):
        scheduled = cls(
            instructor_uids=instructor_uids,
            kaltura_schedule_id=kaltura_schedule_id,
            meeting_days=meeting_days,
            meeting_end_date=meeting_end_date,
            meeting_end_time=meeting_end_time,
            meeting_start_date=meeting_start_date,
            meeting_start_time=meeting_start_time,
            publish_type_=publish_type_,
            recording_type_=recording_type_,
            room_id=room_id,
            section_id=section_id,
            term_id=term_id,
        )
        db.session.add(scheduled)
        std_commit()
        return scheduled

    @classmethod
    def get_all_scheduled(cls, term_id):
        return cls.query.filter_by(term_id=term_id, deleted_at=None).all()

    @classmethod
    def get_scheduled_per_section_ids(cls, section_ids, term_id):
        criteria = and_(cls.section_id.in_(section_ids),
                        cls.term_id == term_id,
                        cls.deleted_at == None)  # noqa: E711
        return cls.query.filter(criteria).order_by(cls.created_at).all()

    @classmethod
    def get_scheduled(cls, section_id, term_id):
        return cls.query.filter_by(section_id=section_id,
                                   term_id=term_id,
                                   deleted_at=None).first()

    @classmethod
    def delete(cls, section_id, term_id):
        sql = """UPDATE scheduled SET deleted_at = now()
            WHERE term_id = :term_id AND section_id = :section_id AND deleted_at IS NULL"""
        db.session.execute(
            text(sql),
            {
                'section_id': section_id,
                'term_id': term_id,
            },
        )

    @classmethod
    def add_alert(cls, scheduled_id, template_type):
        row = cls.query.filter_by(id=scheduled_id).first()
        if row.alerts:
            row.alerts = list(set(row.alerts + [template_type]))
        else:
            row.alerts = [template_type]
        db.session.add(row)
        std_commit()

    def to_api_json(self, rooms_by_id=None):
        room_feed = None
        if self.room_id:
            if rooms_by_id:
                room_feed = rooms_by_id.get(self.room_id, None).to_api_json()
            else:
                room_feed = Room.get_room(self.room_id).to_api_json()
        formatted_days = format_days(self.meeting_days)
        return {
            'id':
            self.id,
            'alerts':
            self.alerts or [],
            'createdAt':
            to_isoformat(self.created_at),
            'instructorUids':
            self.instructor_uids,
            'kalturaScheduleId':
            self.kaltura_schedule_id,
            'meetingDays':
            formatted_days,
            'meetingDaysNames':
            get_names_of_days(formatted_days),
            'meetingEndDate':
            datetime.strftime(self.meeting_end_date, '%Y-%m-%d'),
            'meetingEndTime':
            self.meeting_end_time,
            'meetingEndTimeFormatted':
            format_time(self.meeting_end_time),
            'meetingStartDate':
            datetime.strftime(self.meeting_start_date, '%Y-%m-%d'),
            'meetingStartTime':
            self.meeting_start_time,
            'meetingStartTimeFormatted':
            format_time(self.meeting_start_time),
            'publishType':
            self.publish_type,
            'publishTypeName':
            NAMES_PER_PUBLISH_TYPE[self.publish_type],
            'recordingType':
            self.recording_type,
            'recordingTypeName':
            NAMES_PER_RECORDING_TYPE[self.recording_type],
            'room':
            room_feed,
            'sectionId':
            self.section_id,
            'termId':
            self.term_id,
        }
Ejemplo n.º 4
0
class Scheduled(db.Model):
    __tablename__ = 'scheduled'

    section_id = db.Column(db.Integer, nullable=False, primary_key=True)
    term_id = db.Column(db.Integer, nullable=False, primary_key=True)
    cross_listed_section_ids = db.Column(ARRAY(db.Integer))
    instructor_uids = db.Column(ARRAY(db.String(80)), nullable=False)
    meeting_days = db.Column(db.String, nullable=False)
    meeting_start_time = db.Column(db.String, nullable=False)
    meeting_end_time = db.Column(db.String, nullable=False)
    publish_type = db.Column(publish_type, nullable=False)
    recording_type = db.Column(recording_type, nullable=False)
    room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)

    def __init__(
        self,
        section_id,
        term_id,
        cross_listed_section_ids,
        instructor_uids,
        meeting_days,
        meeting_start_time,
        meeting_end_time,
        publish_type_,
        recording_type_,
        room_id,
    ):
        self.section_id = section_id
        self.term_id = term_id
        self.cross_listed_section_ids = cross_listed_section_ids
        self.instructor_uids = instructor_uids
        self.meeting_days = meeting_days
        self.meeting_start_time = meeting_start_time
        self.meeting_end_time = meeting_end_time
        self.publish_type = publish_type_
        self.recording_type = recording_type_
        self.room_id = room_id

    def __repr__(self):
        return f"""<Scheduled
                    section_id={self.section_id},
                    term_id={self.term_id},
                    cross_listed_section_ids={self.cross_listed_section_ids},
                    instructor_uids={', '.join(self.instructor_uids)},
                    meeting_days={self.meeting_days},
                    meeting_start_time={self.meeting_start_time},
                    meeting_end_time={self.meeting_end_time},
                    publish_type={self.publish_type},
                    recording_type={self.recording_type},
                    room_id={self.room_id},
                    created_at={self.created_at}>
                """

    @classmethod
    def create(
        cls,
        section_id,
        term_id,
        cross_listed_section_ids,
        instructor_uids,
        meeting_days,
        meeting_start_time,
        meeting_end_time,
        publish_type_,
        recording_type_,
        room_id,
    ):
        scheduled = cls(
            cross_listed_section_ids=cross_listed_section_ids,
            instructor_uids=instructor_uids,
            meeting_days=meeting_days,
            meeting_start_time=meeting_start_time,
            meeting_end_time=meeting_end_time,
            publish_type_=publish_type_,
            recording_type_=recording_type_,
            room_id=room_id,
            section_id=section_id,
            term_id=term_id,
        )
        db.session.add(scheduled)
        std_commit()
        return scheduled

    @classmethod
    def get_all_scheduled(cls, term_id):
        return cls.query.filter_by(term_id=term_id).all()

    @classmethod
    def get_scheduled_per_section_ids(cls, section_ids, term_id):
        criteria = and_(cls.section_id.in_(section_ids),
                        cls.term_id == term_id)
        return cls.query.filter(criteria).order_by(cls.created_at).all()

    @classmethod
    def get_scheduled(cls, section_id, term_id):
        return cls.query.filter_by(section_id=section_id,
                                   term_id=term_id).first()

    def to_api_json(self):
        return {
            'createdAt': to_isoformat(self.created_at),
            'crossListedSectionIds': self.cross_listed_section_ids,
            'instructorUids': self.instructor_uids,
            'meetingDays': format_days(self.meeting_days),
            'meetingEndTime': format_time(self.meeting_end_time),
            'meetingStartTime': format_time(self.meeting_start_time),
            'publishType': self.publish_type,
            'publishTypeName': NAMES_PER_PUBLISH_TYPE[self.publish_type],
            'recordingType': self.recording_type,
            'recordingTypeName': NAMES_PER_RECORDING_TYPE[self.recording_type],
            'room': Room.get_room(self.room_id).to_api_json()
            if self.room_id else None,
            'sectionId': self.section_id,
            'termId': self.term_id,
        }