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.
 
 
 
 
 
 

111 lines
4.2 KiB

# 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 'Закончил МЕРДЖ'