You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

303 lines
9.9 KiB

# coding=utf-8
import copy
from lms.tools import out_date_format
STATUS_LABEL_CLASS = 'btn btn-{0} pull-right btn-lg m-b-xs m-r-xs m-t-lg'
# Ключи материалов
# L - Урок
# H - ДЗ
# E - Экзамен
# ! Если мы ставим словарь в значение, обязательно должен быть ключь 'default' !
STATUS_COLLECTION = ({
'title': {'default': u'Доступно для выполнения', 'L': u'Доступно'},
'flag': 'A',
'color': 'info',
'styles': 'text-shadow: 0 0 0;',
'icon': 'glyphicon glyphicon-time'
}, {
'title': {'default': u'Проверяется преподавателем'},
'flag': 'T',
'color': 'info',
'styles': 'text-shadow: 0 0 0;',
'icon': 'glyphicon glyphicon-time'
}, {
'title': {'default': u'Требуется доработка'},
'flag': 'E',
'color': 'danger',
'styles': 'text-shadow: 0 0 0;',
'icon': 'glyphicon glyphicon-time'
}, {
'title': {'default': u'Сдано', 'L': u'Пройдено'},
'flag': 'F',
'color': 'success',
'styles': 'text-shadow: 0 0 0;',
'icon': 'glyphicon glyphicon-ok'
}, {
'title': {'default': u'Не доступно'},
'flag': 'N',
'color': 'default',
'styles': 'color: #ccc;text-shadow: 0 0 0;',
'icon': 'glyphicon glyphicon-remove'
})
COMMENTS_STATUS_COLLECTION = ({
'title': 'Одобрено',
'flag': 'G',
'label': '',
'background': '',
'color': '',
'style': '',
'icon': ''
}, {
'title': 'Отклонено',
'flag': 'F',
'label': '',
'background': '',
'color': '',
'style': '',
'icon': ''
}, {
'title': 'Сообщение от администрации',
'flag': 'A',
'label': '',
'background': '',
'color': '',
'style': '',
'icon': ''
}, {
'title': 'Технический вопрос',
'flag': 'T',
'label': '',
'background': '',
'color': '',
'style': '',
'icon': ''
}, {
'title': '',
'flag': 'S',
'label': '',
'background': '',
'color': '',
'style': '',
'icon': ''
})
# ! Если мы ставим словарь в значение, обязательно должен быть ключь 'default' !
LEVELS_COLLECTION = ({
'title': u'Базовый',
'flag': 'B',
'color': '#fff',
'background': '#5cb85c',
'icon': 'glyphicon glyphicon-signal'
}, {
'title': u'Продвинутый',
'flag': 'A',
'color': '#fff',
'background': '#5bc0de',
'icon': 'glyphicon glyphicon-signal'
}, {
'title': u'Экспертный',
'flag': 'E',
'color': '#fff',
'background': '#d9534f',
'icon': 'glyphicon glyphicon-signal'
}, {
'title': u'Базовый + Продвинутый',
'flag': 'B+A',
'color': '#fff',
'background': '#e68917',
'icon': 'glyphicon glyphicon-signal'
})
# ! Если мы ставим словарь в значение, обязательно должен быть ключь 'default' !
MATERIAL_TYPE_COLLECTION = ({
'title': u'Базовый материал', # Выводимое имя типа
'flag': 'B', # Флаг, по которому идет поиск
'color': '#dee5e7', # Стандартный цвет отображения типа материала
'icon': '/static/img/1441672724_new_seo-37.png' # Стандартная иконка темы
}, {
'title': u'Расширеный материал',
'flag': 'E',
'color': '#66cc99',
'icon': '/static/img/1441673370_8.png'
}, {
'title': u'Премиум материал',
'flag': 'P',
'color': '#ffffcc',
'icon': '/static/img/1441671767_new_seo-36.png'
}, {
'title': u'Предэкзаменационные материалы',
'flag': 'M',
'color': '#dee5e7',
'icon': '/static/img/1447237167_BeOS_app_serv.png'
}, {
'title': u'Экзаменационная тема',
'flag': 'Ex',
'color': '#ff1',
'icon': '/static/img/1441672223_new_seo2-17.png'
})
USER_TYPES = ({
'flag': 'U',
'title': u'Студент',
'background': 'bg-primary',
'style': '',
'label': ''
}, {
'flag': 'T',
'title': u'Преподаватель',
'background': 'bg-primary',
'style': '',
'label': ''
}, {
'flag': 'M',
'title': u'Менеджер',
'background': 'bg-primary',
'style': '',
'label': ''
}, {
'flag': 'S',
'title': 'Руководитель',
'background': 'bg-primary',
'style': '',
'label': ''
}, {
'flag': 'A',
'title': u'Команда «SkillBox»',
'background': 'bg-warning',
'style': 'color: #666;font-weight: normal;text-shadow: 0 0 0;',
'label': ''
}, {
'flag': 'S2',
'title': u'Куратор',
'background': 'bg-warning',
'style': 'color: #666;font-weight: normal;text-shadow: 0 0 0;',
'label': ''
})
BUTTON_TYPES = {
'N': '',
'B': u'Получить полный доступ к курсу',
'H': u'Перейти к заданию',
'L': u'Перейти к изучению',
'O': u'Открыть лекцию',
'E': u'Страница экзамена',
'T': u'Не доступно по подписке',
'F': u'Перейти к экзамену'
}
BUTTON_TYPE = ({
'flag': 'A',
'title': {'default': u'Открыть материал',
'L': u'Перейти к уроку',
'H': u'Перейти к заданию',
'E': u'Перейти к экзамену'},
'color': {'default': '#fff'},
'background': {
'default': '#23ad44',
'H': '#23b7e5'
},
'link': {'L': '/courses/lesson/',
'H': '/courses/homework/',
'E': '/courses/exam/'},
'by_type': {
'L': 'lesson',
'H': 'homework',
'E': 'exam'
}
}, {
'flag': 'F',
'title': {'default': u'Открыть материал',
'L': u'Открыть лекцию',
'H': u'Открыть задание',
'E': u'Открыть экзамен'},
'color': {'default': '#fff'},
'background': {
'default': '#23ad44',
'H': '#23b7e5'
},
'link': {'L': '/courses/lesson/', # ID урока
'H': '/courses/homework/', # ID ДЗ
'E': '/courses/exam/'}, # ID экзамена
'by_type': {
'L': 'lesson',
'H': 'homework',
'E': 'exam'
}
})
def comment_fabric(_comment, __type=None, __user=None):
result = {
'id': _comment.id,
'status': search_in_collection(COMMENTS_STATUS_COLLECTION, 'flag', _comment.status),
'closed': _comment.closed,
'owner': _comment.owner.name if _comment.owner.name else _comment.owner.get_short_name(),
'owner_name': _comment.owner.get_full_name(),
'owner_id': _comment.owner.id,
'owner_email': _comment.owner.email,
'owner_type': search_in_collection(USER_TYPES, 'flag', _comment.owner.in_role),
'owner_avatar': _comment.owner.get_image_url(type_in='small'),
'owner_status': _comment.owner.get_status_display(),
'owner_interactive_key': _comment.owner.interactive_key,
'owner_model': '',
'text': _comment.get_text(),
'date': out_date_format(_comment.date, no_time=False),
'replies': _comment.get_replies(__type, __user),
'files': material_fabric(_comment.files.all()),
'response': _comment.response,
'response_comment': _comment.response_comment.get_face(_type=__type, _user=__user) if _comment.response else None
}
if __user:
result['saw'] = _comment.saw.filter(id=__user.id).exists()
#comment.set_saw(__user)
return result
def material_fabric(stores):
result = []
for store in stores:
result.append({
'id': store.id,
'format': store.f_format.f_type,
'icon_type': 'class' if store.f_format.icon_class else 'icon',
'icon': store.f_format.icon.url if store.f_format.icon else store.f_format.icon_class,
'url': store.original.url,
'title': store.get_name_for_user(),
'name': store.get_file_name()
})
return result
def search_in_collection(collection, field, word, artifact=None, in_type='default'):
# Поиск по полю в коллекции словарей
# == Коллекции статичны. Найдя словарь отображения по флагу к примеру, можно просто вывести результат в веб
# == artifact - получить значение конкретно поля из словаря
# Получает кортеж, берет словари по очереди и сравнивает в них поле field
# Если значение в поле template[field] == work - возвращает полную копию словаря или возвращает пустое значение
render = ''
for template in collection:
if template[field] == word:
if artifact:
render = copy.deepcopy(template[artifact])
else:
render = copy.deepcopy(template)
break
if render:
# Получить шаблон специально для запрашиваемого объекта по ключу объекта
# У урока к примеру сейчас это 'L'
try:
for key, value in render.items():
if type(value) == dict:
if in_type in value:
render[key] = value[in_type]
else:
render[key] = value['default']
except AttributeError:
return render
return render