Ejemplo n.º 1
0
 def remove_curriculum_subject(cur_subj: any):
     if cur_subj is CurriculumSubjects:
         try:
             CurriculumSubjects.query.filter_by(id=cur_subj.id).delete()
         except Exception as e:
             print('error:', e)
     db_session.commit()
Ejemplo n.º 2
0
 def post(self):
     req_params: list((str, bool)) = [('content', True)]
     data = quick_parse(req_params).parse_args()
     import json
     from core.models.Subject import AvailableSubjectEnhance, NewSemData
     from main_db import db_session
     content = json.loads(data['content'])
     _id = content['sem_id']
     print('data', data)
     if _id is not None:
         print('data_id', _id)
         lz: NewSemData = NewSemData.query.filter_by(id=_id).first()
         rz = []
         if lz is not None:
             # s = AvailableSubjectEnhance.query.filter_by(new_sem_id=lz.id).all()
             # rz = [z.subject_code for z in s]
             # AvailableSubjectEnhance.query.filter_by(new_sem_id=lz.id).delete()
             # # for q in s:
             # #     rz.append(q.subject_code)
             # #     q.delete()
             # NewSemData.query.filter_by(id=lz.id).delete()
             lz.delete_sem_data()
             db_session.commit()
             lts = NewSemData.latest_id()
             if lts is not None:
                 lts.use_as_current()
         return {
             'data': {
                 'removed': rz
             }
         }, 200, {
             'Access-Control-Allow-Origin': '*'
         }
Ejemplo n.º 3
0
 def use_as_current(self):
     o = NewSemData.query.filter_by().all()
     for x in o:
         if x.id == self.id:
             x.is_current_semester = True
             continue
         x.is_current_semester = False
     db_session.commit()
Ejemplo n.º 4
0
    def post(self):
        content = 'content'
        req_params: list((str, bool)) = [(content, True)]
        data = quick_parse(req_params).parse_args()
        import json
        c = json.loads(data[content])
        err_items = []
        uploaded = []
        updated = []
        from core.models.StudentData import StudentGrades
        from main_db import db_session

        def req_ok(r_f):
            for r in r_f:
                if r is None or len(str(r)) == 0:
                    return False
            return True

        if isinstance(c, list):
            for s in c:
                s_id = s['student_id']
                s_scode = s['subject_code']
                s_g = s['grade']
                req_f = [s_id, s_scode, s_g]
                r_ok = req_ok(req_f)
                err_items.append(s_id)
                if not r_ok:
                    err_items.append(s)
                    continue
                sg_c: StudentGrades = StudentGrades.check_grade(
                    int(s_id), str(s_scode))
                print('sg_c', sg_c)
                if sg_c is None:
                    z: StudentGrades = StudentGrades(
                        int(s_id),
                        str(s_scode).replace(' ', '').lower(), float(s_g))
                    z.save()
                    uploaded.append(z.student_id)
                    del err_items[-1]
                else:
                    sg_c.grade = s_g
                    updated.append({
                        'student_id': sg_c.student_id,
                        'subject_code': sg_c.subject_code,
                        'grade': sg_c.grade
                    })
                    del err_items[-1]
                    db_session.commit()

        rv = {
            'response': {
                'uploaded': uploaded,
                'updated': updated,
                'errors': err_items
            }
        }
        return response_checker(True, rv, res_code=200)
