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.
909 lines
42 KiB
909 lines
42 KiB
# coding=utf-8
|
|
import datetime
|
|
import re
|
|
from django.db.models import Q
|
|
from access.models import User, ActionJ
|
|
from lms.decors import api_decor
|
|
from courses.models import Course, Lesson, Homework, CourseTheme
|
|
from courses.templates import comment_fabric
|
|
from journals.models import AchievementJ, LessonJ, HomeworkJ, ExamJ, check_journal, HomeworkTry, ExamTry
|
|
from finance.models import Bill
|
|
from courses.tools import set_read_flag, get_next_button
|
|
from management.letters import sent_comment_news, sent_teacher_answer, sent_to_teacher_answer, letter_delete_comment, \
|
|
sent_new_comment
|
|
from management.models import Comment
|
|
from lms.settings import DOMAIN
|
|
from storage.models import Storage
|
|
from library.models import Article
|
|
import django.utils.timezone
|
|
|
|
|
|
@api_decor(without_auth=False, method='POST', need_keys=['id', 'material_id', 'text', 'type'], check_request=True)
|
|
def sent_comment_response(request, context):
|
|
try:
|
|
response = Comment.objects.get(id=request.POST['id'])
|
|
except Comment:
|
|
context['code'] = '0'
|
|
context['response'] = u'Исходный комментарий не найден'
|
|
return context
|
|
comment = Comment.objects.create(owner=request.user, text=request.POST['text'], parent_id=response.id)
|
|
|
|
if request.POST['type'] == 'L':
|
|
try:
|
|
material = Article.objects.get(id=request.POST['material_id'])
|
|
except Article.DoesNotExists:
|
|
context['code'] = '0'
|
|
context['response'] = u'Статья не найдена'
|
|
return context
|
|
|
|
elif request.POST['type'] == 'A':
|
|
try:
|
|
material = Lesson.objects.get(id=request.POST['material_id'])
|
|
except Lesson.DoesNotExists:
|
|
context['code'] = '0'
|
|
context['response'] = u'Урок не найден'
|
|
return context
|
|
|
|
response.replies.add(comment)
|
|
response.response_comment = comment
|
|
response.response = True
|
|
response.saw.add(request.user)
|
|
if response.owner.check_subscription('new_comment'):
|
|
sent_comment_news(response, comment, material, _type=request.POST['type'])
|
|
response.save()
|
|
material.comments.add(comment)
|
|
material.save()
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, method='POST', need_keys=['id'], check_request=True)
|
|
def close_achievement(request, context):
|
|
# Пометка ачивки, как прочитанной
|
|
a = AchievementJ.objects.get(id=request.POST['id'])
|
|
a.got = True
|
|
a.save()
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_achievement(request, context):
|
|
# Получение ачивки пользователя, первой в очереди, не прочитанной
|
|
context['code'] = '0'
|
|
a = AchievementJ.objects.filter(student=request.user, got=False).first()
|
|
if a:
|
|
context['code'] = '1'
|
|
context['data'] = {
|
|
'id': a.id,
|
|
'title': a.title,
|
|
'text': a.text,
|
|
'image': a.achievement.image.url,
|
|
'border': a.achievement.border,
|
|
'background': a.achievement.background
|
|
}
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_process_vector(request, context):
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['id', 'user'], method='GET', check_request=True)
|
|
def check_bill(request, context):
|
|
# Проверка оплаты
|
|
# TODO: Применить новую модель доступов
|
|
course = Course.objects.get(id=request.GET['id'])
|
|
user = User.objects.get(id=request.GET['user'])
|
|
context['code'] = '0'
|
|
if Bill.objects.filter(service__course=course, user=user, status='F').exists():
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['lesson'], method='POST', check_request=True)
|
|
def read_lesson(request, context):
|
|
# Пометка урока как прочитанного
|
|
context['code'] = '1'
|
|
try:
|
|
lesson = Lesson.objects.get(id=request.POST['lesson'])
|
|
journal = LessonJ.objects.get(student=request.user, material=Lesson.objects.get(id=request.POST['lesson']))
|
|
except Lesson.DoesNotExist:
|
|
context['code'] = '0'
|
|
except LessonJ.DoesNotExist:
|
|
context['code'] = '0'
|
|
else:
|
|
context['data'] = [journal.id, lesson.id]
|
|
journal.saw_this()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def sent_lesson_comment(request, context):
|
|
# Отправка комментария урока
|
|
if request.POST['comment_sent_text']:
|
|
lesson = Lesson.objects.get(id=request.POST['comment_for_lesson_id'])
|
|
parent_id = request.POST['reply_for_comment_id']
|
|
comment = Comment.objects.create(parent_id=parent_id, owner=request.user,
|
|
text=request.POST['comment_sent_text'], date=django.utils.timezone.now())
|
|
|
|
lesson.comments.add(comment)
|
|
lesson.save()
|
|
# Получение о добавление файлов комментария
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
if parent_id != '0':
|
|
comment2 = Comment.objects.get(id=parent_id)
|
|
if comment2.owner.check_subscription('new_comment'):
|
|
sent_comment_news(comment2, comment, lesson)
|
|
context['code'] = '1'
|
|
context['data'] = comment.id
|
|
|
|
if not comment.send:
|
|
for eye in User.objects.filter(in_role='S2'):
|
|
sent_new_comment(comment, lesson, eye.email)
|
|
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=True, need_keys=['lesson'], method='POST', check_request=True)
|
|
def load_lesson_comments(request, context):
|
|
# Загрузка списка комментариев
|
|
lesson = Lesson.objects.get(id=request.POST['lesson'])
|
|
context['data'] = lesson.get_comments(_user=request.user)
|
|
|
|
if len(context['data']) == 0:
|
|
context['code'] = '0'
|
|
else:
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=True, need_keys=['id'], method='POST', check_request=True)
|
|
def load_comment(request, context):
|
|
try:
|
|
comment = Comment.objects.get(id=request.POST['id'])
|
|
except Comment.DoesNotExist:
|
|
context['code'] = '0'
|
|
else:
|
|
context['data'] = comment.get_face(__user=request.user)
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def sent_homework_comment(request, context):
|
|
# Отправка ДЗ попытки
|
|
context['data'] = {}
|
|
context['code'] = '0'
|
|
if request.POST['homework_text']:
|
|
homework = HomeworkJ.objects.get(id=request.POST['homework_id'], student=request.user)
|
|
h_status = homework.get_status_flag()
|
|
if h_status not in ['N', 'F']:
|
|
ht, c = HomeworkTry.objects.get_or_create(parent=homework, success=False, f_date=None, student=request.user,
|
|
material=homework.material)
|
|
comment = Comment.objects.create(owner=request.user, text=request.POST['homework_text'],
|
|
date=django.utils.timezone.now())
|
|
ht.comments.add(comment)
|
|
ht.save()
|
|
if c:
|
|
action = ActionJ.objects.create(student=homework.student,
|
|
a_type='I',
|
|
place=u'Курс '+u'\xab'+u'{0}'.format(homework.material.course.get_title())+u'\xbb'+u', домашнее задание # {0}'.format(homework.material.theme.sort),
|
|
text=u'Ваше <a href="{2}/courses/homework/{0}#comment_{1}" '
|
|
u'style="color: blue;">домашнее задание</a> отправлено на проверку.'
|
|
u''.format(homework.material.id, comment.id, DOMAIN))
|
|
homework.date = datetime.datetime.now()
|
|
if homework.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
# Отправка письма и активности преподавателю
|
|
sent_to_teacher_answer(ActionJ.objects.create(
|
|
student=ht.teacher,
|
|
place=u'Студент: {0}, домашнее задание # {1}'.format(
|
|
homework.student,
|
|
homework.material.theme.sort),
|
|
text=u'Текст: {0} <br><a href="{2}/teacher/workshop/homework/{1}" target="_blank">Перейти к проверке</a>'.format(comment.text,
|
|
homework.id, DOMAIN),
|
|
a_type='I'
|
|
))
|
|
|
|
# Проверка и загрузка файлов
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
context['code'] = '1'
|
|
context['data'] = {'try': ht.get_head_face(), 'comment': comment.get_face()}
|
|
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def send_cancel_teach_comment(request, context):
|
|
# Отправка на доработку для преподавателя
|
|
# TODO: Перейти на модель попыток
|
|
if request.POST['comment_sent_text']:
|
|
lesson = HomeworkJ.objects.get(student__id=request.POST['comment_for_user_id'],
|
|
material__theme=request.POST['comment_for_theme_id'], teacher=request.user)
|
|
parent_id = request.POST['reply_for_comment_id']
|
|
comment = Comment.objects.create(parent_id=parent_id, owner=request.user, status='F',
|
|
text=request.POST['comment_sent_text'], date=django.utils.timezone.now())
|
|
lesson.comments.add(comment)
|
|
if lesson.status != 'F':
|
|
lesson.status = 'E'
|
|
action = ActionJ.objects.create(student=lesson.student,
|
|
a_type='D',
|
|
place=u'Курс '+u'\xab'+u'{0}'.format(lesson.homework.course.get_title())+u'\xbb'+u', домашнее задание # {0}'.format(lesson.homework.theme.sort),
|
|
text=u'Ваше домашнее задание проверено преподавателем. '
|
|
u'<a href="{2}/courses/homework/{0}#comment_{1}" '
|
|
u'style="color: blue;">Вам необходимо провести работу над ошибками'
|
|
u'</a>'.format(
|
|
lesson.material.id, comment.id, DOMAIN))
|
|
if lesson.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
lesson.save()
|
|
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
if parent_id != '0':
|
|
comment2 = Comment.objects.get(id=parent_id)
|
|
if comment2.owner.check_subscription('new_comment'):
|
|
sent_comment_news(comment2, comment, lesson)
|
|
context['code'] = '1'
|
|
context['data'] = comment.id
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def send_accept_teach_comment(request, context):
|
|
# Одобрение попытки ДЗ для преподавателя
|
|
# TODO: Перейти на модель попыток
|
|
lesson = HomeworkJ.objects.get(student__id=request.POST['comment_for_user_id'],
|
|
material__theme=request.POST['comment_for_theme_id'], teacher=request.user)
|
|
parent_id = request.POST['reply_for_comment_id']
|
|
comment = Comment.objects.create(parent_id=parent_id, owner=request.user, status='G',
|
|
text=request.POST['comment_sent_text'] + get_next_button(lesson.student, "H",
|
|
lesson.homework.theme.id),
|
|
date=django.utils.timezone.now())
|
|
lesson.comments.add(comment)
|
|
if lesson.status != 'F':
|
|
lesson.status = 'F'
|
|
action = ActionJ.objects.create(student=lesson.student,
|
|
a_type='S',
|
|
place=u'Курс '+u'\xab'+u'{0}'.format(lesson.homework.course.get_title())+u'\xbb'+u', домашнее задание # {0}'.format(
|
|
lesson.homework.theme.sort),
|
|
text=u'Ваше <a href="{2}/courses/homework/{0}#comment_{1}" '
|
|
u'style="color: blue;">домашнее задание</a> одобрено преподавателем.'.format(
|
|
lesson.material.id, comment.id, DOMAIN))
|
|
if lesson.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
set_read_flag(lesson.student, lesson.homework.course)
|
|
lesson.save()
|
|
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
if parent_id != '0':
|
|
comment2 = Comment.objects.get(id=parent_id)
|
|
if comment2.owner.check_subscription('new_comment'):
|
|
sent_comment_news(comment2, comment, lesson)
|
|
context['code'] = '1'
|
|
context['data'] = comment.id
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def send_exam_cancel_teach_comment(request, context):
|
|
# Отправка попытки на доработку для преподавателя
|
|
# TODO: Перейти на модель попыток
|
|
if request.POST['comment_sent_text']:
|
|
lesson = ExamJ.objects.get(student__id=request.POST['comment_for_user_id'],
|
|
material__course__id=request.POST['comment_for_theme_id'], teacher=request.user)
|
|
parent_id = request.POST['reply_for_comment_id']
|
|
comment = Comment.objects.create(parent_id=parent_id, owner=request.user, status='F',
|
|
text=request.POST['comment_sent_text'], date=django.utils.timezone.now())
|
|
lesson.comments.add(comment)
|
|
if lesson.status != 'F':
|
|
lesson.status = 'E'
|
|
action = ActionJ.objects.create(student=lesson.student,
|
|
a_type='D',
|
|
place=u'Экзаменационная работа '+u'\xab'+u'{0}'.format(lesson.exam.course.get_title())+u'\xbb',
|
|
text=u'Ваша работа отправлена на доработку. '
|
|
u'<a href="{1}/courses/exam/{0}" style="color: blue;">'
|
|
u'Вам необходимо провести работу над ошибками</a>'.format(
|
|
lesson.material.id, DOMAIN))
|
|
if lesson.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
lesson.save()
|
|
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
if parent_id != '0':
|
|
comment2 = Comment.objects.get(id=parent_id)
|
|
if comment2.owner.check_subscription('new_comment'):
|
|
sent_comment_news(comment2, comment, lesson)
|
|
context['code'] = '1'
|
|
context['data'] = comment.id
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def send_exam_accept_teach_comment(request, context):
|
|
# Принятие экзамена для преподавателя
|
|
# TODO: Перейти на модель попыток
|
|
lesson = ExamJ.objects.get(student__id=request.POST['comment_for_user_id'],
|
|
material__course__id=request.POST['comment_for_theme_id'], teacher=request.user)
|
|
parent_id = request.POST['reply_for_comment_id']
|
|
comment = Comment.objects.create(parent_id=parent_id, owner=request.user, status='G',
|
|
text=request.POST['comment_sent_text'] +
|
|
request.POST['comment_sent_text'] + get_next_button(lesson.student, "E",
|
|
lesson.exam.course.id),
|
|
date=django.utils.timezone.now())
|
|
lesson.comments.add(comment)
|
|
if lesson.status != 'F':
|
|
lesson.status = 'F'
|
|
action = ActionJ.objects.create(student=lesson.student,
|
|
a_type='W',
|
|
place=u'Экзаменационная работа '+u'\xab'+u'{0}'.format(lesson.exam.course.get_title())+u'\xbb',
|
|
text=u'Ваша <a href="{1}/courses/exam/{0}#" '
|
|
u'style="color: blue;">экзаменационная работа</a> принята преподователем. '
|
|
u'Поздравляем вас!'.format(
|
|
lesson.material.id, DOMAIN))
|
|
if lesson.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
lesson.save()
|
|
# TODO: Много повторений в других методах, переделать на отдельный метод
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
if parent_id != '0':
|
|
comment2 = Comment.objects.get(id=parent_id)
|
|
if comment2.owner.check_subscription('new_comment'):
|
|
sent_comment_news(comment2, comment, lesson)
|
|
context['code'] = '1'
|
|
context['data'] = comment.id
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['theme', 'student'], method='POST', check_request=True)
|
|
def load_homework_comments_for_teacher(request, context):
|
|
# Получение комментариев для преподавателя
|
|
# TODO: Перейти на модель попыток
|
|
homework = HomeworkJ.objects.get(material__theme__id=request.POST['theme'], student__id=request.POST['student'],
|
|
teacher=request.user)
|
|
context['data'] = []
|
|
for i in homework.comments.filter(parent_id='0').order_by('date'):
|
|
context['data'].append(comment_fabric(i, __user=request.user))
|
|
|
|
if len(context['data']) == 0:
|
|
context['code'] = '0'
|
|
else:
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['theme', 'student'], method='POST', check_request=True)
|
|
def load_exam_comments_for_teacher(request, context):
|
|
# Полечение попыток экзамена
|
|
# TODO: Перейти на модель попыток
|
|
homework = ExamJ.objects.get(material__course__id=request.POST['theme'], student__id=request.POST['student'],
|
|
teacher=request.user)
|
|
context['data'] = []
|
|
for i in homework.comments.filter(parent_id='0').order_by('date'):
|
|
context['data'].append(comment_fabric(i, __user=request.user))
|
|
|
|
if len(context['data']) == 0:
|
|
context['code'] = '0'
|
|
else:
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['homework'], method='POST', check_request=True)
|
|
def load_homework_comments(request, context):
|
|
# Загрузка комментариев по ДЗ
|
|
# TODO: Перейти на модель попыток
|
|
homework = HomeworkJ.objects.get(material__id=request.POST['homework'], student=request.user)
|
|
context['data'] = []
|
|
for i in homework.comments.filter(parent_id='0').order_by('date'):
|
|
context['data'].append(comment_fabric(i, __user=request.user))
|
|
|
|
if len(context['data']) == 0:
|
|
context['code'] = '0'
|
|
else:
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def sent_exam_comment(request, context):
|
|
# Отправка попытки сутедентом
|
|
context['data'] = {}
|
|
context['code'] = '0'
|
|
if request.POST['exam_text']:
|
|
exam = ExamJ.objects.get(id=request.POST['exam_id'], student=request.user)
|
|
h_status = exam.get_status_flag()
|
|
if h_status not in ['N', 'F']:
|
|
ht, c = ExamTry.objects.get_or_create(parent=exam, success=False, f_date=None, student=request.user,
|
|
material=exam.material)
|
|
comment = Comment.objects.create(owner=request.user, text=request.POST['exam_text'],
|
|
date=django.utils.timezone.now())
|
|
ht.comments.add(comment)
|
|
ht.save()
|
|
if c:
|
|
action = ActionJ.objects.create(student=exam.student,
|
|
a_type='I',
|
|
place=u'Курс '+u'\xab'+u'{0}'.format(
|
|
exam.material.course.get_title())+u'\xbb'+u', Экзаменационная работа',
|
|
text=u'Ваша <a href="{2}/courses/exam/{0}#comment_{1}" '
|
|
u'style="color: blue;">экзаменационная работа</a> отправлена на проверку.'
|
|
u''.format(exam.material.id, comment.id, DOMAIN))
|
|
exam.date = datetime.datetime.now()
|
|
if exam.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
# Отправка письма и активности преподавателю
|
|
sent_to_teacher_answer(ActionJ.objects.create(
|
|
student=ht.teacher,
|
|
place=u'Студент: {0}, Экзамен'.format(exam.student),
|
|
text=u'Текст: {0} <br><a href="{2}/teacher/workshop/exam/{1}" target="_blank">Перейти к проверке</a>'.format(comment.text, exam.id, DOMAIN),
|
|
a_type='P'
|
|
))
|
|
# Проверка и загрузка файлов
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
context['code'] = '1'
|
|
context['data'] = {'try': ht.get_head_face(), 'comment': comment.get_face()}
|
|
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=True, need_keys=['exam'], method='POST', check_request=True)
|
|
def load_exam_comments(request, context):
|
|
# Загрузка попыток по экзаменам
|
|
# TODO: Перейти на модель попыток
|
|
exam = ExamJ.objects.get(material__id=request.POST['exam'])
|
|
context['data'] = []
|
|
for i in exam.comments.filter(parent_id='0').order_by('date'):
|
|
context['data'].append(comment_fabric(i, __user=request.user))
|
|
|
|
if len(context['data']) == 0:
|
|
context['code'] = '0'
|
|
else:
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def delete_comment(request, context):
|
|
comment = Comment.objects.get(id=request.POST.get('comment'))
|
|
if comment.owner == request.user or request.user.is_admin:
|
|
if request.POST.get('text'):
|
|
letter_delete_comment(comment, request.POST.get('text'))
|
|
|
|
if Comment.objects.filter(parent_id=comment.id, closed=False).exists():
|
|
comment.closed = True
|
|
comment.save()
|
|
else:
|
|
comment.delete()
|
|
if comment.parent_id != '0' and Comment.objects.filter(id=comment.parent_id,
|
|
closed=True).exists() and not Comment.objects.filter(
|
|
parent_id=comment.parent_id).exists():
|
|
Comment.objects.get(id=comment.parent_id).delete()
|
|
|
|
context['code'] = '1'
|
|
else:
|
|
context['code'] = '0'
|
|
context['response'] = u'Вы не можете удалить коммментарий, автором которого вы не являетесь'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_lesson_comments_length(request, context):
|
|
context['code'] = '1'
|
|
context['data'] = Lesson.objects.get(id=request.GET['id']).comments.filter(closed=False).count()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_homework_comments_length(request, context):
|
|
context['code'] = '1'
|
|
|
|
try:
|
|
result = HomeworkJ.objects.get(material=Homework.objects.get(id=request.GET['id']),
|
|
student=request.user).get_comments_length()
|
|
except HomeworkJ.DoesNotExist:
|
|
result = 0
|
|
|
|
context['data'] = result
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_homework_comments_length_for_teacher(request, context):
|
|
context['code'] = '1'
|
|
context['data'] = HomeworkJ.objects.get(material__theme__id=request.GET['id'], teacher=request.user,
|
|
student__id=request.GET['student']).get_comments_length()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_exam_comments_length_for_teacher(request, context):
|
|
context['code'] = '1'
|
|
context['data'] = ExamJ.objects.get(material__course__id=request.GET['id'], teacher=request.user,
|
|
student__id=request.GET['student']).get_comments_length()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_exam_comments_length(request, context):
|
|
context['code'] = '1'
|
|
context['data'] = ExamJ.objects.get(material__id=request.GET['id'], student=request.user).get_comments_length()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def get_comment_text(request, context):
|
|
try:
|
|
comment = Comment.objects.get(id=request.GET['comment'])
|
|
except Comment.DoesNotExist:
|
|
context['code'] = '0'
|
|
else:
|
|
context['code'] = '1'
|
|
context['data'] = comment.get_text()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['ID'], check_request=True, method='GET')
|
|
def get_lesson_context(request, context):
|
|
if request.user.in_role != 'U':
|
|
lesson = Lesson.objects.get(id=request.GET['ID'])
|
|
materials = [] if lesson.materials.all() else ''
|
|
for i in lesson.materials.all():
|
|
materials.append({
|
|
'url': i.original.url,
|
|
'id': 'single_image' if i.f_format.f_type == 'I' else '',
|
|
'file_name': i.get_file_name(),
|
|
'name_for_user': i.get_name_for_user(),
|
|
'icon_class': i.f_format.icon_class
|
|
})
|
|
context['data'] = {
|
|
'video': lesson.video,
|
|
'description': lesson.description,
|
|
'title': lesson.title,
|
|
'materials': materials
|
|
}
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['start_place_type', 'start_place_id'], method='GET', check_request=True)
|
|
def get_next_button_ajax(request, context):
|
|
# Получение следующей кнопки
|
|
context['data'] = get_next_button(request.user,
|
|
request.GET['start_place_type'],
|
|
request.GET['start_place_id'])
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=True, need_keys=['id'], method='GET', check_request=True)
|
|
def by_course_data(request, context):
|
|
# Получить информацию окна покупки для курса
|
|
try:
|
|
course = Course.objects.get(id=request.GET['id'])
|
|
except Course.DoesNotExist:
|
|
context['code'] = '1'
|
|
else:
|
|
context['code'] = '1'
|
|
context['data'] = {
|
|
'image': course.buy_icon.url if course.buy_icon else '/static/img/1442791218_certificate.png',
|
|
'name': course.title,
|
|
'basic': CourseTheme.objects.filter(course=course,
|
|
_type='B').count() if not course.use_fail or course.basic_len == 0 else course.basic_len,
|
|
'addition': CourseTheme.objects.filter(
|
|
Q(course=course, _type='A') | Q(course=course, _type='P') | Q(course=course,
|
|
_type='M')).count() if not course.use_fail or course.addition_len == 0 else course.addition_len,
|
|
'min_price': 6777 if course.min_price == 0 else course.min_price
|
|
}
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False, need_keys=['ID'], method='GET', check_request=True)
|
|
def get_homework_context(request, context):
|
|
# Получение информации из ДЗ
|
|
if request.user.in_role != 'U':
|
|
homework = CourseTheme.objects.get(id=request.GET['ID']).get_homework()
|
|
materials = [] if homework.materials.all() else ''
|
|
for i in homework.materials.all():
|
|
materials.append({
|
|
'url': i.original.url,
|
|
'id': 'single_image' if i.f_format.f_type == 'I' else '',
|
|
'file_name': i.get_file_name(),
|
|
'name_for_user': i.get_name_for_user(),
|
|
'icon_class': i.f_format.icon_class
|
|
})
|
|
context['data'] = {
|
|
'description': homework.description,
|
|
'materials': materials
|
|
}
|
|
context['code'] = '1'
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def sent_homework_up_teacher(request, context):
|
|
context['data'] = {}
|
|
context['code'] = '0'
|
|
if request.POST['homework_text']:
|
|
homework = HomeworkJ.objects.get(id=request.POST['homework_id'])
|
|
h_status = homework.get_status_flag()
|
|
if h_status not in ['N', 'F']:
|
|
ht, c = HomeworkTry.objects.get_or_create(parent=homework, success=False, f_date=None, teacher=request.user,
|
|
material=homework.material, student=homework.student)
|
|
comment = Comment.objects.create(owner=request.user, status='G',
|
|
text=request.POST['homework_text'],
|
|
date=django.utils.timezone.now())
|
|
ht.comments.add(comment)
|
|
|
|
action = ActionJ.objects.create(student=ht.student,
|
|
a_type='I',
|
|
place=u'Курс '+u'\xab'+u'{0}'.format(homework.material.course.get_title())+u'\xbb'+u', домашнее задание # {0}'.format(homework.material.theme.sort),
|
|
text=u'Ваше <a href="{2}/courses/homework/{0}#comment_{1}" '
|
|
u'style="color: blue;">домашнее задание</a> одобрено преподавателем.'.format(
|
|
homework.material.id, comment.id, DOMAIN))
|
|
|
|
if homework.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
# Отправка письма и активности преподавателю
|
|
sent_to_teacher_answer(ActionJ.objects.create(
|
|
student=ht.get_teacher(),
|
|
place=u'Студент: {0}, домашнее задание # {1}'.format(
|
|
homework.student,
|
|
homework.material.theme.sort),
|
|
text=u'Задание одобрено',
|
|
a_type='S'
|
|
))
|
|
|
|
# Проверка и загрузка файлов
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
context['code'] = '1'
|
|
context['data'] = {'try': ht.get_head_face(), 'comment': comment.get_face()}
|
|
ht.saw_this()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def sent_homework_down_teacher(request, context):
|
|
context['data'] = {}
|
|
context['code'] = '0'
|
|
if request.POST['homework_text'] and request.user.in_role == 'T':
|
|
homework = HomeworkJ.objects.get(id=request.POST['homework_id'])
|
|
h_status = homework.get_status_flag()
|
|
if h_status not in ['N', 'F']:
|
|
ht, c = HomeworkTry.objects.get_or_create(parent=homework, success=False, f_date=None, teacher=request.user,
|
|
material=homework.material, student=homework.student)
|
|
comment = Comment.objects.create(owner=request.user, date=django.utils.timezone.now(), status='F',
|
|
text=request.POST['homework_text'])
|
|
ht.comments.add(comment)
|
|
ht.success = False
|
|
ht.f_date = datetime.datetime.now()
|
|
ht.save()
|
|
action = ActionJ.objects.create(student=ht.student,
|
|
a_type='S',
|
|
place=u'Курс '+u'\xab'+u'{0}'.format(homework.material.course.get_title())+u'\xbb'+u', домашнее задание # {0}'.format(homework.material.theme.sort),
|
|
text=u'Ваше домашнее задание проверено преподавателем. '
|
|
u'<a href="{2}/courses/homework/{0}#comment_{1}" '
|
|
u'style="color: blue;">Вам необходимо провести работу над ошибками'
|
|
u'</a>'.format(
|
|
homework.material.id, comment.id, DOMAIN))
|
|
|
|
if ht.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
|
|
# Отправка письма и активности преподавателю
|
|
ActionJ.objects.create(
|
|
student=ht.get_teacher(),
|
|
place=u'Студент: {0}, домашнее задание # {1}'.format(
|
|
homework.student,
|
|
homework.material.theme.sort),
|
|
text=u'Задание отправлено на доработку',
|
|
a_type='D'
|
|
)
|
|
|
|
# Проверка и загрузка файлов
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
context['code'] = '1'
|
|
context['data'] = {'try': ht.get_head_face(), 'comment': comment.get_face()}
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def sent_exam_up_teacher(request, context):
|
|
context['data'] = {}
|
|
context['code'] = '0'
|
|
if request.POST['exam_text']:
|
|
homework = ExamJ.objects.get(id=request.POST['exam_id'])
|
|
h_status = homework.get_status_flag()
|
|
if h_status not in ['N', 'F']:
|
|
ht, c = ExamTry.objects.get_or_create(parent=homework, success=False, f_date=None, teacher=request.user,
|
|
material=homework.material, student=homework.student)
|
|
comment = Comment.objects.create(owner=request.user, status='G',
|
|
text=request.POST['exam_text'],
|
|
date=django.utils.timezone.now())
|
|
ht.comments.add(comment)
|
|
action = ActionJ.objects.create(student=ht.student,
|
|
a_type='W',
|
|
place=u'Экзаменационная работа '+u'\xab'+u'{0}'.format(
|
|
ht.material.course.get_title())+u'\xbb',
|
|
text=u'Ваша <a href="{1}/courses/exam/{0}#" '
|
|
u'style="color: blue;">экзаменационная работа</a> принята преподователем. '
|
|
u'Поздравляем вас!'.format(
|
|
ht.material.id, DOMAIN))
|
|
|
|
if homework.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
# Отправка письма и активности преподавателю
|
|
ActionJ.objects.create(
|
|
student=ht.get_teacher(),
|
|
place=u'Студент: {0}, Экзамен'.format(homework.student),
|
|
text=u'Экзамен одобрен',
|
|
a_type='S'
|
|
)
|
|
|
|
if not ExamTry.objects.filter(teacher=homework.teacher, success=True).exists():
|
|
# Отправка письма и активности преподавателю
|
|
ActionJ.objects.create(
|
|
student=ht.teacher,
|
|
place=u'Студент: {0}, Экзамен'.format(homework.student),
|
|
text=u'Поздравляем. Ваш первый студент дошедший до конца',
|
|
a_type='W'
|
|
)
|
|
|
|
# Проверка и загрузка файлов
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
context['code'] = '1'
|
|
context['data'] = {'try': ht.get_head_face(), 'comment': comment.get_face()}
|
|
ht.saw_this()
|
|
return context
|
|
|
|
|
|
@api_decor(without_auth=False)
|
|
def sent_exam_down_teacher(request, context):
|
|
context['data'] = {}
|
|
context['code'] = '0'
|
|
if request.POST['exam_text'] and request.user.in_role == 'T':
|
|
homework = ExamJ.objects.get(id=request.POST['exam_id'])
|
|
h_status = homework.get_status_flag()
|
|
if h_status not in ['N', 'F']:
|
|
ht, c = ExamTry.objects.get_or_create(parent=homework, success=False, f_date=None, teacher=request.user,
|
|
material=homework.material, student=homework.student)
|
|
comment = Comment.objects.create(owner=request.user, date=django.utils.timezone.now(), status='F',
|
|
text=request.POST['exam_text'])
|
|
ht.comments.add(comment)
|
|
ht.f_date = datetime.datetime.now()
|
|
ht.save()
|
|
action = ActionJ.objects.create(student=ht.student,
|
|
a_type='D',
|
|
place=u'Экзаменационная работа '+u'\xab'+u'{0}'.format(
|
|
ht.material.course.get_title())+u'\xbb',
|
|
text=u'Ваша работа отправлена на доработку. '
|
|
u'<a href="{1}/courses/exam/{0}" style="color: blue;">'
|
|
u'Вам необходимо провести работу над ошибками</a>'.format(
|
|
ht.material.id, DOMAIN))
|
|
|
|
if ht.student.check_subscription('teacher'):
|
|
sent_teacher_answer(action)
|
|
|
|
# Отправка письма и активности преподавателю
|
|
ActionJ.objects.create(
|
|
student=ht.get_teacher(),
|
|
place=u'Студент: {0}, Экзамен'.format(homework.student),
|
|
text=u'Задание отправлено на доработку',
|
|
a_type='D'
|
|
)
|
|
|
|
# Проверка и загрузка файлов
|
|
r = re.compile('^file_')
|
|
files_keys = []
|
|
for i in request.POST.keys():
|
|
if r.match(i): files_keys.append(i)
|
|
|
|
if files_keys:
|
|
for i in files_keys:
|
|
comment.files.add(Storage.objects.get(key=request.POST[i]))
|
|
comment.save()
|
|
|
|
context['code'] = '1'
|
|
context['data'] = {'try': ht.get_head_face(), 'comment': comment.get_face()}
|
|
return context
|
|
|