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.
73 lines
2.4 KiB
73 lines
2.4 KiB
# coding=utf-8
|
|
import os
|
|
import django
|
|
import sys
|
|
import datetime
|
|
|
|
start = datetime.datetime.now()
|
|
sys.path.append("/var/www/projects/codemy/")
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
|
|
django.setup()
|
|
|
|
from courses.models import Course, CourseTheme, Exam, Homework, Lesson
|
|
from journals.models import TeacherJ, CourseThemeJ, LessonJ, HomeworkJ, ExamJ
|
|
from access.models import User
|
|
from lms.tools import show_progress
|
|
|
|
|
|
def check_this(obj, collection):
|
|
if not collection.get(obj.material.id):
|
|
collection[obj.material.id] = True
|
|
else:
|
|
obj.delete()
|
|
|
|
|
|
def check_TJ(_course, _user):
|
|
try:
|
|
_tj = TeacherJ.objects.get(course=_course, student=_user)
|
|
except TeacherJ.DoesNotExist:
|
|
return None
|
|
except TeacherJ.MultipleObjectsReturned:
|
|
_tmp = TeacherJ.objects.filter(course=_course, student=_user).order_by('start_date')
|
|
_tj = _tmp[0]
|
|
for i in _tmp:
|
|
if i != _tj:
|
|
i.delete()
|
|
|
|
return _tj
|
|
|
|
|
|
_all = User.objects.all().count()
|
|
_n = 0
|
|
_about_time = []
|
|
for _user in User.objects.all():
|
|
_st = datetime.datetime.now()
|
|
for _course in Course.objects.all():
|
|
_l = dict({i.id: False for i in Lesson.objects.filter(course=_course)})
|
|
_h = dict({i.id: False for i in Homework.objects.filter(course=_course)})
|
|
_e = dict({i.id: False for i in Exam.objects.filter(course=_course)})
|
|
_t = dict({i.id: False for i in CourseTheme.objects.filter(course=_course)})
|
|
|
|
_tj = check_TJ(_course, _user)
|
|
|
|
if _tj:
|
|
for _cj in CourseThemeJ.objects.filter(parent=_tj):
|
|
check_this(_cj, _t)
|
|
|
|
for _lj in LessonJ.objects.filter(parent__parent=_tj):
|
|
check_this(_lj, _l)
|
|
|
|
for _hj in HomeworkJ.objects.filter(parent__parent=_tj):
|
|
check_this(_hj, _h)
|
|
|
|
for _ej in ExamJ.objects.filter(parent__parent=_tj):
|
|
check_this(_ej, _e)
|
|
|
|
_ft = datetime.datetime.now()
|
|
_about_time.append((_ft - _st).microseconds)
|
|
_average = (((_all - _n) * (sum(_about_time) / len(_about_time)))/1000000)/60
|
|
show_progress(_all, _n, post=' // "Удаление дуближей журналов" // Расчетное оставщееся время Этапа: {0:6.4} мин '.format(_average))
|
|
_n += 1
|
|
|
|
finish = datetime.datetime.now()
|
|
print('\nTIME: %s seconds' % (finish - start).seconds)
|
|
|