Beispiel #1
0
	def course_search(self, courseCode):
		"""
		Returns all known sections of the specified course. Each section in the
		returned dictionary is unique.
		"""
		namespace = 'course-search'
		cacheTime = 60 # Cache course search results for one minute
		cached = memcache.get(courseCode, namespace)
		if cached:
			return cached

		courses = Course.all()
		courses.filter('courseCode =', courseCode)
		courses = self._make_sections_unique(courses)

		courseDict = self._build_course_dict(courses)
		memcache.set(courseCode, courseDict, namespace=namespace, time=cacheTime)
		return courseDict
	def safely_delete(self, schedule):
		profile = profiles.get_user_profile_from_ds()

		# Simply comparing the two schedules themselves doesn't work
		# so we compare their keys
		if profile.currentSchedule.key() == schedule.key():
			logging.info('Deleted current schedule "' + schedule.name + '"')
			profile.currentSchedule = None
			profile.put()

		# Delete all courses in this schedule
		courses = Course.all().ancestor(schedule)
		for course in courses:
			course.delete()
		# Unshare this schedule from everyone
		records = ShareRecord.all().ancestor(schedule)
		for sharing in records:
			sharing.delete()
		schedule.delete()
	def update_courses(self, schedule, courseDict):
		# Get all courses in datastore
		# For each course submitted, overwrite a course from the datastore with it.
		# If there are not enough courses in the datastore, create new ones.
		# If there are leftover courses, delete them.
		query = Course.all()
		query.ancestor(schedule)
		fromDatastore = []
		coursesToPut = []
		
		for course in query:
			fromDatastore.append(course)
	
		for courseData in courseDict:
			# Courses should belong to their schedule's entity group
			course = self.safePop(fromDatastore) or Course(parent=schedule)
			course.owner = users.get_current_user()
			course.schedule = schedule

			course.update_from_coursedata(courseData)
			coursesToPut.append(course)

		# The courses left in fromDatastore should be deleted
		return coursesToPut, fromDatastore