Exemple #1
0
 def media_delete_by_id(usertoken, media_id, term):
     term_db = TermGateway()
     term_db.update_validation(term, is_shown=0)
     media_db = MediaGateway()
     rv = media_db.delete(media_id)
     if rv['code'] == 0:
         ControlService.write_to_log(usertoken, "media", str(media_id),
                                     "delete")
     return rv
 def media_add(usertoken, type, youtube_id, term_id):
     media_db = MediaGateway()
     term_db = TermGateway()
     term_db.update_validation(term_id, is_shown=0)
     database_result = media_db.create(type, youtube_id, term_id)
     result = {
         "code": database_result['code'],
         "message": database_result['message'],
     }
     if result["code"] == 0:
         number = media_db.access_get_number(visitor=VisitorLastNumber)
         ControlService.write_to_log(usertoken, "media", str(number), "add")
     return result
Exemple #3
0
    def term_get_random():
        term_db = TermGateway()
        id = term_db.access_get_number(visitor=VisitorRandomNumber)
        terms = term_db.read_by_id(id)
        teacher_db = TeacherGateway()
        teachers = teacher_db.read_all()
        if teachers == None:
            teachers = {}

        disciplines = {}
        department_db = DepartmentGateway()
        departments = department_db.read_all()
        if departments == None:
            departments = {}
        else:
            discipline_db = DisciplineGateway()
            disciplines = discipline_db.read_all()
            if disciplines == None:
                disciplines = {}
            else:
                for (index, row_discipline) in enumerate(disciplines):
                    department_id = row_discipline['department_id']
                    department = ''
                    for (index, row) in enumerate(departments):
                        if row['iddepartment'] == department_id:
                            department = row['initials']
                    row_discipline['department_id'] = department

        if terms == None:
            return {"term": {}, "media": {}}
        else:
            media_db = MediaGateway()
            rv = media_db.read_by_term(id)
            if rv == None:
                rv = {}
            return {
                "term": terms,
                "media": rv,
                "disciplines": disciplines,
                "teachers": teachers
            }
Exemple #4
0
    def log_read_last(count):
        logDB = LogGateway()
        logs = logDB.read_last(count=count)

        user_db = UserGateway()
        users = user_db.read_all()

        department_db = DepartmentGateway()
        departments = department_db.read_all()

        discipline_db = DisciplineGateway()
        disciplines = discipline_db.read_all()

        teacher_db = TeacherGateway()
        teachers = teacher_db.read_all()

        term_db = TermGateway()
        terms = term_db.read_for_editor(start=0, end=20, only_invalided=False)

        media_db = MediaGateway()
        medias = media_db.read_all()

        if logs == None:
            return {}
        else:
            for (index_log, log) in enumerate(logs):
                # correct date
                tmp = log['date_time']
                log['date_time'] = tmp.strftime('%d.%m.%Y %H:%M')
                # add user to log
                for (index_user, user) in enumerate(users):
                    if (log['user'] == user['iduser']):
                        log['user'] = user
                # long series for if for element detection
                if (log['table'] == "user"):
                    for (index_user, user) in enumerate(users):
                        if (log['element'] == user['iduser']):
                            element_text = user['first_name'] + " " + user[
                                'last_name']
                            log['element'] = {
                                "id": user['iduser'],
                                "text": element_text
                            }
                if (log['table'] == "department"):
                    for (index_department,
                         department) in enumerate(departments):
                        if (log['element'] == department['iddepartment']):
                            element_text = department['initials']
                            log['element'] = {
                                "id": department['iddepartment'],
                                "text": element_text
                            }
                if (log['table'] == "discipline"):
                    for (index_discipline,
                         discipline) in enumerate(disciplines):
                        if (log['element'] == discipline['iddiscipline']):
                            element_text = discipline['name']
                            log['element'] = {
                                "id": discipline['iddiscipline'],
                                "text": element_text
                            }
                if (log['table'] == "teacher"):
                    for (index_teacher, teacher) in enumerate(teachers):
                        if (log['element'] == teacher['idteacher']):
                            element_text = teacher['name']
                            log['element'] = {
                                "id": teacher['idteacher'],
                                "text": element_text
                            }
                if (log['table'] == "term"):
                    for (index_term, term) in enumerate(terms):
                        if (log['element'] == term['idterm']):
                            element_text = term['caption']
                            log['element'] = {
                                "id": term['idterm'],
                                "text": element_text
                            }
                if (log['table'] == "media"):
                    for (index_media, media) in enumerate(medias):
                        if (log['element'] == media['idmedia']):
                            types = {
                                1: "Жест",
                                2: "Артикуляция",
                                3: "Контекстный пример"
                            }
                            element_text = types[media['type']]
                            log['element'] = {
                                "id": media['idmedia'],
                                "text": element_text
                            }
        rv = logs

        return rv