Ejemplo n.º 5
0
    def post(self):
        content = 'content'
        req_params: list((str, bool)) = [(content, True)]
        data = quick_parse(req_params).parse_args()
        import json
        c = json.loads(data[content])
        err_items = []
        uploaded = []
        from core.models.StudentData import StudentData, Course
        from core.models.CurriculumEnums import YearEnum

        def req_ok(r_f):
            for r in r_f:
                if r is None or len(str(r)) == 0:
                    return False
            return True

        print('c', c)
        if isinstance(c, list):
            for s in c:
                s_id = s['student_id']
                s_fn = s['full_name']
                s_c = s['course']
                s_y = s['year']
                req_f = [s_id, s_fn, s_c, s_y]
                r_ok = req_ok(req_f)
                err_items.append(s_id)
                if not r_ok:
                    # err_items.append(s)
                    continue
                # es = StudentData.search_student(s_id)
                # if es is None:
                #     continue

                _s_c: Course = Course.find_course_title(s_c)
                if _s_c is None:
                    continue

                z: StudentData = StudentData.search_student(s_id)
                if z is not None:
                    z.full_name = s_fn
                    z.course_id = _s_c.id
                    z.year = YearEnum(str(s_y).lower())
                    z.save(do_commit=False)
                    continue

                z: StudentData = StudentData(int(s_id),
                                             str(s_fn).strip(), _s_c,
                                             YearEnum(str(s_y).lower()))
                z.save(do_commit=False)
                uploaded.append(z.student_id)
                del err_items[-1]
            from main_db import db_session
            db_session.commit()
        rv = {'response': {'uploaded': uploaded, 'errors': err_items}}

        return response_checker(True, rv, res_code=200)
Ejemplo n.º 6
0
 def save(self, do_commit=True):
     from sqlalchemy import exc
     try:
         db_session.add(self)
         if do_commit:
             db_session.commit()
         # db.session.close()
         return self
     except exc.IntegrityError:
         return None
Ejemplo n.º 7
0
 def post(self):
     student_id = 'student_id'
     req_params: list((str, bool)) = [(student_id, True)]
     data = quick_parse(req_params).parse_args()
     sid = data[student_id]
     msg = 'deleted'
     r_num = 200
     try:
         from core.models.StudentData import StudentData
         from main_db import db_session
         StudentData.query.filter_by(student_id=sid).delete()
         db_session.commit()
     except Exception as e:
         msg = e
         r_num = 500
     rv = {'message': msg}
     return response_checker(True, rv, res_code=r_num)
Ejemplo n.º 8
0
 def post(self):
     curriculum_id = 'curriculum_id'
     req_params: list((str, bool)) = [(curriculum_id, True)]
     data = quick_parse(req_params).parse_args()
     cid = data[curriculum_id]
     msg = 'deleted'
     r_num = 200
     from core.models.Subject import Curriculum, CurriculumSubjects
     from main_db import db_session
     Curriculum.query.filter_by(id=cid).delete()
     CurriculumSubjects.query.filter_by(curriculum_id=cid).delete()
     db_session.commit()
     # try:
     #
     # except Exception as e:
     #     msg = e
     #     r_num = 500
     rv = {'message': msg}
     return response_checker(True, rv, res_code=r_num)
Ejemplo n.º 9
0
    def post(self):
        curriculum_id = 'curriculum_id'
        content = 'content'
        req_params: list((str, bool)) = [(curriculum_id, True),
                                         (content, True)]
        data = quick_parse(req_params).parse_args()
        import json
        _c = json.loads(data[content])
        _cid = data[curriculum_id]

        from core.models.Subject import Curriculum
        curr = Curriculum.search_curriculum(int(_cid))
        if curr is None:
            return response_checker(True,
                                    {'message': 'curriculum id not found'},
                                    res_code=404)

        errors = []
        if isinstance(_c, list):
            for x in _c:
                if isinstance(x, dict):
                    x_keys = x.keys()
                    _2_add = {
                        'curriculum_id': _cid,
                        'code': str(x['code']).replace(' ', '').lower(),
                        'title': x['title'],
                        'year': x['year'],
                        'semester': x['semester'],
                        'units': x['units'],
                    }
                    if 'pre_req' in x_keys:
                        _2_add['pre_req'] = str(x['pre_req']).replace(
                            ' ', '').lower()
                    rv, n, a = new_subject(_2_add, commit=False)
                    if isinstance(n, int):
                        if n != 200:
                            _2_add['error'] = {'code': n, 'note': rv['note']}
                            errors.append(_2_add)
            from main_db import db_session
            db_session.commit()
        rv = {'response': {'errors': errors}}

        return response_checker(True, rv)
