Ejemplo n.º 1
0
    def load_from_db(self, filename, id):
        result = db_select(
            filename, """SELECT ID, START, END, COURSE, SEMESTER, STATE
										FROM SURVEYS
										WHERE ID = """ + str(id))[0]
        if not result:
            return None

        self._id = result[0]
        self._start = result[1]
        self._end = result[2]
        self._course = find_course(result[3], result[4])
        self._course.survey = self
        self._questions = []
        qids = [
            x[0] for x in db_select(
                filename,
                """SELECT QUESTIONID FROM INCLUDE WHERE SURVEYID = """ +
                str(id) + " ORDER BY POSITION")
        ]
        for qid in qids:
            newQuestion = Question()
            newQuestion.load_from_db(filename, qid)
            self._questions.append(newQuestion)

        return self
Ejemplo n.º 2
0
    def test_fail_enrollment(self):
        user = login_user('z100', 'student228', 'localhost')
        course = find_course('COMP15610', '17s2')  #Course does not exist
        user.enrol(course)

        self.assertEqual(course, None)
        self.assertEqual(user.is_enrolled_in(course), False)
Ejemplo n.º 3
0
def get_pending_guests():
	users = db_select(DATABASE_FILENAME, 'SELECT ZID, ROLE FROM PASSWORDS')
	guests = []
	for user in users:
		if user[1].startswith('pending'):
			guests.append([int(user[0]), find_course(user[1].split(':')[1], user[1].split(':')[2])])

	return guests
Ejemplo n.º 4
0
def login_user(zID, password, ip_addr):
	zID = zID.replace('z', '')
	try:
		int(zID)
	except:
		return None
	results = db_select(DATABASE_FILENAME, 'SELECT PASSWORD, ROLE FROM PASSWORDS WHERE ZID = ' + str(zID))
	if len(results) == 0:
		print('No user found with that zID')
		return None
	actual_password, role = results[0]

	if role == 'admin':
		user = Admin(zID, actual_password)
	elif role == 'staff':
		user = Staff(zID, actual_password)
		enrolled_courses = db_select(DATABASE_FILENAME, 'SELECT COURSE, SEMESTER FROM ENROLMENTS WHERE ZID = '+str(zID))
		for course, semester in enrolled_courses:
			user.enrol(find_course(course, semester))
	elif role == 'student':
		user = Student(zID, actual_password)
		enrolled_courses = db_select(DATABASE_FILENAME, 'SELECT COURSE, SEMESTER FROM ENROLMENTS WHERE ZID = '+str(zID))
		for course, semester in enrolled_courses:
			user.enrol(find_course(course, semester))
	elif role == 'guest':
		user = Guest(zID, actual_password)
		enrolled_courses = db_select(DATABASE_FILENAME, 'SELECT COURSE, SEMESTER FROM ENROLMENTS WHERE ZID = '+str(zID))
		for course, semester in enrolled_courses:
			user.enrol(find_course(course, semester))

	if user.login(zID, password):
		logged_in[ip_addr] = user
		print(zID, "logged in", "["+str(datetime.now())+"]",
			  {Admin: 'Admin', Student: 'Student', Staff: 'Staff', Guest: 'Guest'}[type(user)])
		return user
	return None
Ejemplo n.º 5
0
    def load_from_dict(self, data):
        self._course = find_course(data['course'], data['semester'])
        self._course.survey = self

        startData = data['start'].split('-')
        self._start = datetime.date(int(startData[0]), int(startData[1]),
                                    int(startData[2]))
        endData = data['end'].split('-')
        self._end = datetime.date(int(endData[0]), int(endData[1]),
                                  int(endData[2]))

        self._questions = []
        for question in json.loads(data['surveyData']):
            newQuestion = Question()
            newQuestion.load_from_dict(question)
            self._questions.append(newQuestion)
Ejemplo n.º 6
0
def register_guest():
	if request.method == 'GET':
		return render_template("register_guest.html", bad_username=False, bad_course=False, register_success=False)

	zID = int(request.form.get('username').replace('z',''))
	password = request.form.get('password')
	try:
		course = find_course(request.form.get('course').split(':')[0].upper(),
							 request.form.get('course').split(':')[1].lower())
	except IndexError:
		course = None

	existing_zIDs = [int(x[0]) for x in db_select(DATABASE_FILENAME, 'SELECT ZID FROM PASSWORDS')]
	bad_username = True if zID in existing_zIDs else False
	bad_course = True if course == None else False

	if bad_username or bad_course:
		return render_template("register_guest.html", bad_username=bad_username, bad_course=bad_course, register_success=False)

	guest_register(zID, password, course)
	return render_template("register_guest.html", bad_username=bad_username, bad_course=bad_course, register_success=True)
Ejemplo n.º 7
0
    def test_cancel_enrollment(self):
        user = login_user('z100', 'student228', 'localhost')
        course = find_course('COMP1531', '17s2')
        user.unenrol(course)

        self.assertEqual(user.is_enrolled_in(course), False)