Ejemplo n.º 1
0
 def clear_lesson(self, lesson, write_response=True):
     from model import Student, StudentActivity
     from google.appengine.ext import db
     db.delete(StudentActivity.fetch_all("lesson =", lesson))
     db.delete(Student.fetch_all("lesson =", lesson))
     self.log_out_all_students(lesson, False);
     if write_response:
         self.write_response_plain_text("OK")
Ejemplo n.º 2
0
	def _send_tab_delimited_report(self, lesson_code, utc_offset):
		import StringIO
		from model import Student, StudentActivity, Lesson
		import helpers
		encoding = "UTF-8"

		lesson = Lesson.get_by_key_name(lesson_code)
		assert lesson is not None

		if lesson is None or lesson.teacher_key != self.teacher_key:
			self.write_response_plain_text("ERROR:  Lesson code appears to be incorrect.")
		else:

			students = Student.fetch_all("lesson =", lesson)
			task_titles = tuple(task_info[0] for task_info in lesson.tasks)
			student_key_to_nickname = dict((s.key().name(), s.nickname) for s in students)
			activities = StudentActivity.fetch_all("lesson =", lesson)

			report_buffer = StringIO.StringIO()
			excel_writer = UnicodeWriter(report_buffer, "excel-tab", "utf8")

			headers = (
#					"Lesson_Code",
					"Timestamp",
					"Student",
					"Task_Number",
					"Task_Name",
					"Activity_Type",
					"Query",
					"Link_URL",
					"Link_Title",
					"Is_Helpful",
					"Answer_Text",
					"Answer_Explanation"
			)
			excel_writer.writerow(headers)

			for activity in activities:
				student_key = activity.student_key.name()
				student_nickname = student_key_to_nickname[student_key]
				timestamp = (activity.timestamp - utc_offset).strftime("%m/%d/%Y %H:%M:%S")
				task_idx = activity.task_idx
				task_title = task_titles[task_idx]
				task_num = task_idx + 1
				line_parts = (
#						lesson_code,
						timestamp,
						student_nickname,
						task_num,
						task_title,
						activity.activity_type,
						activity.search,
						activity.link,
						activity.link_title,
						activity.is_helpful,
						activity.answer_text,
						activity.answer_explanation
				)
#				line_parts = tuple(unicode(p).encode("utf8") for p in line_parts)
				excel_writer.writerow(line_parts)
			report_text = report_buffer.getvalue()
			report_buffer.close()

			content_type = "text/tab-separated-values"
			filename = "search_party_lesson_%s_activity_as_of_%s.txt"%(lesson_code, helpers.timestamp())
			self.write_response_as_file(encoded_content=report_text, content_type=content_type, filename=filename, encoding=encoding)