Ejemplo n.º 10
0
    def post(self):
        req_params: list((str, bool)) = [('student_id', True),
                                         ('semester_id', True),
                                         ('content', True),
                                         ('is_block_section', False)]
        data = quick_parse(req_params).parse_args()
        is_block_section = data['is_block_section']
        if is_block_section is None:
            is_block_section = False
        else:
            is_block_section = True if str(
                is_block_section).lower() == 'true' else False
        print('is_block_section', is_block_section)
        import json
        from core.models.Subject import AvailableSubjectEnhance, NewSemData
        from core.models.Faculty import AdvisingData
        from core.models.StudentData import StudentData
        from main_db import db_session
        content = json.loads(data['content'])
        # _id = content['sem_id']
        print('data', data)
        print('content', content)
        print('isinstance(content, list)', isinstance(content, list))
        socket_rv = {}
        if isinstance(content, list):
            try:
                s_data: StudentData = StudentData.query.filter_by(
                    student_id=int(data['student_id'])).first()
                ns: NewSemData = NewSemData.query.filter_by(
                    id=data['semester_id']).first()
                old_opi: [AdvisingData] = AdvisingData.query.filter_by(
                    student_id=int(data['student_id'])).all()
                print('old_opi', old_opi)
                print('sem_i', ns.id)
                rem_s_codes: [] = []
                for z in old_opi:
                    z_id: AvailableSubjectEnhance = AvailableSubjectEnhance.query.filter_by(
                        id=z.available_subject_id).first()
                    print('z_id.id', z_id.new_sem.id)
                    if z_id.new_sem.id == ns.id:
                        AdvisingData.query.filter_by(id=z.id).delete()
                        db_session.commit()
                        rem_s_codes.append(z_id.subject_code)
                s_codes: list = []
                for c in content:
                    opi: AvailableSubjectEnhance = AvailableSubjectEnhance \
                        .query.filter_by(id=c) \
                        .first() if not \
                        is_block_section else \
                        AvailableSubjectEnhance.query.filter_by(subject_code=c, new_sem_id=ns.id).first()
                    if opi is None and is_block_section:
                        opi = AvailableSubjectEnhance(ns, c)
                        opi.save()
                    if opi is not None and s_data is not None:
                        new_data: AdvisingData = AdvisingData(opi, s_data)
                        new_data.save()
                        s_codes.append(opi.subject_code)

                from api.sockets import AdvisingConfigs, advising_socket_emit
                socket_rv = {
                    'content': {
                        'removed': rem_s_codes,
                        'added': s_codes
                    }
                }
                # advising_socket_emit(AdvisingConfigs.new_advising_form_submitted, socket_rv)
                # print('socket_rv', socket_rv)
            except Exception as e:
                print('error', e)
                response_checker(True, {'error': 'server error'}, res_code=500)

            return response_checker(True, {
                'message': 'finished',
                'data': socket_rv
            },
                                    res_code=200)
        else:
            return response_checker(True, {'error': 'forbidden'}, res_code=403)
Ejemplo n.º 11
0
 def delete_avail_sub(self):
     from core.models.Faculty import AdvisingData
     AdvisingData.query.filter_by(available_subject_id=self.id).delete()
     AvailableSubjectEnhance.query.filter_by(id=self.id).delete()
     db_session.commit()
Ejemplo n.º 12
0
 def delete_sem_data(self):
     s = AvailableSubjectEnhance.query.filter_by(new_sem_id=self.id).all()
     for x in s:
         x.delete_avail_sub()
     NewSemData.query.filter_by(id=self.id).delete()
     db_session.commit()
Ejemplo n.º 13
0
 def remove_a_subject(self, subj: Subject):
     c_id = self.id
     s_id = subj.id
     CurriculumSubjects.query.filter_by(curriculum_id=c_id,
                                        subject_id=s_id).delete()
     db_session.commit()