-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts.py
61 lines (50 loc) · 2.26 KB
/
scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from datacenter.models import Schoolkid, Mark, \
Lesson, Commendation, Chastisement
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from datacenter.commendations import commendations
import random
def get_schoolkid(full_name):
try:
schoolkid = Schoolkid.objects.get(full_name__contains=full_name)
except ObjectDoesNotExist:
print('There is no kid with name {}'.format(full_name))
return None
except MultipleObjectsReturned:
print('There are multiple kids with name {}'.format(full_name))
return None
return schoolkid
def fix_marks(full_name):
schoolkid = get_schoolkid(full_name)
bad_marks = Mark.objects.filter(
points__in=[2, 3], schoolkid=schoolkid)
for i, bad_mark in enumerate(bad_marks, 1):
bad_mark.points = 5
bad_mark.save()
print('{} оценок исправлено для ученика {}.'.format(i, full_name))
def remove_chastisements(full_name):
schoolkid = get_schoolkid(full_name)
Chastisement.objects.filter(schoolkid=schoolkid).delete()
print('Удалены все замечания для ученика {}.'.format(full_name))
def create_commendation(full_name, subject):
schoolkid = get_schoolkid(full_name)
if not schoolkid:
return None
latest_lesson = Lesson.objects.filter(
year_of_study=schoolkid.year_of_study,
group_letter=schoolkid.group_letter,
subject__title=subject).order_by('-date')[0]
if not Commendation.objects.filter(created=latest_lesson.date,
schoolkid=schoolkid,
subject=latest_lesson.subject,
teacher=latest_lesson.teacher):
Commendation.objects.create(
text=random.choice(commendations),
created=latest_lesson.date,
schoolkid=schoolkid,
subject=latest_lesson.subject,
teacher=latest_lesson.teacher)
return 'Похвала для {} - добавлена.'.format(full_name)
return 'Похоже, что похвала для последнего урока {} - уже есть.'.format(
subject)
if __name__ == "__main__":
pass