-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.py
75 lines (59 loc) · 2.11 KB
/
Utilities.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
__author__ = '[email protected] (Mike George)'
from contextlib import contextmanager
from Objects.Enrollment import Enrollment
import string, sys
def clean_name(name):
clean = name
clean = string.capitalize(clean)
return clean
def clean_title(title):
clean = title
clean = string.replace(clean, "'", "''")
return clean
def course_version(course_full_name):
course_version = course_full_name
course_version = course_version.split("-")
course_version = course_version[1].split("_")
return course_version[0]
def deconstruct_title(title, type):
enrollment = Enrollment()
if type == "s":
student_lastname = title.split(',')[0]
student_firstname = title.split(',')[1].split('-')[0].strip()
enrollment.student.lastname = student_lastname
enrollment.student.firstname = student_firstname
else:
teacher_lastname = title.split('-')[1].strip().split(" ")[1]
teacher_firstname = title.split('-')[1].strip().split(" ")[0]
course_version = title.split('-')[2].strip()
course_name = title.split('-')[0].strip()
course_id = title.split('-')[3].strip()
enrollment.teacher.lastname = teacher_lastname
enrollment.teacher.firstname = teacher_firstname
enrollment.course.version = course_version
enrollment.course.name = course_name
enrollment.course.id = course_id
return enrollment
def gen_title(enrollment, type):
title = ""
if type == "s":
title += clean_name(enrollment.student.lastname)
title += ", "
title += clean_name(enrollment.student.firstname)
title += " - Assignments"
else:
title += enrollment.course.name
title += " - "
title += clean_name(enrollment.teacher.firstname)
title += " "
title += clean_name(enrollment.teacher.lastname)
title += " - "
title += enrollment.course.version
title += " - "
title += enrollment.course.id
return title
def remove_from_list(l_remove, l_from):
for v in l_remove:
l_from.remove(v)
return l_from