Exemplo n.º 1
0
	def get(self):
		user = users.get_current_user()
		if(user):
			userQuery = User.query(User.userid == user.user_id())

			userEntity = None

			for thisUser in userQuery:
				userEntity = thisUser
				formCheck(self, user)
				missedLectureCheck(user)
				if userEntity.email is None:
					userEntity.email = user.email()
					userEntity.put()

			if userEntity is None:
				userEntity = User(
					userid=user.user_id(),
					score=0,
					streak=0,
					count=0,
					history=[],
					email = user.email())

				module1Query = Module.query(Module.code == 'GENG0013')
				for module in module1Query:
					for lecture in module.lectures:
						userEntity.lectures.append(lecture)

				module2Query = Module.query(Module.code == 'GENG0002')
				for module in module2Query:
					for lecture in module.lectures:
						userEntity.lectures.append(lecture)

				challengeQuery = Challenge.query().order(Challenge.challengeid)
				for challenge in challengeQuery:
					userEntity.challenges.append(challenge)

				userEntity.put()
				self.redirect('/info')

			completedChalls = []

			for challenge in userEntity.challenges:
				if challenge.complete:
					completedChalls.append(challenge)

			template_values = {
				'username' : userEntity.username,
				'logout' : users.create_logout_url(self.request.uri),
				'score' : userEntity.score,
				'count' : userEntity.count,
				'streak' : userEntity.streak,
				'completedChalls' : completedChalls
			}
			template = JINJA_ENVIRONMENT.get_template('/assets/home.html')
			self.response.write(template.render(template_values))

		else:
			self.redirect(users.create_login_url(self.request.uri))
Exemplo n.º 2
0
 def get(self, moduleID, title, institution, teachDate, instructors, description):
     account = get_account()
     if account:
         newCourse = dict()
         newCourse["CourseURL"] = urlparse.unquote(
             self.request.get('courseURL'))
         newCourse["Title"] = title
         newCourse["Institution"] = institution
         newCourse["TeachingDate"] = teachDate
         newCourse["Instructors"] = instructors
         newCourse["Description"] = description
         newCourse["DownloadPageLink"] = urlparse.unquote(
             self.request.get('materials'))
         newCourse["scoreRanking"] = 1
         moduleID = int(moduleID)
         match = Module.query(Module.category == moduleID).fetch()
         match = match[0]
         moduleCourses = match.courses
         newCourse['ID'] = len(moduleCourses)
         moduleCourses.append(newCourse)
         match.courses = moduleCourses
         match.courses = sorted(
             match.courses, key=lambda k: k['scoreRanking'], reverse=True)
         match.put()
         response = {'success': 'Course submitted successfully.'}
     else:
         response = {'error': 'You are not logged in. '}
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps(response))
Exemplo n.º 3
0
 def get(self):
     modules = [m.to_dict() for m in Module.query().fetch()]
     modules = sorted(
         modules,
         key=lambda module: module['name'].lower()
     )
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps(modules))
Exemplo n.º 4
0
 def get(self, modulename):
     match = Module.query(Module.name == modulename).fetch()
     if len(match) > 0:
         response = {'response': 'module exists'}
     else:
         y = youtube.Youtube()
         ocws = ocwsearch.OCWSearch()
         search_name = modulename + " tutorial"
         y_list, y_type = y.search(search_name)
         course_list = ocws.search(modulename)
         module = Module(
             name=modulename,
             youtube=y_list,
             yt_type=y_type, courses=course_list
         )
         module.put()
         response = {'response': 'successfully stored'}
         module.category = module.key.id()
         module.put()
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps(response))
Exemplo n.º 5
0
 def get(self, moduleID, courseID):
     courseID = int(courseID)
     account = get_account()
     if account:
         courseVoteList = dict(account.courses_voted)
         idPair = moduleID + "+" + str(courseID)
         if idPair not in courseVoteList.keys() or courseVoteList[idPair] == 'Y':
             case = "votedYes"
             if idPair not in courseVoteList.keys():
                 case = "notVoted"
             courseVoteList[idPair] = 'N'
             account.courses_voted = courseVoteList.items()
             account.put()
             moduleID = int(moduleID)
             match = Module.query(Module.category == moduleID).fetch()
             match = match[0]
             moduleCourses = match.courses
             newScore = 0
             for course in moduleCourses:
                 if course:
                     if course['ID'] == courseID:
                         if case == "notVoted":
                             course["scoreRanking"] = course[
                                 "scoreRanking"] - 1
                         else:
                             course["scoreRanking"] = course[
                                 "scoreRanking"] - 2
                         newScore = course["scoreRanking"]
             match.courses = moduleCourses
             match.courses = sorted(
                 match.courses, key=lambda k: k['scoreRanking'], reverse=True)
             match.put()
             response = {
                 'success': 'Vote submitted successfully.', 'newScore': newScore}
         else:
             response = {'error': 'No.'}
     else:
         response = {'error': 'You are not logged in. '}
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps(response))
Exemplo n.º 6
0
    def get(self):
        jac = job_api_calls.JobApiCalls()
        categories = jac.get_categories()
        y = youtube.Youtube()
        ocws = ocwsearch.OCWSearch()
        for c in categories:
            # retrieve items from API's
            c_id = int(c['id'])
            name = HTMLParser.HTMLParser().unescape(c['name'])
            search_name = name + " tutorial"
            y_list, y_type = y.search(search_name)
            course_list = ocws.search(name)

            # store/update as needed
            match = Module.query(Module.category == c_id).fetch()
            module = Module(
                name=name,
                youtube=y_list,
                yt_type=y_type, courses=course_list, category=c_id
            )

            if len(match) == 0:
                module.put()
            else:
                match = match[0]
                if (str(match.name) != name or
                        str(match.yt_type) != y_type or
                        match.youtube != y_list or
                        match.courses != course_list):
                    match.name = name
                    match.youtube = y_list
                    match.yt_type = y_type
                    match.courses = course_list
                    match.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(categories))