Ejemplo n.º 1
0
	def setUp(self):
		faculty = Faculty(name='Faculty of Science', slug='science')
		faculty.save()
		department = Department(short_name='BIOL', faculty=faculty, long_name='Biology')
		department.save()
		self.course = Course(department=department, number=112, description="lol", credits=3)
		self.course.save()
		self.course_sem_1 = CourseSemester(term='Winter', year='2011', course=self.course)
		self.course_sem_1.save()
		self.course_sem_2 = CourseSemester(term='Summer', year='2011', course=self.course)
		self.course_sem_2.save()
Ejemplo n.º 2
0
	def test_same_semester(self):
		course = Course.objects.get(pk=1)
		course_sem_1 = CourseSemester(term='Winter', year='2011', course=course)
		course_sem_1.save()
		course_sem_2 = CourseSemester(term='Summer', year='2011', course=course)
		course_sem_2.save()
		course_sem_3 = CourseSemester(term='Winter', year='2011', course=course)
		course_sem_3.save()
		print "lol"
Ejemplo n.º 3
0
def create(request, department, number, page_type):
	course = get_object_or_404(Course, department=department, number=int(number))

	if page_type not in types:
		raise Http404
	else:
		obj = types[page_type]
		if request.method == 'POST':
			# Create the page
			num_sections = request.POST['num_sections']
			term = request.POST['term']
			year = request.POST['year']
			try:
				course_sem = CourseSemester.objects.get(term=term, year=year, course=course)
			except CourseSemester.DoesNotExist:
				course_sem = CourseSemester(term=term, year=year, course=course)
				course_sem.save()

			# The title and subject are generated by the PageType object, in kwargs
			kwargs = obj.get_kwargs(request.POST)
			new_page = Page(course_sem=course_sem, num_sections=num_sections, page_type=page_type, **kwargs)
			new_page.save()
			username = request.user.username if request.user.is_authenticated() else 'Anonymous'
			email = request.user.email if request.user.is_authenticated() else '*****@*****.**'
			new_page.save_sections(request.POST, username, email)
			data = {
				'course': course,
			}
			# Get the keyword arguments from the page type method
			if new_page:
				data['page'] = new_page
				return render(request, "pages/success.html", data)
			else:
				return render(request, "pages/error.html", data)
		else:
			data = {
				'course': course,
				'page_type': obj,
				'form_template': obj.get_form_template(),
				'help_template': obj.get_help_template(),
				'field_templates': obj.get_field_templates(),
				'terms': ['winter', 'summer', 'fall'], # fix this later
				'years': range(2011, 1999, -1),
				'num_sections': range(1, 11), # for people without javascript DON'T DELETE THIS UNLESS YOU HAVE ANOTHER SOLUTION FOR A FALLBACK
			}
			return render(request, "pages/create.html", data)
Ejemplo n.º 4
0
class CourseSemesterTest(TestCase):
	def setUp(self):
		faculty = Faculty(name='Faculty of Science', slug='science')
		faculty.save()
		department = Department(short_name='BIOL', faculty=faculty, long_name='Biology')
		department.save()
		self.course = Course(department=department, number=112, description="lol", credits=3)
		self.course.save()
		self.course_sem_1 = CourseSemester(term='Winter', year='2011', course=self.course)
		self.course_sem_1.save()
		self.course_sem_2 = CourseSemester(term='Summer', year='2011', course=self.course)
		self.course_sem_2.save()

	def test_same_semester(self):
		duplicate = CourseSemester(term='Winter', year='2011', course=self.course)
		self.assertRaises(IntegrityError, duplicate.save)

	def test_get_semester(self):
		course_sem_1 = CourseSemester.objects.get(term='Winter', year='2011', course=self.course)
		self.assertEqual(course_sem_1, self.course_sem_1)
		self.assertRaises(CourseSemester.DoesNotExist, CourseSemester.objects.get, term='Summer', year='1999', course=self.course)