parent
cf8727331f
commit
606000fb18
28 changed files with 0 additions and 7301 deletions
@ -1,9 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
apps = ['access', 'courses', 'finance', 'management', 'storage'] |
||||
|
||||
for app in apps: |
||||
os.system('python manage.py dumpdata {0} -o fixtures/{0}.json'.format(app)) |
||||
|
||||
print u'Загружаю медиа' |
||||
os.system('tar czf media.tar.gz media/') |
||||
@ -1,15 +0,0 @@ |
||||
# coding=utf-8 |
||||
import json |
||||
|
||||
print 'Вытаскиваю материалы' |
||||
_fixture = json.load(open('fixtures/courses.json')) |
||||
|
||||
loader = ('courses.course') |
||||
w = open('fixtures/courses.json', 'w') |
||||
for i in _fixture: |
||||
if i['model'] in loader.keys(): |
||||
i['model'] = loader[i['model']] |
||||
|
||||
json.dump(_fixture, w) |
||||
w.close() |
||||
print 'Закончил вытаскивание' |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@ |
||||
[] |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,105 +0,0 @@ |
||||
# coding=utf-8 |
||||
|
||||
|
||||
def set_hm_success(obj): |
||||
# Получить статус домашку в success |
||||
if obj['fields']['status'] == 'F': |
||||
return True |
||||
else: |
||||
return False |
||||
|
||||
|
||||
def create_try(obj): |
||||
# Создать попытку со всеми комментариями и результатом |
||||
global HT |
||||
HT += 1 |
||||
if obj["fields"]["teacher"]: |
||||
_journal_result.append({"model": "journals.homeworktry", |
||||
"pk": HT, "fields": {"parent": obj['pk'], "student": obj['fields']['student'], |
||||
"teacher": obj['fields']['teacher'], |
||||
"material": obj['fields']['homework'], |
||||
"date": obj['fields']['date'], "f_date": obj['fields']['f_date'], |
||||
"comments": obj['fields']['comments'], |
||||
"success": set_hm_success(obj), |
||||
"expired": False}}) |
||||
|
||||
print 'Создание карты курса' |
||||
# id: {'themes': {}, 'exam': 'id экзамена'} |
||||
# 'themes': {'id темы': {'lessons': [список id уроков], 'homework': id дз} |
||||
_courses_map = {} |
||||
for i in _fixture: |
||||
if i['model'] == 'courses.course': |
||||
if i['pk'] not in _courses_map.keys(): |
||||
# Добавить курс на карту |
||||
_courses_map[i['pk']] = {'themes': {}, 'exam': {}} |
||||
|
||||
elif i['model'] == 'courses.coursetheme': |
||||
# Добавить тему в курс |
||||
if i['pk'] not in _courses_map[i['fields']['course']]['themes'].keys(): |
||||
_courses_map[i['fields']['course']]['themes'][i['pk']] = {'lessons': set({}), 'homework': ''} |
||||
|
||||
elif i['model'] == 'courses.exam': |
||||
# Присвоить курсу ID экзамена |
||||
_courses_map[i['fields']['course']]['exam'] = i['pk'] |
||||
|
||||
elif i['model'] == 'courses.homework': |
||||
# Добавить домашнее задание в тему |
||||
_courses_map[i['fields']['course']]['themes'][i['fields']['theme']]['homework'] = i['pk'] |
||||
|
||||
elif i['model'] == 'courses.lesson': |
||||
_courses_map[i['fields']['course']]['themes'][i['fields']['theme']]['lessons'].add(i['pk']) |
||||
|
||||
# Вторая обработка |
||||
print 'Постобработка' |
||||
for key, value in _theme_counts.items(): |
||||
value['fix'] = int(value['fix']) + 1 |
||||
value['last'] = value['fix'] |
||||
# +1 - готовый ID для новой темы |
||||
|
||||
print 'Обход по карте' |
||||
_merge_map = { |
||||
'journals.teacherj': {'exclude': ['lessons', 'homeworks', 'exam', 'f_date'], |
||||
'new': {'progress': 0}, |
||||
'rename': {}, |
||||
'rebuild': {}}, |
||||
'journals.lessonj': {'exclude': ['status'], |
||||
'new': {'success': True, 'parent': None}, |
||||
'rename': {'lesson': 'material'}, |
||||
'rebuild': {}}, |
||||
'journals.homeworkj': {'exclude': ['status', 'comments'], |
||||
'new': {'success': set_hm_success, 'parent': None}, |
||||
'rename': {'homework': 'material'}, |
||||
'rebuild': {'comments': create_try}}, |
||||
'journals.examj': {'exclude': ['status', 'comments'], |
||||
'new': {'success': False, 'parent': None}, |
||||
'rename': {'exam': 'material'}, |
||||
'rebuild': {}}, |
||||
} |
||||
|
||||
# Преобразовать модели объектов |
||||
_journal_result = [] |
||||
for i in _journal: |
||||
if i['model'] in _merge_map.keys(): |
||||
__tmp = {} |
||||
for key, value in _merge_map[i['model']]['rebuild'].items(): |
||||
value(i) |
||||
for key, value in i['fields'].items(): |
||||
# Исключить не используемые поля |
||||
if key not in _merge_map[i['model']]['exclude']: |
||||
if key in _merge_map[i['model']]['rename'].keys(): |
||||
# Переименовать переменные |
||||
__tmp[_merge_map[i['model']]['rename'][key]] = value |
||||
else: |
||||
__tmp[key] = value |
||||
for key, value in _merge_map[i['model']]['new'].items(): |
||||
if type(value) in [str, int, bool] or value is None: |
||||
__tmp[key] = value |
||||
else: |
||||
# Получение не определенного заранее ответа |
||||
__tmp[key] = value(i) |
||||
# Как получить ID журнала темы |
||||
__tmp = {"pk": i['pk'], "model": i['model'], "fields": __tmp} |
||||
_journal_result.append(__tmp) |
||||
else: |
||||
_journal_result.append(i) |
||||
json.dump(_journal_result, open('fixtures/journals.json', 'w')) |
||||
@ -1,63 +0,0 @@ |
||||
м# coding=utf-8 |
||||
import os |
||||
|
||||
import django |
||||
|
||||
from post_fixtures import main |
||||
from _utils.clear_db import main as clear_main |
||||
|
||||
print '==== Загружаю DJANGO' |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from storage.models import Storage, CroppedImage |
||||
|
||||
print '==== Загрузил DJANGO' |
||||
# == Загрузка данных |
||||
|
||||
print '==== Обрабатываю модели' |
||||
|
||||
# Загрузка материалов |
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
||||
print BASE_DIR |
||||
APPS = ('storage', 'access', 'management', 'courses', 'finance', ) |
||||
#courses_models = ('courses.course', 'courses.coursetheme', 'courses.lesson', 'courses.homework', 'courses.exam') |
||||
#journal_models = ('courses.teacherj', 'courses.lessonj', 'courses.homeworkj', 'courses.examj') |
||||
#finance_models = ("courses.bill", 'courses.price', 'courses.servicerequest') |
||||
|
||||
|
||||
clear_main() |
||||
os.system('python merge_fixtures.py') |
||||
|
||||
# Загрузить фикстуры не изменившихся моделей |
||||
print '==== Заливаю модели' |
||||
for app in APPS: |
||||
print app.upper() |
||||
os.system('python manage.py loaddata fixtures/{0}.json'.format(app)) |
||||
|
||||
print '==== Заливаю MEDIA' |
||||
os.system('tar xfz media.tar.gz') |
||||
print '==== Проверка заливки' |
||||
# Проверить существование файлов из storage |
||||
errors = [] |
||||
for store in Storage.objects.all(): |
||||
# Проверить original, f_format.icon |
||||
obj = (store.original.path if store.original else '', |
||||
store.f_format.icon.path if store.f_format and store.f_format.icon else '') |
||||
for i in obj: |
||||
if i and not os.path.exists(i): |
||||
errors.append(i) |
||||
#print 'Ошибки файлов: {0}'.format(len(errors)) |
||||
|
||||
for store in CroppedImage.objects.all(): |
||||
# croppedimage.big, croppedimage.middle, croppedimage.small |
||||
obj = (store.big.path if store.big else '', |
||||
store.middle.path if store.middle else '', |
||||
store.small.path if store.small else '') |
||||
for i in obj: |
||||
if i and not os.path.exists(i): |
||||
errors.append(i) |
||||
#print 'Ошибки файлов: {0}'.format(len(errors)) |
||||
print 'Ошибки файлов: {0}'.format(len(errors)) |
||||
#print errors |
||||
|
||||
main() |
||||
@ -1,277 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
import django |
||||
import sys |
||||
import simplejson as json |
||||
|
||||
sys.path.append("/var/www/projects/lms/") |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from __migrate.post_fixtures import show_progress |
||||
from courses.models import Course, CourseTheme, Lesson, Homework, Exam, Skills, SkillJ, Achievements, CourseBuilder |
||||
from management.models import Comment |
||||
from storage.models import Storage |
||||
|
||||
_fixture = json.load(open('fixtures/courses.json')) |
||||
user_pk = 1 |
||||
courses = [] |
||||
lessons = [] |
||||
themes = [] |
||||
homeworks = [] |
||||
exams = [] |
||||
skills = [] |
||||
skillsj = [] |
||||
achs = [] |
||||
|
||||
|
||||
def new_index(model, key, obj): |
||||
if str(key) in pk_map[model]: |
||||
return obj.objects.get(id=pk_map[model][str(key)]) |
||||
return None |
||||
|
||||
|
||||
# Пример записи маршрута |
||||
pk_map = json.load(open('pk_maps.json')) |
||||
if 'courses.course' not in pk_map.keys(): |
||||
pk_map['courses.course'] = {} |
||||
|
||||
if 'courses.coursetheme' not in pk_map.keys(): |
||||
pk_map['courses.coursetheme'] = {} |
||||
|
||||
if 'courses.lesson' not in pk_map.keys(): |
||||
pk_map['courses.lesson'] = {} |
||||
|
||||
if 'courses.homework' not in pk_map.keys(): |
||||
pk_map['courses.homework'] = {} |
||||
|
||||
if 'courses.exam' not in pk_map.keys(): |
||||
pk_map['courses.exam'] = {} |
||||
|
||||
if 'courses.skills' not in pk_map.keys(): |
||||
pk_map['courses.skills'] = {} |
||||
|
||||
if 'courses.skillj' not in pk_map.keys(): |
||||
pk_map['courses.skillj'] = {} |
||||
|
||||
if 'courses.achievements' not in pk_map.keys(): |
||||
pk_map['courses.achievements'] = {} |
||||
|
||||
for i in _fixture: |
||||
if i['model'] == 'courses.course': |
||||
if i not in courses: |
||||
courses.append(i) |
||||
|
||||
elif i['model'] == 'courses.coursetheme': |
||||
if i not in themes: |
||||
themes.append(i) |
||||
|
||||
elif i['model'] == 'courses.lesson': |
||||
if i not in lessons: |
||||
lessons.append(i) |
||||
|
||||
elif i['model'] == 'courses.homework': |
||||
if i not in homeworks: |
||||
homeworks.append(i) |
||||
|
||||
elif i['model'] == 'courses.exam': |
||||
if i not in exams: |
||||
exams.append(i) |
||||
|
||||
elif i['model'] == 'courses.skills': |
||||
if i not in skillsj: |
||||
skills.append(i) |
||||
|
||||
elif i['model'] == 'courses.skillj': |
||||
if i not in skillsj: |
||||
skillsj.append(i) |
||||
|
||||
elif i['model'] == 'courses.achievements': |
||||
if i not in achs: |
||||
achs.append(i) |
||||
|
||||
print '\nCourse' |
||||
_now = 0 |
||||
big_len = len(courses) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in courses: |
||||
c = Course.objects.create( |
||||
level=i['fields']['level'], |
||||
public=True, |
||||
title=i['fields']['title'], |
||||
description=i['fields']['description'], |
||||
image=i['fields']['image'], |
||||
big_image=i['fields']['big_image'], |
||||
page=i['fields']['page'], |
||||
preview=i['fields']['preview'], |
||||
sort=i['fields']['sort'], |
||||
use_fail=i['fields']['use_fail'], |
||||
basic_len=i['fields']['basic_len'], |
||||
addition_len=i['fields']['addition_len'], |
||||
min_price=i['fields']['min_price'], |
||||
buy_icon=i['fields']['buy_icon'] |
||||
) |
||||
|
||||
pk_map['courses.course'][str(i['pk'])] = str(c.id) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
|
||||
print u'\nCourseTheme' |
||||
_now = 0 |
||||
big_len = len(themes) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in themes: |
||||
c = CourseTheme.objects.create( |
||||
price_type='E' if i['fields']['type'] == 'A' else i['fields']['type'], |
||||
_type='E' if i['fields']['type'] == 'A' else i['fields']['type'], |
||||
icon=i['fields']['icon'], |
||||
course=new_index('courses.course', i['fields']['course'], Course), |
||||
sort=i['fields']['sort'], |
||||
title=i['fields']['title'], |
||||
description=i['fields']['description'], |
||||
) |
||||
# print i['fields']['course'] |
||||
# print new_index('courses.course', i['fields']['course'], Course) |
||||
pk_map['courses.coursetheme'][str(i['pk'])] = str(c.id) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
|
||||
print u'\nLessons' |
||||
_now = 0 |
||||
big_len = len(lessons) |
||||
show_progress(big_len, _now) |
||||
for i in lessons: |
||||
c = Lesson.objects.create( |
||||
free=i['fields']['free'], |
||||
token=i['fields']['token'], |
||||
title=i['fields']['title'], |
||||
sort=i['fields']['sort'], |
||||
course=new_index('courses.course', i['fields']['course'], Course), |
||||
theme=new_index('courses.coursetheme', i['fields']['theme'], CourseTheme), |
||||
description=i['fields']['description'], |
||||
video=i['fields']['video'] |
||||
) |
||||
for key in i['fields']['materials']: |
||||
c.materials.add(new_index('storage.storage', key, Storage)) |
||||
|
||||
for key in i['fields']['comments']: |
||||
# print key |
||||
# print new_index('management.comment', key, Comment) |
||||
c.comments.add(new_index('management.comment', key, Comment)) |
||||
|
||||
pk_map['courses.lesson'][str(i['pk'])] = str(c.id) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
|
||||
print u'\nHomework' |
||||
_now = 0 |
||||
big_len = len(homeworks) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in homeworks: |
||||
c = Homework.objects.create( |
||||
token=i['fields']['token'], |
||||
course=new_index('courses.course', i['fields']['course'], Course), |
||||
theme=new_index('courses.coursetheme', i['fields']['theme'], CourseTheme), |
||||
description=i['fields']['description'], |
||||
sort=1 |
||||
) |
||||
for key in i['fields']['materials']: |
||||
c.materials.add(new_index('storage.storage', key, Storage)) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['courses.homework'][str(i['pk'])] = str(c.id) |
||||
|
||||
print u'\nExams' |
||||
_now = 0 |
||||
big_len = len(exams) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in exams: |
||||
tm = CourseTheme.objects.create( |
||||
course=new_index('courses.course', i['fields']['course'], Course), |
||||
_type='Ex' |
||||
) |
||||
pk_map['courses.coursetheme'][str(tm.id)] = str(tm.id) |
||||
c = Exam.objects.create( |
||||
token=i['fields']['token'], |
||||
sort=1, |
||||
course=new_index('courses.course', i['fields']['course'], Course), |
||||
theme=tm, |
||||
icon=new_index('storage.storage', i['fields']['diploma'], Storage), |
||||
title=i['fields']['title'], |
||||
description=i['fields']['description'], |
||||
diploma=new_index('storage.storage', i['fields']['diploma'], Storage) |
||||
) |
||||
for key in i['fields']['materials']: |
||||
c.materials.add(new_index('storage.storage', key, Storage)) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['courses.exam'][str(i['pk'])] = str(c.id) |
||||
|
||||
print u'\nПереформировать порядок' |
||||
for course in Course.objects.all(): |
||||
_count = 1 |
||||
#print course |
||||
for _type in ['B', 'M', 'Ex', 'E', 'P']: |
||||
for theme in CourseTheme.objects.filter(course=course, _type=_type): |
||||
theme.sort = _count |
||||
_count += 1 |
||||
theme.save() |
||||
#print _count |
||||
|
||||
print u'\nКарты курсов' |
||||
for course in Course.objects.all(): |
||||
CourseBuilder(course).main() |
||||
|
||||
print u'\nSkills' |
||||
_now = 0 |
||||
big_len = len(skills) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in skills: |
||||
c, c2 = Skills.objects.get_or_create( |
||||
title=i['fields']['title'], |
||||
color=i['fields']['color'] |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['courses.skills'][str(i['pk'])] = str(c.id) |
||||
|
||||
print u'\nSkillsJ' |
||||
_now = 0 |
||||
big_len = len(skillsj) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in skillsj: |
||||
c, c2 = SkillJ.objects.get_or_create( |
||||
skill=new_index('courses.skills', i['fields']['skill'], Skills), |
||||
lesson=new_index('courses.lesson', i['fields']['lesson'], Lesson), |
||||
size=i['fields']['size'] |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['courses.skillj'][str(i['pk'])] = str(c.id) |
||||
|
||||
print u'\nAchivements' |
||||
_now = 0 |
||||
big_len = len(achs) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in achs: |
||||
c, c2 = Achievements.objects.get_or_create( |
||||
tech_name=i['fields']['tech_name'], |
||||
icon=i['fields']['icon'], |
||||
title=i['fields']['title'], |
||||
image=i['fields']['image'], |
||||
background=i['fields']['background'], |
||||
border=i['fields']['border'], |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['courses.achievements'][str(i['pk'])] = str(c.id) |
||||
|
||||
for course in Course.objects.all(): |
||||
course.build_map() |
||||
json.dump(pk_map, open('pk_maps.json', 'w')) |
||||
@ -1,110 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
import django |
||||
import sys |
||||
import simplejson as json |
||||
|
||||
|
||||
sys.path.append("/var/www/projects/lms/") |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from __migrate.post_fixtures import show_progress |
||||
from courses.models import Course |
||||
from finance.models import Price, Bill, ServiceRequest |
||||
from access.models import User |
||||
|
||||
_fixture = json.load(open('fixtures/courses.json')) |
||||
user_pk = 1 |
||||
prices = [] |
||||
bills = [] |
||||
requests = [] |
||||
|
||||
|
||||
def new_index(model, key, obj): |
||||
if str(key) in pk_map[model]: |
||||
return obj.objects.get(id=pk_map[model][str(key)]) |
||||
return None |
||||
|
||||
|
||||
# Пример записи маршрута |
||||
pk_map = json.load(open('pk_maps.json')) |
||||
if 'finance.price' not in pk_map.keys(): |
||||
pk_map['finance.price'] = {} |
||||
|
||||
if 'finance.bill' not in pk_map.keys(): |
||||
pk_map['finance.bill'] = {} |
||||
|
||||
if 'finance.servicerequest' not in pk_map.keys(): |
||||
pk_map['finance.servicerequest'] = {} |
||||
|
||||
for i in _fixture: |
||||
if i['model'] == 'courses.price': |
||||
prices.append(i) |
||||
elif i['model'] == 'courses.bill': |
||||
bills.append(i) |
||||
elif i['model'] == 'courses.servicerequest': |
||||
requests.append(i) |
||||
|
||||
print u'\nPrice' |
||||
_now = 0 |
||||
big_len = len(prices) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in prices: |
||||
f, c = Price.objects.get_or_create( |
||||
m_type=i['fields']['m_type'], |
||||
public=i['fields']['public'], |
||||
title=i['fields']['title'], |
||||
cost=i['fields']['cost'], |
||||
course=new_index('courses.course', i['fields']['course'], Course), |
||||
description=i['fields']['description'] |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['finance.price'][str(i['pk'])] = str(f.id) |
||||
|
||||
print u'\nBill' |
||||
_now = 0 |
||||
big_len = len(bills) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in bills: |
||||
s = Bill.objects.create( |
||||
status=i['fields']['status'], |
||||
user=new_index('access.user', i['fields']['user'], User), |
||||
manager=new_index('access.user', i['fields']['manager'], User), |
||||
service=new_index('finance.price', i['fields']['service'], Price), |
||||
key=i['fields']['key'], |
||||
out_id=i['fields']['out_id'], |
||||
date=i['fields']['date'], |
||||
status_changed=i['fields']['status_changed'], |
||||
comment=i['fields']['comment'], |
||||
finish_date=i['fields']['finish_date'], |
||||
salt=i['fields']['salt'], |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['finance.bill'][str(i['pk'])] = str(s.id) |
||||
|
||||
print u'\nServiceRequest' |
||||
_now = 0 |
||||
big_len = len(requests) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in requests: |
||||
c = ServiceRequest.objects.create( |
||||
status=i['fields']['status'], |
||||
student=new_index('access.user', i['fields']['student'], User), |
||||
course=new_index('courses.course', i['fields']['course'], Course), |
||||
manager=new_index('access.user', i['fields']['manager'], User), |
||||
cancel_description=i['fields']['cancel_description'], |
||||
charge=i['fields']['charge'], |
||||
date=i['fields']['date'], |
||||
f_date=i['fields']['f_date'], |
||||
send=i['fields']['send'], |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['finance.servicerequest'][str(i['pk'])] = str(c.id) |
||||
|
||||
json.dump(pk_map, open('pk_maps.json', 'w')) |
||||
@ -1,111 +0,0 @@ |
||||
# coding=utf-8 |
||||
import json |
||||
|
||||
HT = 0 |
||||
|
||||
|
||||
print 'Приступил к МЕРДЖУ' |
||||
|
||||
loader = { |
||||
'courses.teacherj': 'journals.teacherj', |
||||
'courses.lessonj': 'journals.lessonj', |
||||
'courses.homeworkj': 'journals.homeworkj', |
||||
'courses.examj': 'journals.examj', |
||||
'courses.bill': 'finance.bill', |
||||
'courses.price': 'finance.price', |
||||
'courses.servicerequest': 'finance.servicerequest', |
||||
'courses.selfbillrequest': 'finance.selfbillrequest', |
||||
'courses.selfbillhistory': 'finance.selfbillhistory', |
||||
'courses.achievementj': 'journals.achievementj' |
||||
} |
||||
|
||||
_journal = [] |
||||
_finance = [] |
||||
_courses = [] |
||||
_theme_count = 0 |
||||
_theme_counts = {} |
||||
M_material = '' |
||||
_fixture = json.load(open('fixtures/courses.json')) |
||||
# Первая обработка |
||||
for i in _fixture: |
||||
if i['model'] in loader.keys(): |
||||
i['model'] = loader[i['model']] |
||||
|
||||
if i['model'] == 'courses.coursetheme': |
||||
# Проверяем существование реестра счетчиков по курсу |
||||
if i['fields']['course'] not in _theme_counts.keys(): |
||||
_theme_counts[i['fields']['course']] = 0 |
||||
|
||||
if int(i['pk']) > _theme_count: |
||||
# Ловим последний ID темы |
||||
_theme_count = int(i['pk']) |
||||
|
||||
if i['fields']['type'] == 'A': |
||||
i['fields']['price_type'] = 'E' |
||||
i['fields']['type'] = 'E' |
||||
# Считаем количество расширеных тем |
||||
else: |
||||
i['fields']['price_type'] = i['fields']['type'] |
||||
|
||||
# Ловим последнюю сортировку базовых тем курса |
||||
if i['fields']['type'] == 'B' and int(i['fields']['sort']) > _theme_counts[i['fields']['course']]: |
||||
_theme_counts[i['fields']['course']] = int(i['fields']['sort']) |
||||
|
||||
if i['fields']['type'] == 'M': |
||||
# Ловим предэкзаменационные материалы |
||||
i['fields']['price_type'] = 'B' |
||||
M_material = i |
||||
M_material['fields']['sort'] = False |
||||
|
||||
if i['model'] == 'courses.homework': |
||||
i['fields']['sort'] = '1' |
||||
|
||||
if i['model'] == 'courses.course': |
||||
i['fields']['public'] = True |
||||
|
||||
if i['model'] == 'courses.exam': |
||||
i['fields']['sort'] = '1' |
||||
|
||||
if 'finance' in i['model']: |
||||
_finance.append(i) |
||||
elif 'courses' in i['model']: |
||||
_courses.append(i) |
||||
|
||||
_theme_counts[M_material['fields']['course']] += 1 |
||||
for i in _fixture: |
||||
if i['model'] == 'courses.exam': |
||||
# Создаю для каждого экзамена экзаменационную тему |
||||
if not M_material['fields']['sort'] and M_material['fields']['course'] == i['fields']['course']: |
||||
M_material['fields']['sort'] = int(_theme_counts[M_material['fields']['course']]) |
||||
_theme_counts[M_material['fields']['course']] += 1 |
||||
_courses.append(M_material) |
||||
_theme_count += 1 # Пересчет количества экзаменов |
||||
_courses.append({"model": "courses.coursetheme", |
||||
"pk": int(_theme_count), # Расчитать ID темы - последняя |
||||
"fields": {"type": "Ex", |
||||
"price_type": "B", |
||||
"icon": "", |
||||
"course": i['fields']['course'], |
||||
"sort": int(_theme_counts[i['fields']['course']]), # Расчитать сортировку |
||||
"title": "Экзаменационная тема", |
||||
"description": ""} |
||||
}) |
||||
i['fields']['theme'] = int(_theme_count) |
||||
|
||||
|
||||
json.dump(_courses, open('fixtures/courses.json', 'w')) |
||||
json.dump(_finance, open('fixtures/finance.json', 'w')) |
||||
|
||||
_fixture = json.load(open('fixtures/management.json')) |
||||
for i in _fixture: |
||||
if i['model'] == 'management.comment': |
||||
i['fields']['saw'] = [] |
||||
tmp = {} |
||||
for key, value in i['fields'].items(): |
||||
# Убрать не нужны поля |
||||
if key != 'public': |
||||
tmp[key] = value |
||||
i['fields'] = tmp |
||||
|
||||
json.dump(_fixture, open('fixtures/management.json', 'w')) |
||||
print 'Закончил МЕРДЖ' |
||||
@ -1,228 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
import django |
||||
import sys |
||||
import simplejson as json |
||||
|
||||
sys.path.append("/var/www/projects/lms/") |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from __migrate.post_fixtures import show_progress |
||||
from access.models import User |
||||
from courses.models import Exam, Homework, Lesson, Achievements, Course, CourseTheme |
||||
from journals.models import TeacherJ, AchievementJ, LessonJ, HomeworkJ, ExamJ, CourseThemeJ, HomeworkTry, check_journal |
||||
from storage.models import Storage |
||||
from management.models import Comment |
||||
|
||||
_fixture = json.load(open('fixtures/courses.json')) |
||||
|
||||
teachers = [] |
||||
achss = [] |
||||
lessonss = [] |
||||
homeworks = [] |
||||
exams = [] |
||||
|
||||
|
||||
def new_index(model, key, obj): |
||||
if str(key) in pk_map[model]: |
||||
return obj.objects.get(id=pk_map[model][str(key)]) |
||||
return None |
||||
|
||||
|
||||
# Пример записи маршрута |
||||
pk_map = json.load(open('pk_maps.json')) |
||||
if 'journals.teacherj' not in pk_map.keys(): |
||||
pk_map['journals.teacherj'] = {} |
||||
|
||||
if 'journals.achievementj' not in pk_map.keys(): |
||||
pk_map['journals.achievementj'] = {} |
||||
|
||||
if 'journals.lessonj' not in pk_map.keys(): |
||||
pk_map['journals.lessonj'] = {} |
||||
|
||||
if 'journals.homeworkj' not in pk_map.keys(): |
||||
pk_map['journals.homeworkj'] = {} |
||||
|
||||
if 'journals.examj' not in pk_map.keys(): |
||||
pk_map['journals.examj'] = {} |
||||
|
||||
for i in _fixture: |
||||
if i['model'] == 'courses.teacherj': |
||||
teachers.append(i) |
||||
elif i['model'] == 'courses.achievementj': |
||||
achss.append(i) |
||||
elif i['model'] == 'courses.lessonj': |
||||
lessonss.append(i) |
||||
elif i['model'] == 'courses.homeworkj': |
||||
homeworks.append(i) |
||||
elif i['model'] == 'courses.examj': |
||||
exams.append(i) |
||||
|
||||
|
||||
def achnivs(): |
||||
print u'\nAchievementJ' |
||||
_now = 0 |
||||
big_len = len(achss) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in achss: |
||||
s = AchievementJ.objects.create( |
||||
group=i['fields']['group'], |
||||
title=i['fields']['title'], |
||||
text=i['fields']['text'], |
||||
student=new_index('access.user', i['fields']['student'], User), |
||||
achievement=new_index('courses.achievements', i['fields']['achievement'], Achievements), |
||||
got=i['fields']['got'], |
||||
date=i['fields']['date'] |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['journals.achievementj'][str(i['pk'])] = str(s.id) |
||||
|
||||
|
||||
def tej(): |
||||
print u'\nПереформирование журналов TeacherJ' |
||||
for i in teachers: |
||||
tj, c = TeacherJ.objects.get_or_create(student=new_index('access.user', i['fields']['student'], User), |
||||
course=new_index('courses.course', i['fields']['course'], Course)) |
||||
# print i['fields'] |
||||
if tj.start_date != i['fields']['start_date']: |
||||
tj.start_date = i['fields']['start_date'] |
||||
if tj.teacher != new_index('access.user', i['fields']['teacher'], User): |
||||
tj.teacher = new_index('access.user', i['fields']['teacher'], User) |
||||
# check_journal(tj, tj.student, tj.course) |
||||
tj.save() |
||||
|
||||
check_journal(tj) |
||||
pk_map['journals.teacherj'][str(i['pk'])] = str(tj.id) |
||||
|
||||
print u'\nCreate CourseThemeJ' |
||||
for journal in TeacherJ.objects.all(): |
||||
for theme in CourseTheme.objects.filter(course=journal.course): |
||||
c, c2 = CourseThemeJ.objects.get_or_create(material=theme, student=journal.student) |
||||
if c.parent != journal: |
||||
c.parent = journal |
||||
c.save() |
||||
|
||||
|
||||
def get_point(point, t, f): |
||||
if point: |
||||
return t |
||||
else: |
||||
return f |
||||
|
||||
|
||||
def lj(): |
||||
print u'\nLessonJ' |
||||
_now = 0 |
||||
big_len = len(lessonss) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in lessonss: |
||||
# print i |
||||
c, c2 = LessonJ.objects.get_or_create( |
||||
student=new_index('access.user', i['fields']['student'], User), |
||||
material=new_index('courses.lesson', i['fields']['lesson'], Lesson), |
||||
# parent=CourseThemeJ.objects.get(student=new_index('access.user', i['fields']['student'], User), |
||||
# material=new_index('courses.lesson', i['fields']['lesson'], Lesson).theme) |
||||
) |
||||
c.success = bool(i['fields']['status'] == 'F') |
||||
c.date = get_point(i['fields']['status'] != 'N', i['fields']['date'], None) |
||||
c.f_date = get_point(i['fields']['status'] == 'F', i['fields']['f_date'], None) |
||||
c.save() |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['journals.lessonj'][str(i['pk'])] = str(c.id) |
||||
|
||||
|
||||
def create_try(parent, date): |
||||
return HomeworkTry.objects.create( |
||||
parent=parent, |
||||
material=parent.material, |
||||
student=parent.student, |
||||
teacher=parent.teacher, |
||||
date=date |
||||
) |
||||
|
||||
|
||||
def hj(): |
||||
print u'\nHomeworkJ' |
||||
_now = 0 |
||||
big_len = len(homeworks) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in homeworks: |
||||
c, c2 = HomeworkJ.objects.get_or_create( |
||||
student=new_index('access.user', i['fields']['student'], User), |
||||
material=new_index('courses.homework', i['fields']['homework'], Homework) |
||||
# parent=CourseThemeJ.objects.get(student=new_index('access.user', i['fields']['student'], User), |
||||
# material=new_index('courses.homework', i['fields']['homework'], |
||||
# Homework).theme) |
||||
) |
||||
c.date = i['fields']['date'] |
||||
c.f_date = i['fields']['f_date'] |
||||
c.teacher = new_index('access.user', i['fields']['teacher'], User) |
||||
c.success = False |
||||
c.save() |
||||
comments = [new_index('management.comment', comment, Comment) for comment in i['fields']['comments']] |
||||
_try = None |
||||
for comment in comments: |
||||
must_del = False |
||||
if not _try: |
||||
_try = create_try(c, comment.date) |
||||
|
||||
if '<span class="label label-success">Задача принята! </span><br>' in comment.text.encode('utf8'): |
||||
_try.f_date = comment.date |
||||
_try.success = True |
||||
must_del = True |
||||
|
||||
if '<span class="label label-danger">Отправлено на доработку!</span><br>' in comment.text.encode('utf8'): |
||||
_try.f_date = comment.date |
||||
must_del = True |
||||
|
||||
_try.comments.add(comment) |
||||
_try.save() |
||||
|
||||
if must_del: |
||||
_try = None |
||||
must_del = False |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['journals.homeworkj'][str(i['pk'])] = str(c.id) |
||||
|
||||
|
||||
def exj(): |
||||
print u'\nExamJ' |
||||
_now = 0 |
||||
big_len = len(exams) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in exams: |
||||
# print i |
||||
c, c2 = ExamJ.objects.get_or_create( |
||||
material=new_index('courses.exam', i['fields']['exam'], Exam), |
||||
student=new_index('access.user', i['fields']['student'], User) |
||||
# parent=CourseThemeJ.objects.get(student=new_index('access.user', i['fields']['student'], User), |
||||
# material___type='Ex', |
||||
# material__course=new_index('courses.exam', i['fields']['exam'], |
||||
# Exam).course) |
||||
) |
||||
c.teacher = new_index('access.user', i['fields']['teacher'], User) |
||||
c.date = i['fields']['date'] |
||||
c.f_date = i['fields']['f_date'] |
||||
c.success = False |
||||
c.diploma = new_index('storage.storage', i['fields']['diploma'], Storage) |
||||
c.save() |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['journals.examj'][str(i['pk'])] = str(c.id) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
# achnivs() |
||||
lj() |
||||
hj() |
||||
exj() |
||||
tej() |
||||
|
||||
json.dump(pk_map, open('pk_maps.json', 'w')) |
||||
@ -1,88 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
import django |
||||
import sys |
||||
import simplejson as json |
||||
|
||||
|
||||
|
||||
sys.path.append("/var/www/projects/lms/") |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from __migrate.post_fixtures import show_progress |
||||
from storage.models import Storage |
||||
from access.models import User |
||||
from management.models import News, Comment, Feedback |
||||
|
||||
_fixture = json.load(open('fixtures/management.json')) |
||||
user_pk = 1 |
||||
findex = [] |
||||
storage = [] |
||||
crimg = [] |
||||
|
||||
|
||||
def new_index(model, key, obj): |
||||
if str(key) in pk_map[model]: |
||||
return obj.objects.get(id=pk_map[model][str(key)]) |
||||
return None |
||||
|
||||
|
||||
# Пример записи маршрута |
||||
pk_map = json.load(open('pk_maps.json')) |
||||
if 'management.news' not in pk_map.keys(): |
||||
pk_map['management.news'] = {} |
||||
|
||||
if 'management.comment' not in pk_map.keys(): |
||||
pk_map['management.comment'] = {} |
||||
|
||||
if 'management.feedback' not in pk_map.keys(): |
||||
pk_map['management.feedback'] = {} |
||||
|
||||
for i in _fixture: |
||||
if i['model'] == 'management.news': |
||||
findex.append(i) |
||||
elif i['model'] == 'management.comment': |
||||
storage.append(i) |
||||
elif i['model'] == 'management.feedback': |
||||
crimg.append(i) |
||||
|
||||
print u'\nComments' |
||||
_now = 0 |
||||
big_len = len(storage) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in storage: |
||||
s = Comment.objects.create( |
||||
closed=i['fields']['closed'], |
||||
parent_id=i['fields']['parent_id'], |
||||
owner=new_index('access.user', i['fields']['owner'], User), |
||||
text=i['fields']['text'], |
||||
date=i['fields']['date'], |
||||
send=i['fields']['send'] |
||||
) |
||||
for key in i['fields']['files']: |
||||
s.files.add(new_index('storage.storage', key, Storage)) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['management.comment'][str(i['pk'])] = str(s.id) |
||||
|
||||
print u'\nFeedBack' |
||||
_now = 0 |
||||
big_len = len(crimg) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in crimg: |
||||
c = Feedback.objects.create( |
||||
closed=i['fields']['closed'], |
||||
name=i['fields']['name'], |
||||
email=i['fields']['email'], |
||||
phone=i['fields']['phone'], |
||||
text=i['fields']['text'], |
||||
date=i['fields']['date'], |
||||
send=i['fields']['send'] |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['management.feedback'][str(i['pk'])] = str(c.id) |
||||
|
||||
json.dump(pk_map, open('pk_maps.json', 'w')) |
||||
@ -1,100 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
import django |
||||
import sys |
||||
import simplejson as json |
||||
|
||||
|
||||
|
||||
sys.path.append("/var/www/projects/lms/") |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from __migrate.post_fixtures import show_progress |
||||
from storage.models import FormatIndex, Storage, CroppedImage |
||||
|
||||
_fixture = json.load(open('fixtures/storage.json')) |
||||
user_pk = 1 |
||||
findex = [] |
||||
storage = [] |
||||
crimg = [] |
||||
|
||||
|
||||
def new_index(model, key, obj): |
||||
if str(key) in pk_map[model]: |
||||
return obj.objects.get(id=pk_map[model][str(key)]) |
||||
return None |
||||
|
||||
# Пример записи маршрута |
||||
pk_map = json.load(open('pk_maps.json')) |
||||
if 'storage.formatindex' not in pk_map.keys(): |
||||
pk_map['storage.formatindex'] = {} |
||||
|
||||
if 'storage.storage' not in pk_map.keys(): |
||||
pk_map['storage.storage'] = {} |
||||
|
||||
if 'storage.croppedimage' not in pk_map.keys(): |
||||
pk_map['storage.croppedimage'] = {} |
||||
|
||||
|
||||
for i in _fixture: |
||||
if i['model'] == 'storage.formatindex': |
||||
findex.append(i) |
||||
elif i['model'] == 'storage.storage': |
||||
storage.append(i) |
||||
elif i['model'] == 'storage.croppedimage': |
||||
crimg.append(i) |
||||
|
||||
print u'\nFormatIndex' |
||||
_now = 0 |
||||
big_len = len(findex) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in findex: |
||||
f = FormatIndex.objects.create( |
||||
f_type=i['fields']['f_type'], |
||||
name=i['fields']['name'], |
||||
description=i['fields']['description'], |
||||
icon=i['fields']['icon'], |
||||
icon_class=i['fields']['icon_class'], |
||||
) |
||||
pk_map['storage.formatindex'][str(i['pk'])] = str(f.id) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
|
||||
print u'\nStorage' |
||||
_now = 0 |
||||
big_len = len(storage) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in storage: |
||||
s = Storage.objects.create( |
||||
loaded=i['fields']['loaded'], |
||||
name=i['fields']['name'], |
||||
key=i['fields']['key'], |
||||
original=i['fields']['original'], |
||||
f_format=new_index('storage.formatindex', i['fields']['f_format'], FormatIndex), |
||||
description=i['fields']['description'], |
||||
date=i['fields']['date'], |
||||
error=i['fields']['error'], |
||||
) |
||||
pk_map['storage.storage'][str(i['pk'])] = str(s.id) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
|
||||
print u'\nCroppedImg' |
||||
_now = 0 |
||||
big_len = len(crimg) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in crimg: |
||||
c = CroppedImage.objects.create( |
||||
original=new_index('storage.storage', i['fields']['original'], Storage), |
||||
big=i['fields']['big'], |
||||
middle=i['fields']['middle'], |
||||
small=i['fields']['small'], |
||||
cropped=i['fields']['cropped'], |
||||
) |
||||
pk_map['storage.croppedimage'][str(i['pk'])] = str(c.id) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
json.dump(pk_map, open('pk_maps.json', 'w')) |
||||
@ -1,116 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
import django |
||||
import sys |
||||
import simplejson as json |
||||
|
||||
|
||||
|
||||
sys.path.append("/var/www/projects/lms/") |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from __migrate.post_fixtures import show_progress |
||||
from access.models import User, Subscription, ActionJ |
||||
|
||||
_fixture = json.load(open('fixtures/access.json')) |
||||
user_pk = 1 |
||||
users = [] |
||||
subs = [] |
||||
acts = [] |
||||
actjs = [] |
||||
|
||||
|
||||
# Пример записи маршрута |
||||
pk_map = json.load(open('pk_maps.json')) |
||||
if 'access.user' not in pk_map: |
||||
pk_map['access.user'] = {} |
||||
|
||||
if 'access.subscription' not in pk_map: |
||||
pk_map['access.subscription'] = {} |
||||
|
||||
if 'access.actionj' not in pk_map: |
||||
pk_map['access.actionj'] = {} |
||||
|
||||
for i in _fixture: |
||||
if i['model'] == 'access.user': |
||||
users.append(i) |
||||
elif i['model'] == 'access.subscription': |
||||
subs.append(i) |
||||
elif i['model'] == 'access.actionj': |
||||
actjs.append(i) |
||||
|
||||
print u'\nUsers' |
||||
_now = 0 |
||||
big_len = len(users) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in users: |
||||
u = User.objects.create( |
||||
password=i['fields']['password'], |
||||
email=i['fields']['email'], |
||||
changed_email=i['fields']['changed_email'], |
||||
phone=i['fields']['phone'], |
||||
back_phone=i['fields']['back_phone'], |
||||
status=i['fields']['status'], |
||||
in_role=i['fields']['in_role'], |
||||
deactivate=i['fields']['deactivate'], |
||||
city=i['fields']['city'], |
||||
b_day=i['fields']['b_day'], |
||||
token=i['fields']['token'], |
||||
activate_time=i['fields']['activate_time'], |
||||
reg_status=i['fields']['reg_status'], |
||||
is_active=i['fields']['is_active'], |
||||
is_admin=i['fields']['is_admin'], |
||||
is_staff=i['fields']['is_staff'], |
||||
avatar=i['fields']['avatar'], |
||||
fname=i['fields']['fname'], |
||||
name=i['fields']['name'], |
||||
oname=i['fields']['oname'], |
||||
skype='', |
||||
facebook='', |
||||
vk='', |
||||
linkedin='', |
||||
odnoklassniki='', |
||||
date_joined=i['fields']['date_joined'] |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['access.user'][str(i['pk'])] = str(u.id) |
||||
|
||||
print u'\nSubscriptions' |
||||
_now = 0 |
||||
big_len = len(subs) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in subs: |
||||
s = Subscription.objects.create( |
||||
owner=User.objects.get(id=pk_map['access.user'][str(i['fields']['owner'])]), |
||||
news=i['fields']['news'], |
||||
teacher=i['fields']['teacher'], |
||||
new_comments=i['fields']['new_comments'], |
||||
send_sms=i['fields']['send_sms'], |
||||
courses=i['fields']['courses'], |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['access.subscription'][str(i['pk'])] = str(s.id) |
||||
|
||||
print u'\nActions' |
||||
_now = 0 |
||||
big_len = len(actjs) |
||||
show_progress(big_len, _now) |
||||
|
||||
for i in actjs: |
||||
a = ActionJ.objects.create( |
||||
student=User.objects.get(id=pk_map['access.user'][str(i['fields']['student'])]), |
||||
a_type=i['fields']['a_type'], |
||||
place=i['fields']['place'], |
||||
date=i['fields']['date'], |
||||
text=i['fields']['text'], |
||||
) |
||||
_now += 1 |
||||
show_progress(big_len, _now) |
||||
pk_map['access.actionj'][str(i['pk'])] = str(a.id) |
||||
|
||||
|
||||
json.dump(pk_map, open('pk_maps.json', 'w')) |
||||
@ -1 +0,0 @@ |
||||
{} |
||||
@ -1,121 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
|
||||
import django |
||||
import sys |
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
from courses.models import CourseTheme, Course |
||||
from journals.models import HomeworkTry as HT, TeacherJ, CourseThemeJ, LessonJ, HomeworkJ, ExamJ |
||||
|
||||
|
||||
def split_ht(): |
||||
# Разделить комментарии по попыткам |
||||
print '==== Разбиваю попытки' |
||||
big_length = HT.objects.all().count() |
||||
_now = 0 |
||||
show_progress(big_length, _now) |
||||
for i in HT.objects.all(): |
||||
# Получить все попытки |
||||
# Пройтись по комментариям по порядку |
||||
# Если в тексте преподавателя есть <span class="label label-danger">Отправлено на доработку!</span> |
||||
# <span class="label label-success">Задача принята! </span><br> - одобрено |
||||
do = True |
||||
for n in i.comments.all().order_by('id'): |
||||
if do: |
||||
_tmp = HT.objects.create(parent=i.parent, material=i.material, student=i.student, teacher=i.teacher, |
||||
date=i.date, f_date=i.f_date) |
||||
do = False |
||||
if '<span class="label label-success">Задача принята! </span><br>' in n.text.encode('utf8'): |
||||
#print 'Нашел одобрение' |
||||
_tmp.success = True |
||||
_tmp.f_date = n.date |
||||
_tmp.save() |
||||
do = True |
||||
elif '<span class="label label-danger">Отправлено на доработку!</span><br>' in n.text.encode('utf8'): |
||||
#print 'Нашел отказ' |
||||
_tmp.success = False |
||||
_tmp.f_date = n.date |
||||
_tmp.save() |
||||
do = True |
||||
#print 'Добавил комментарий в попытку {0}'.format(_tmp.id) |
||||
_tmp.comments.add(n) |
||||
i.delete() |
||||
_now += 1 |
||||
show_progress(big_length, _now) |
||||
print '' |
||||
|
||||
|
||||
def CTJ_split(): |
||||
print '==== Создаю журналы тем' |
||||
# TODO: Не нужно создавать тему там, где нет журналов? |
||||
# Присвоить журналы тем домашним работам/ урокам/ экзаменам |
||||
big_length = TeacherJ.objects.all().count() |
||||
_now = 0 |
||||
show_progress(big_length, _now) |
||||
for journal in TeacherJ.objects.all(): |
||||
for theme in CourseTheme.objects.filter(course=journal.course): |
||||
CTJ = CourseThemeJ.objects.create(parent=journal, material=theme, student=journal.student) |
||||
if CTJ.material.type == 'B': |
||||
for lesson in LessonJ.objects.filter(material__theme=theme, student=journal.student): |
||||
if lesson.parent != CTJ: |
||||
lesson.parent = CTJ |
||||
lesson.save() |
||||
for homework in HomeworkJ.objects.filter(material__theme=theme, student=journal.student): |
||||
if homework.parent != CTJ: |
||||
homework.parent = CTJ |
||||
homework.save() |
||||
|
||||
elif CTJ.material.type == 'Ex': |
||||
try: |
||||
ex = ExamJ.objects.get(material__course=journal.course, student=journal.student) |
||||
except ExamJ.DoesNotExist: |
||||
pass |
||||
else: |
||||
ex.parent = CTJ |
||||
ex.save() |
||||
_now += 1 |
||||
show_progress(big_length, _now, post=journal.id) |
||||
print '' |
||||
|
||||
|
||||
def empty_journals(): |
||||
print '==== Создаю пустые журналы' |
||||
big_length = Course.objects.all().count() |
||||
_now = 0 |
||||
show_progress(big_length, _now) |
||||
for course in Course.objects.all(): |
||||
try: |
||||
TeacherJ.objects.create(course=course, student=None) |
||||
except: |
||||
continue |
||||
else: |
||||
_now += 1 |
||||
show_progress(big_length, _now) |
||||
print '' |
||||
|
||||
|
||||
def show_progress(full, now, post=''): |
||||
# + Процесс отображения процентов выполнения |
||||
# Отображение процента выполнения |
||||
if full != 0: |
||||
progress = float(now / (full * 0.01)) |
||||
else: |
||||
progress = '100' |
||||
sys.stdout.write(u'\rВыполнено: {0:6.4}% {1}'.format(progress, post)) |
||||
sys.stdout.flush() |
||||
|
||||
|
||||
def rights(): |
||||
os.system('chown www-data:www-data -R *') |
||||
|
||||
|
||||
def main(): |
||||
rights() |
||||
#CTJ_split() |
||||
empty_journals() |
||||
#split_ht() |
||||
|
||||
if __name__ == '__main__': |
||||
main() |
||||
@ -1,11 +0,0 @@ |
||||
# coding=utf-8 |
||||
import os |
||||
import django |
||||
print '==== Загружаю DJANGO' |
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings") |
||||
django.setup() |
||||
|
||||
from courses.models import Lesson, CourseMap |
||||
|
||||
l = Lesson.objects.all().first() |
||||
CourseMap.objects.create(lesson=l, sort=0) |
||||
Binary file not shown.
@ -1,83 +0,0 @@ |
||||
function parseGetParams() { |
||||
var $_GET = {}; |
||||
var __GET = window.location.search.substring(1).split("&"); |
||||
for(var i=0; i<__GET.length; i++) { |
||||
var getVar = __GET[i].split("="); |
||||
$_GET[getVar[0]] = typeof(getVar[1])=="undefined" ? "" : getVar[1]; |
||||
} |
||||
return $_GET; |
||||
} |
||||
|
||||
function in_array(value, array) { |
||||
for(var i=0; i<array.length; i++){ |
||||
if(value == array[i]) return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
function check_email(data){ |
||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
||||
return re.test(data); |
||||
} |
||||
|
||||
function not_empty(data){ |
||||
var result = false; |
||||
if (data.length > 0){ |
||||
result = true |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
function check_form(email, phone, data, error) { |
||||
$(error).fadeOut('fast'); |
||||
if(check_email(email) && not_empty(phone)){ |
||||
create_bill($(data), $(error)) |
||||
} else { |
||||
$('[name=error_place]').html('Форма заполнена не верно').fadeIn(); |
||||
} |
||||
} |
||||
|
||||
function create_bill(form, error){ |
||||
var get = parseGetParams(); |
||||
if ('admitad_uid' in get){ |
||||
var forms = $('forms'); |
||||
var ad_ui = get['admitad_uid']; |
||||
var input = '<input readonly name="uid" style="display: none;" value="'+ad_ui+'">'; |
||||
for (var i =0;i<forms.length;i++){ |
||||
$(forms[i]).append(input) |
||||
} |
||||
} |
||||
$(error).fadeOut(); |
||||
$.ajax({ |
||||
type: 'POST', |
||||
url: 'https://lms.ru/access/create_bill/', |
||||
data: $(form).serialize(), |
||||
success: function(data) { |
||||
if (data.code == '0'){ |
||||
$(error).html(data.response).fadeIn(); |
||||
} else { |
||||
if (data['data']['gift']){ |
||||
location.href=data['data']['pay_url'] |
||||
} else { |
||||
$(error).html('Счет успешно добавлен').fadeIn(); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function create_user(form, error){ |
||||
$(error).fadeOut(); |
||||
$.ajax({ |
||||
type: 'POST', |
||||
url: 'https://lms.ru/access/create_user/', |
||||
data: $(form).serialize(), |
||||
success: function(data) { |
||||
if (data.code == '0'){ |
||||
$(error).html(data.response).fadeIn(); |
||||
} else { |
||||
$(error).html('Пользователь успешно зарегистрирован').fadeIn(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
File diff suppressed because one or more lines are too long
@ -1,19 +0,0 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<title>Title</title> |
||||
<script type="text/javascript" src='jquery.min.js'></script> |
||||
<script type="text/javascript" src='form.js'></script> |
||||
</head> |
||||
<body> |
||||
<form onclick="return false;" name="bill_form"> |
||||
<p name="error_place" style="background: #ffc; display: none;"></p> |
||||
<input name="email" placeholder="Почта" type="text"> |
||||
<input name="phone" placeholder="Телефон" type="text"> |
||||
<input name="token" value="iLeeoRvQM7gpAyAglTi3" readonly style="display: none;"> |
||||
<input name="service" value="k7vNYr2bg7q0oAznexWfsmd9ik91OtuVjizKJQuuaRiJ3aOr5I" readonly style="display: none;"> |
||||
<button onclick="check_form($('[name=email]').val(), $('[name=phone]').val(), $($(this).parent()), $('[name=error_place]'))">Отправить</button> |
||||
</form> |
||||
</body> |
||||
</html> |
||||
@ -1,13 +0,0 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<title>Подключение оплаты со стороннего ресурса</title> |
||||
</head> |
||||
<body> |
||||
<form> |
||||
<input name="email"> |
||||
<button onclick></button> |
||||
</form> |
||||
</body> |
||||
</html> |
||||
@ -1,15 +0,0 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<title>Title</title> |
||||
<script language="javascript" src="../static/js/prototype.js"></script> |
||||
<script language="javascript" src="../static/js/NTP.js"></script> |
||||
<script language="javascript"> |
||||
NTP.sync(); |
||||
</script> |
||||
</head> |
||||
<body> |
||||
|
||||
</body> |
||||
</html> |
||||
File diff suppressed because it is too large
Load Diff
@ -1,10 +0,0 @@ |
||||
# coding=utf-8 |
||||
import re |
||||
|
||||
with open('1.txt', 'r') as myfile: |
||||
data=myfile.read() |
||||
|
||||
r = re.compile(r"^[-a-z0-9!#$%&'*+/=?^_`{|}~]+(\.[-a-z0-9!#$%&'*+/=?^_`{|}~]+)*@([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?\.)*(aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|[a-z][a-z])$") |
||||
|
||||
n = re.compile(r'\w+$') |
||||
print r.findall(data) |
||||
Loading…
Reference in new issue