915
915
return self.db.query(query).dictresult()
918
def get_enrolment(self, login, dry=False):
920
Get all offerings (in IVLE) the student is enrolled in.
921
Returns a list of dicts (all values strings), with the keys:
922
offeringid, subj_code, subj_name, subj_short_name, year, semester, url
925
SELECT offering.offeringid, subj_code, subj_name, subj_short_name,
926
semester.year, semester.semester, subject.url
927
FROM login, enrolment, offering, subject, semester
928
WHERE enrolment.offeringid=offering.offeringid
929
AND login.loginid=enrolment.loginid
930
AND offering.subject=subject.subjectid
931
AND semester.semesterid=offering.semesterid
933
AND login=%s;""" % _escape(login)
936
return self.db.query(query).dictresult()
938
918
def get_enrolment_groups(self, login, offeringid, dry=False):
940
920
Get all groups the user is member of in the given offering.
955
935
return self.db.query(query).dictresult()
957
def get_subjects_status(self, login, dry=False):
959
Get all subjects in IVLE, split into lists of enrolled and unenrolled
961
Returns a tuple of lists (enrolled, unenrolled) of dicts
962
(all values strings) with the keys:
963
subj_code, subj_name, subj_short_name, url
965
enrolments = self.get_enrolment(login)
966
all_subjects = self.get_subjects()
968
enrolled_set = set(x['subj_code'] for x in enrolments)
970
enrolled_subjects = [x for x in all_subjects
971
if x['subj_code'] in enrolled_set]
972
unenrolled_subjects = [x for x in all_subjects
973
if x['subj_code'] not in enrolled_set]
974
enrolled_subjects.sort(key=lambda x: x['subj_code'])
975
unenrolled_subjects.sort(key=lambda x: x['subj_code'])
976
return (enrolled_subjects, unenrolled_subjects)
980
939
def get_groups_by_user(self, login, offeringid=None, dry=False):