Ejemplo n.º 1
0
def enroll(student_id):
    search_param = request.args.get('q')
    student = get_object_or_404(Student, Student.student_id == student_id)

    if search_param:
        courses = Course.select().join(StudentEnrollment).where(
            StudentEnrollment.student != student
            & (
                Course.name.contains(search_param)
            )
        )
    else:
        courses = Course.select().where(
            Course.id.not_in(
                StudentEnrollment.select(
                StudentEnrollment.course
            ).join(Course).where(
                    StudentEnrollment.student == student
                )
            )
        )

    return render_template(
        'student/enroll.html',
        title="Enroll",
        student=student,
        courses=courses,
        search=search_param
    )
Ejemplo n.º 2
0
 def test_parse_course_object(self):
     test_data = {
         "id": "fc:fs:fs:emne:ntnu.no:EXPH0004:1",
         "type": "fc:fs:emne",
         "parent": "fc:org:ntnu.no",
         "membership": {
             "basic": "member",
             "fsroles": ["STUDENT"],
             "active": True,
             "notAfter": "2017-12-14T23:00:00Z",
             "subjectRelations": "undervisning",
             "displayName": "Student"
         },
         "displayName":
         "Examen philosophicum for naturvitenskap og teknologi"
     }
     course = Course(
         course_code="EXPH0004",
         course_name="Examen philosophicum for naturvitenskap og teknologi",
         credit=7.5,
         average_grade=0,
         pass_rate=100.0)
     course.save()
     course_info = parse_course_object(test_data)
     self.assertEqual(course_info["course_code"], "EXPH0004")
     self.assertEqual(
         course_info["course_name"],
         "Examen philosophicum for naturvitenskap og teknologi")
     self.assertEqual(course_info["semester"], "H2017")
Ejemplo n.º 3
0
 def save(self, **kw):
     u = Course(name=kw['name'],
                purpose=kw['purpose'],
                techerId=kw['techerId'],
                techerNumber=kw['techerNumber'],
                techerName=kw['techerName'])
     u.save()
Ejemplo n.º 4
0
def create_course_view(request):
    context = {}
    if request.method == 'POST':
        course_form = CourseCreateForm(request.POST,
                                       request.FILES,
                                       instance=request.user)

        course = Course()
        if course_form.is_valid():
            data = course_form.cleaned_data
            course.name = data['name']
            course.target_language = data['target_language']
            course.source_language = data['source_language']
            course.description = data['description']
            course.author = request.user
            if (data['image']):
                course.image = data['image']

            try:
                course.save()
                return redirect('course:detail', course.slug)
            except IntegrityError:
                print("error")
                context[
                    'course_error'] = "You have already created a course with this name. Choose a different one."
    else:
        course_form = CourseCreateForm(instance=request.user)

    context['course_form'] = course_form

    return render(request, 'course/create_course.html', context)
Ejemplo n.º 5
0
 def get_course_or_create(self):
     try:
         self.course = Course.objects.get(name_slug=self.dir)
     except:
         self.course = Course()
         self.course.name_slug = self.dir
         self.course.save()
Ejemplo n.º 6
0
    def setUp(self):
        '''Set up the user infrastructure.'''

        #User creation
        self.user = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #User2 creation
        self.user2 = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #User3 creation
        self.user3 = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #Course Instantiation
        self.course = Course(name="testing course", slug="testing-course")
        self.course.save()
Ejemplo n.º 7
0
    def handle(self, *args, **options):
        course_id = 1
        BASE_DIR = os.path.dirname(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
        workbook = openpyxl.load_workbook(BASE_DIR + '/course_data.xlsx')
        sheet = workbook.get_sheet_by_name("Sheet1")
        for row in sheet:
            if row[0].row == 1:
                continue

            course_time_spaces = self.__get_course_times(row[8].value)

            course = Course(course_id=course_id,
                            course_no=row[0].value,
                            semester=row[1].value,
                            university=row[2].value,
                            campus=row[3].value,
                            classification=row[4].value,
                            course_name=row[5].value,
                            professor=row[6].value,
                            credit=row[7].value)
            course.save()
            course_id += 1
            for course_time_space in course_time_spaces:
                course_time_space.course = course
                course_time_space.save()
Ejemplo n.º 8
0
    def setUpTestData(cls):
        course = Course(title='TDDD12', body='Big boody')
        course.save()

        Comment.objects.create(author='TDDX21',
                               body='Ave maria its ti me to shower',
                               course=course)
Ejemplo n.º 9
0
class NotificationTests(TestCase):
    '''Tests related to the actual Notification functionality.'''
    def setUp(self):
        '''Set up the user infrastructure.'''

        #User creation
        self.user = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #Course Instantiation
        self.course = Course(name="testing course", slug="testing-course")
        self.course.save()

        #Course Section Instantiation
        self.coursesection = CourseSection(name="Section 1",
                                           course=self.course)
        self.coursesection.save()

        #Category Instantiation
        self.category = Category(
            name="Category 1 for testing course",
            slug="cat-1-testing-course",
            section=self.coursesection,
        )
        self.category.save()

        #SubCategory Instantiation
        self.subcategory = SubCategory(
            name="SubCategory 1 for testing course",
            slug="subcategory-1-testing-course",
            category=self.category,
        )
        self.subcategory.save()

        self.question = Question(
            course=self.course,
            section=self.coursesection,
            category=self.category,
            subcategory=self.subcategory,
            question_text="Here is an example question.",
            option_A="Here is option A.",
            option_B="Here is option B.",
            answer_letter="A",
            answer_explanation="Here is an example explanation.",
        )
        self.question.save()

    def test_notification_creation(self):
        '''Test the creation of a notification.'''

        notification = Notification.objects.create(
            text="Notification test",
            recipient=self.user,
            link=self.question.get_absolute_url())

        notification.read = True
        notification.save()
Ejemplo n.º 10
0
def seed_enrollment_table():
    enrl = StudentEnrollment(course=(Course.get(Course.id == 1)),
                             student=(Student.get(Student.id == 1)))
    enrl.save()

    enrl = StudentEnrollment(course=(Course.get(Course.id == 2)),
                             student=(Student.get(Student.id == 2)))
    enrl.save()
Ejemplo n.º 11
0
class UserProfileTests(TestCase):
    '''Tests related to the actual UserProfile and Model manager functionality.'''
    def setUp(self):
        '''Set up the user infrastructure.'''

        #User creation
        self.user = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #User2 creation
        self.user2 = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #User3 creation
        self.user3 = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #Course Instantiation
        self.course = Course(name="testing course", slug="testing-course")
        self.course.save()

    def test_user_profile_creation(self):
        '''Test the user profile automatic creation.'''
        assert len(UserProfile.objects.all()) == 3

    def test_user_profile_querysets(self):
        '''Test the user profile querysets.'''

        self.user.profile.update(course=self.course)
        self.user2.profile.update(course=self.course)
        self.user3.profile.update(course=self.course)

        self.user.profile.update(state="California")
        self.user2.profile.update(state="California")
        self.user3.profile.update(state="Nevada")

        self.user.profile.update(major="Engineering")
        self.user2.profile.update(major="Engineering")

        assert len(
            UserProfile.objects.get_profiles_by_course(
                course=self.course)) == 3
        assert len(
            UserProfile.objects.get_profiles_by_major(
                course=self.course, major="Engineering")) == 2
        assert len(
            UserProfile.objects.get_profiles_by_state(course=self.course,
                                                      state="California")) == 2
    def setUpTestData(cls):
        course = Course(title='TDDD12', body='Big boody')
        course.save()

        assignment = Assignment(title='TDDD11',
                                description='Very big yes',
                                deadline=datetime.today(),
                                course=course)
        assignment.save()
Ejemplo n.º 13
0
    def setUp(self):
        '''Set up the test and category infrastructure.'''

        #Course Instantiation
        self.course = Course(name="testing course", slug="testing-course")
        self.course.save()

        #Course Section Instantiation
        self.coursesection = CourseSection(name="Section 1",
                                           course=self.course)
        self.coursesection.save()

        #Category Instantiation
        self.category = Category(
            name="Category 1 for testing course",
            slug="cat-1-testing-course",
            section=self.coursesection,
        )
        self.category.save()

        #SubCategory Instantiation
        self.subcategory = SubCategory(
            name="SubCategory 1 for testing course",
            slug="subcategory-1-testing-course",
            category=self.category,
        )
        self.subcategory.save()

        #User creation
        self.user = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        self.user2 = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )

        #Question creation
        self.question = Question(
            course=self.course,
            section=self.coursesection,
            category=self.category,
            subcategory=self.subcategory,
            question_text="Here is an example question.",
            option_A="Here is option A.",
            option_B="Here is option B.",
            answer_letter="A",
            answer_explanation="Here is an example explanation.",
            index=1,
        )
        self.question.save()
Ejemplo n.º 14
0
    def setUp(self):
        '''Set up the test and category infrastructure.'''

        #Course Instantiation
        self.course = Course(name="testing course", slug="testing-course")
        self.course.save()

        self.course2 = Course(name="testing course2", slug="testing-course2")
        self.course2.save()

        #Course Section Instantiation
        self.coursesection = CourseSection(name="Section 1",
                                           course=self.course)
        self.coursesection.save()

        self.coursesection2 = CourseSection(name="Section 2",
                                            course=self.course2)
        self.coursesection2.save()

        #Category Instantiation
        self.category = Category(
            name="Category 1 for testing course",
            slug="cat-1-testing-course",
            section=self.coursesection,
        )
        self.category.save()

        self.category2 = Category(
            name="Category 1 for testing course",
            slug="cat-1-testing-course2",
            section=self.coursesection2,
        )
        self.category2.save()

        #SubCategory Instantiation
        self.subcategory = SubCategory(
            name="SubCategory 1 for testing course",
            slug="subcategory-1-testing-course",
            category=self.category,
        )
        self.subcategory.save()

        self.subcategory2 = SubCategory(
            name="SubCategory 2 for testing course",
            slug="subcategory-2-testing-course",
            category=self.category2,
        )
        self.subcategory2.save()

        #User creation
        self.user = MyUser.objects.create_test_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )
Ejemplo n.º 15
0
 def post(self, request):
     '''删除课程'''
     course_code = request.POST.get('courseCode')
     if not Course.objects.filter(code=course_code).exists():
         return self.error(msg=f"course not exist", err=request.POST)
     else:
         try:
             course = Course(code=course_code, deleted=True)
             course.save()
         except Exception as e:
             return self.error(msg=str(e), err=e.args)
Ejemplo n.º 16
0
 def test_post_review_invalid_JSON_formatting_and_values_course_exists(self):
     invalid_test_data = {"course_code": "TDT4290",
                          "score": -2,
                          "workload": "abx",
                          "difficulty": 0}
     course = Course(course_code="TDT4290", course_name="Customer Driven Project", credit=15, average_grade=1,
                     pass_rate=100.0)
     course.save()
     c = APIClient()
     c.credentials(HTTP_AUTHORIZATION='valid_token')
     response = c.post("/review/", data=invalid_test_data, format="json")
     self.assertEqual(response.status_code, 400)
Ejemplo n.º 17
0
def save_courses(course_list):
    """
    Saves a list of course information dictionaries to the database.

    :param course_list: List of dict, List of course information for courses
    """
    for course_dict in course_info_list:
        Course.create(code=course_dict["code"],
                      name=course_dict["norwegian_name"].strip(),
                      credit=course_dict["credit"],
                      average_grade=course_dict["average"],
                      pass_rate=course_dict["pass_rate"]).save()
Ejemplo n.º 18
0
    def setUp(self):
        self.student_a = Student(
            first_name="Tiffany",
            last_name="Jeruto",
            date_of_birth=datetime.date(2000, 6, 24),
            registration_number="254016",
            Email="*****@*****.**",
            phone_number="0789647745",
            place_of_residence="Rongai",
            guardian_phone="0789567484",
            id_number=345378625,
            date_joined=datetime.date.today(),
        )

        self.student_b = Student(
            first_name="Clay",
            last_name="Jensen",
            date_of_birth=datetime.date(1999, 7, 25),
            registration_number="254017",
            Email="*****@*****.**",
            phone_number="0789765945",
            place_of_residence="Roysambu",
            guardian_phone="0780007684",
            id_number=3453734789,
            date_joined=datetime.date.today(),
        )

        self.python = Course(name="Python",
                             duration_in_months=10,
                             Course_number="1001",
                             description="Django and Flask frameworks")

        self.javascript = Course(
            name="Javascript",
            duration_in_months=10,
            Course_number="1002",
            description="Vanilla javascript and frameworks")

        self.hardware = Course(name="Hardware",
                               duration_in_months=10,
                               Course_number="1003",
                               description=" Product design using Fusion 360")

        self.teacher = Teacher(first_name="James",
                               last_name="Mwai",
                               place_of_residence="Kilimani",
                               phone_number="0723456786",
                               Email="*****@*****.**",
                               id_number=3128956743,
                               profession="Google Expert",
                               registration_number="2344",
                               date_joined=datetime.date.today())
Ejemplo n.º 19
0
def get_course():
    """
    生成一个课程

    :author: lishanZheng
    :date: 2020/01/03
    """
    clazz = get_clazz()
    teacher = get_teacher()
    course_data = get_course_data()
    course = Course(**course_data, clazz=clazz, teacher=teacher)
    course.save()
    return course
    def setUpTestData(cls):
        course = Course(title='TDDD12', body='Big boody')
        course.save()

        assignment = Assignment(title='TDDD11',
                                description='Very big yes',
                                deadline=datetime.today(),
                                course=course)
        assignment.save()

        handin = Handin.objects.create(holder='TDDX21',
                                       attached_files='ada/beda/ceda',
                                       assignment=assignment)
        handin.save()
Ejemplo n.º 21
0
 def test_retrieve_courses_from_token_valid_token(self):
     with patch("course.views.Course") as mock_course_db:
         mock_course_db.return_value.objects.return_value.filter.return_value = [
             Course.create("AAA9999", "Test course", 0, 0, 100.0)
         ]
         number_of_courses = len(retrieve_courses_from_token("valid_token"))
         self.assertEqual(number_of_courses, 28)
Ejemplo n.º 22
0
def createRelationBetweenCourseAndCourse(courseObject, couseName, graph):
    # 从数据库中查找特点node
    prerequisiteCourseNode = graph.nodes.match('Course',
                                               name=couseName).first()
    if prerequisiteCourseNode:
        # 将node转换为对象
        prerequisiteCourse = courseObject.wrap(prerequisiteCourseNode)
    else:
        try:
            from course.models import Course
            prerequisiteCourse = Course()
        except Exception as e:
            print(e)
        prerequisiteCourse.name = couseName
    # 构建关系
    courseObject.Prerequisite.add(prerequisiteCourse)
Ejemplo n.º 23
0
 def test_retrieve_courses_from_token_invalid_token(self):
     with patch("course.views.Course") as mock_course_db:
         mock_course_db.return_value.objects.return_value.filter.return_value = [
             Course.create("AAA9999", "Test course", 0, 0, 100.0)
         ]
     with self.assertRaises(TypeError):
         retrieve_courses_from_token("invalid_token")
Ejemplo n.º 24
0
    def change_expire(self, request):
        """切换购物车商品的勾选状态"""
        user_id = request.user.id
        expire_id = request.data.get("expire_id")
        course_id = request.data.get("course_id")
        try:
            # 判断课程是否存在
            course = Course.objects.get(is_show=True,
                                        is_deleted=False,
                                        id=course_id)
            # 判断课程的有效期选项是0还是其他的数值,如果是其他数值,还要判断是否存在于有效期选项表中
            if expire_id > 0:
                epxire_item = CourseExpire.objects.filter(is_show=True,
                                                          is_deleted=False,
                                                          id=expire_id)
                if not epxire_item:
                    raise Course.DoesNotExist()
        except Course.DoesNotExist:
            return Response({"message": "参数有误!当前商品课程不存在或者不能存在的有效期!"},
                            status=status.HTTP_400_BAD_REQUEST)

        redis_conn = get_redis_connection("cart")
        redis_conn.hset("cart_%s" % user_id, course_id, expire_id)

        # 在切换有效期选项以后,重新获取真实价格
        real_price = course.real_price(expire_id)

        return Response({"message": "切换课程有效期成功!", "real_price": real_price})
Ejemplo n.º 25
0
def upload_course(request):
	if request.method != "POST":
		return JsonResponse({'error_code': 1, 'msg': "not POST method, it's "+request.method})
	data = json.loads(request.body)
	team = Team.objects.filter(pk=data.get("tid")).first()
	# print(data.get("tid"))
	if team is None:
		return JsonResponse({'error_code': 2, 'msg': "team not exist", "id": Team.objects.all().last().id, "tid":data.get("tid")})
	name = data.get('name')
	teacher = data.get('teacher')
	description = data.get('description')
	link = data.get('link')
	# TODO: change time
	startTime = data.get('startTime')
	endTime = data.get('endTime')
	startTime = datetime.datetime.strptime(startTime, "%Y-%m-%d %H:%M:%S")
	endTime = datetime.datetime.strptime(endTime, "%Y-%m-%d %H:%M:%S")
	# courseTime = CourseTime(addTime=addTime, endTime=endTime)
	# courseTime.save()

	image = data.get('image')
	print("this is image:\n"+image)
	course = Course(tid=team, name=name, teacher=teacher, description=description, link=link, picture=image)
	course.save()
	courseTime = CourseTime(startTime=startTime, endTime=endTime, cid=course)
	courseTime.save()
	return JsonResponse({'error_code': 0})
Ejemplo n.º 26
0
    def change_expire(self, request):
        """改变redis中课程的有效期"""
        user_id = request.user.id
        expire_id = request.data.get("expire_id")
        course_id = request.data.get("course_id")

        try:
            course = Course.objects.get(is_show=True,
                                        is_delete=False,
                                        id=course_id)
            # 如果前端传递来的有效期选项  如果不是0  则修改课程对应的有效期
            if expire_id > 0:
                expire_iem = CourseExpire.objects.filter(is_show=True,
                                                         is_delete=False,
                                                         id=expire_id)
                if not expire_iem:
                    raise Course.DoesNotExist()
        except Course.DoesNotExist:
            return Response({"message": "课程信息不存在"},
                            status=status.HTTP_400_BAD_REQUEST)

        connection = get_redis_connection("cart")
        connection.hset("cart_%s" % user_id, course_id, expire_id)

        # 重新计算切换有效期后的价钱
        real_price = course.real_nuw_price(expire_id)

        return Response({"message": "切换有效期成功", "price": real_price})
Ejemplo n.º 27
0
	def setUp(self):
		self.student_a=Student(first_name=Joy,
			last_name=Wahome,
			date_of_birth=datetime.date(1998,8,25),
			registration_number=123,
			place_of_residence=Nairobi,
			phone_number=123456789,
			[email protected],
			guardian_phone=12345,
			id_number=1111111,
			date_joined=datetime.date.today(),)

		self.student_b=Student(first_name=Ivy,
			last_name=Wahome,
			date_of_birth=datetime.date(1996,5,24),
			registration_number=1234,
			place_of_residence=Nairobi,
			phone_number=123456789,
			[email protected],
			guardian_phone=123456,
			id_number=2222222,
			date_joined=datetime.date.today(),)

		self.python=Course(name=python,
			duration_in_months=10,
			course_number=1,
			description=Learn to code in Python,)

		self.javascript=Course(name=javascript,
			duration_in_months=10,
			course_number=2,
			description=Learn to code in JS,)

		self.hardware=Course(name=hardware,
			duration_in_months=10,
			course_number=3,
			description=Learn to build hardware,)

		self.teacher=Teacher(first_name=James,
			last_name=Mwai,
			date_of_birth=datetime.date(1998,8,25),
			registration_no=123,
			place_of_residence=Nairobi,
			phone_number=123456789,
			[email protected],
			id_number=1111111,
			profession=Consultant,)
Ejemplo n.º 28
0
def add_course(request):
    person = Person.objects.get(user=request.user)
    if person.role == 'TEACHER':
        if request.method == 'POST':
            try:
                title = request.POST['title']
                description = request.POST['body']
                code = request.POST['code']
                print title, description, code
                new_course = Course(title=title, description=description, code=code,
                                    teacher=person, college=person.college)
                new_course.save()
            except Exception as e:
                print e
    else:
        return render_to_response('404.html', locals(), context_instance=RequestContext(request))
    return render_to_response('add_course.html', locals(), context_instance=RequestContext(request))
Ejemplo n.º 29
0
 def test_get_reviewable_courses_invalid_token(self):
     with patch("course.views.get_current_semester") as mock_curr_semester, \
          patch("course.views.Course") as mock_course_db:
         mock_curr_semester.return_value = "H2020"
         mock_course_db.return_value.objects.return_value.filter.return_value = [
             Course.create("AAA9999", "Test course", 0, 0, 100.0)]
         with self.assertRaises(ValueError):
             get_reviewable_courses("invalid token")
Ejemplo n.º 30
0
 def post(self, request):
     course_code = request.POST.get('courseCode')
     if not Course.objects.filter(code=course_code).exists():
         return self.error(msg=f"course not exist", err=request.POST)
     else:
         try:
             # 赋予复制后的课程新code并返回该code,新课其余信息与原课一致
             codes = [int(course.code) for course in Course().objects]
             new_course_code = str(max(codes)+1)
             course = Course(code=course_code)
             Course.objects.create(code=new_course_code, name=course.name,
                                   start_time=course.start_time, end_time=course.end_time,
                                   description=course.description, deleted=course.deleted,
                                   students=course.students, teachers=course.teachers)
             return self.success(new_course_code)
         except Exception as e:
             return self.error(msg=str(e), err=e.args)
Ejemplo n.º 31
0
 def setUp(self) -> None:
     courses = [
         Course(course_code="TDT4120", course_name="AlgDat", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TMA4100", course_name="Matte 1", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="EXPH0004", course_name="Exphil", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TFE4101", course_name="KretsDigtek", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TFY4125", course_name="Fysikk", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TDT4290", course_name="KPro", credit=7.5, average_grade=1, pass_rate=100.0),
         Course(course_code="TDT4136", course_name="AI Intro", credit=7.5, average_grade=1, pass_rate=100.0),
     ]
     for c in courses: c.save()
     reviews = [
         Review(id=1, course_code="TMA4100", user_email="*****@*****.**", score=5, workload=1, difficulty=2,
                review_text="Bra f*g", full_name="Test test", study_programme="MTDT"),
         Review(id=2, course_code="TMA4100", user_email="*****@*****.**", score=3, workload=0, difficulty=0,
                review_text="Givende", full_name="KPro Kproson", study_programme="MTKPRO"),
         Review(id=3, course_code="TMA4100", user_email="*****@*****.**", score=4, workload=1, difficulty=2,
                review_text="Lattice", full_name="Heman 2015", study_programme="MTDT"),
         Review(id=4, course_code="TDT4120", user_email="*****@*****.**", score=5, workload=2, difficulty=2,
                review_text="Kult", full_name="KPro Kproson", study_programme="MTKPRO"),
         Review(id=5, course_code="TDT4120", user_email="*****@*****.**", score=1, workload=0, difficulty=0,
                review_text="Kjipt", full_name="Test test", study_programme="MTDT"),
         Review(id=6, course_code="EXPH0004", user_email="*****@*****.**", score=3, workload=1, difficulty=0,
                review_text="<3", full_name="KPro Kproson", study_programme="MTDT")
     ]
     for r in reviews: r.save()
     UserAuth(expiring_token="valid_token", access_token="valid_token", user_email="*****@*****.**").save()
     User.objects.create(username="******", email="*****@*****.**").save()
Ejemplo n.º 32
0
def pasth(request):
    context = RequestContext(request)
    if request.user.is_authenticated(): 
        data = request.POST.get('test')
        results = list()
        pq = PyQuery(data)
        coursesFound = 0;
        tempSchedule = Schedule()
        for c in pq('tr'):
            results.append(pq(c).text())
	
			#find out if this is class data
            query = "COURSE SECT GRADE CREDIT CREDIT EARNED CREDIT FOR GPA COURSE TITLE"
			
			
            if pq(c).text() == query: #go through the page to find when courses first appear 
				coursesFound = 1
				#print "found courses" #debug log
				
            else: #if it is not a header then do this
				if coursesFound == 1: #if it is not a header AND courses have already been found, parse them
					coursedata = pq(c)
					pastClass = Course() #temp class object 
					for d in coursedata('td'): # break the tr down into it's td values
						#print coursedata(d).text() #debugging logs 
						
						length = len(coursedata(d).text()) #get the length of the data so we know what field it is
						
						if length == 8:
							pastClass.name = coursedata(d).text()
						else: 
							if length == 4:
								 pastClass.section = coursedata(d).text() #0000 for transfer classes
							else:
								if length == 1 or length == 2:
									pastClass.finalgrade = coursedata(d).text() 
								else:
									if length == 3:
										pastClass.cedits = coursedata(d).text() #note: there can be multiple credit fields (credits earned, for gpa, credits), we are grabbing the very last one 
									else:
										pastClass.cname = coursedata(d).text()
					tempSchedule.add(pastClass)
						
        user_profile = request.user.get_profile()				
        user_profile.pastHistory = tempSchedule; #go to user profile and add tempschedule	
			
        return render_to_response('pasth.html', {"results": results,}, context_instance=context)

    else:
        return render_to_response('nsi.html', context_instance=context)
Ejemplo n.º 33
0
 def handle_noargs(self, **options):
     courses = simplejson.load(open(os.path.join(settings.COMMANDS_ROOT[0], 'courses.json')))
     institute = Institute.objects.get(name='University of Waterloo')
     for course in courses['courses']:
         course = course['course']
         title = course['title']
         abbrev = course['faculty_acronym'] + ' ' + course['course_number']
         description = course['description']
         try:
             Course.objects.get(title=title)
         except Course.DoesNotExist:
             new_course = Course()
             new_course.title = title
             new_course.abbrev = abbrev
             new_course.institute = institute
             new_course.description = description
             new_course.save()
             print 'Added: %s' % new_course.abbrev
Ejemplo n.º 34
0
def fill(request):
    bank_courses = parse_page()
    bank_names = map(lambda b: b['bank'], bank_courses)
    db_banks = list(Bank.objects.all())
    for b in bank_names:
        if len([i for i in db_banks if i.normal_name == b.lower()]) == 0:
            b_ = Bank(exact_name=b, normal_name=b.lower())
            b_.save()
            db_banks.append(b_)
    for course in bank_courses:
        bank = [i for i in db_banks if i.normal_name == course['bank'].lower()][0]
        date = datetime.now().strftime("%Y-%m-%d %H:00")
        c = Course(currency=0, sell=course['usd']['sell'], buy=course['usd']['buy'], bank=bank, date=date)
        c.save()
        c = Course(currency=1, sell=course['eur']['sell'], buy=course['eur']['buy'], bank=bank, date=date)
        c.save()
    return render(request, 'fill.html', {})
Ejemplo n.º 35
0
student_users.permissions.add(student_view)
teacher_users.permissions.add(teacher_view)
student_users.save()
teacher_users.save()

rob = User.objects.create_user('rob', '*****@*****.**', 'thomas')
rob.groups.add(student_users)
rob.save()

durga = User.objects.create_user('durga', '*****@*****.**', 'thomas')
durga.groups.add(teacher_users)
durga.save()

#Copy and paste everything above into a manage.py shell session

course1  = Course(title="course 1", slug="course-1", description="description", teacher=bob)
course1.save()

week_from_today = datetime.timedelta(days=7)
sample_due_date = datetime.date.today() + week_from_today
assignment1 = Assignment(name="assignment 1",
                         slug="assignment-1",
                         description="Assignment 1 description",
                         #due_date=datetime.datetime(2012, 7, 31, 5, 0, tzinfo=<UTC>),
                         due_date=sample_due_date,
                         teacher=bob,
                         course=course1)
assignment1.save()

grade1 = Grade(letter_grade="A",course=course1,assignment=assignment1)
grade1.save()
Ejemplo n.º 36
0
    def handle(self, *args, **options):
            updateR = False
            if options['rating']:
                updateR = True    
            url = "http://www.registrar.ufl.edu/soc/201401/all/"
            page = urllib2.urlopen(url)
            soup = BeautifulSoup(page)
            list1 = list()      # list of categories
            list2 = list()      #list of website endings
            soup2 = [option.get('value') for option in soup.findAll('option')]
            contents = [str(x.text) for x in soup.find_all('option')]
            x = 0
            for value in contents:
                # all option values all DEPARTMENTS
                list1.append(value)
                
            for value in soup2:
                # all endings for the web addresses per department 
                list2.append(value)

            for idx, website in enumerate(list2):
                temp1 = website.strip()
                if not not temp1:
                    print "OPENING: " + url + website
                    page = urllib2.urlopen(url+ website)
                    pages = str( page.read()) 
                    
                    started = False
                    moveA = False
                    count = 0
                    y = 0
                    g = Course('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')
                    pq = PyQuery(pages)
                    tag = pq('td')
                    index = list2.index(website)
                    
                    for c in  pq('td'):
                        if (pq(c).text().__len__() == 8 and pq(c).text()[3:4] == " ") or (pq(c).text().__len__() == 9 and pq(c).text()[3:4] == " "):
                                y = 0
                                x= x+1
                                
                                if g.name != '0':
                                    g.dept = list1[index] # Department added to each course
                                    g.save()
                                    
                                g = Course(x,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ')
                                g.name = pq(c).text()
                                started = True
                                moveA = False
                                
                        if (not (pq(c).text().__len__() == 8 and pq(c).text()[3:4] == " ") or (pq(c).text().__len__() == 9 and pq(c).text()[3:4] == " ")) and started == True:
                                y = y+1
                                if y == 7 and moveA != True:
                                     g.lday = pq(c).text()
                                if y == 21 and moveA != True:
                                     g.dday = pq(c).text()
                                if y == 22 and moveA != True:
                                     g.dtime = pq(c).text()
                                if y == 23 and moveA != True:
                                     g.dbuild = pq(c).text()
                                if y == 24 and moveA != True:
                                     g.droom = pq(c).text()
                                if y == 5 and moveA != True:
                                     if (len(pq(c).text()) == 0) or (len(pq(c).text()) == 1):
                                             moveA = True
                                     else: g.section = pq(c).text()
                                if y == 6 and moveA != True:
                                     g.cedits = pq(c).text()
                                if y == 8 and moveA != True:
                                     g.ltime = pq(c).text()
                                if y == 9 and moveA != True:
                                     g.lbuild = pq(c).text()
                                if y == 10 and moveA != True:
                                     g.lroom = pq(c).text()
                                if y == 12 and moveA != True:
                                     g.cname = pq(c).text()
                                if y == 13 and moveA != True:
                                     g.cinst = pq(c).text()
                                     if updateR:
                                         g.rmpr = getrmp(g.cinst,count)
                                         count = count +1
                                     
                                if y == 6 and moveA == True:
                                     g.section = pq(c).text()
                                if y == 7 and moveA == True:
                                     g.cedits = pq(c).text()
                                if y == 9 and moveA == True:
                                     g.ltime = pq(c).text()
                                if y == 22 and moveA == True:
                                     g.dday = pq(c).text()
                                if y == 23 and moveA == True:
                                     g.dtime = pq(c).text()
                                if y == 24 and moveA == True:
                                     g.dbuild = pq(c).text()
                                if y == 25 and moveA == True:
                                     g.dbuild = pq(c).text()
                                if y == 8 and moveA == True:
                                     g.lday = pq(c).text()
                                if y == 10 and moveA == True:
                                     g.lbuild = pq(c).text()
                                if y == 11 and moveA == True:
                                     g.lroom = pq(c).text()
                                if y == 13 and moveA == True:
                                     g.cname = pq(c).text()
                                if y == 14 and moveA == True:
                                     g.cinst = pq(c).text()
                                     if updateR:
                                         g.rmpr = getrmp(g.cinst,count)
                                         count = count +1
                                         
                                if y == 36 and moveA == True:
                                     g.d2day = pq(c).text()
                                if y == 37 and moveA == True:
                                     g.d2time = pq(c).text()
                                if y == 38 and moveA == True:
                                     g.d2build = pq(c).text()
                                if y == 39 and moveA == True:
                                     g.d2room = pq(c).text()
Ejemplo n.º 37
0
    def parse_courses(self, term, page):
    	# Get rows from the table
        rows = page.get_element_by_id('GridView1').xpath('tbody')[0]
        skip = True
        added = 0
        updated = 0
        # Parse all rows
        for row in rows:
            # Skip the first row (titles)
            if skip is True:
                skip = False
                continue

            # Parse elements
            crn = int(row.getchildren()[0].text.strip())
            course = row.getchildren()[1].xpath('a')[0].text.strip()
            course_link = row.getchildren()[1].xpath('a')[0].attrib['href']
            section = row.getchildren()[2].text.strip()
            title = row.getchildren()[3].xpath('a')[0].text.strip()
            bookstore_link = row.getchildren()[3].xpath('a')[0].attrib['href']
            hours = row.getchildren()[4].text.strip()
            attrstring = row.getchildren()[5].xpath('span')[0].text
            attributes = attrstring.strip() if attrstring else ''
            ctype = row.getchildren()[6].text.strip()
            meeting_times = []

            # Possibility of having multiple meeting times
            days_list = list(row.getchildren()[7].itertext())
            times_list = list(row.getchildren()[8].itertext())
            for i, days in enumerate(days_list):
                days = days.strip()
                # These don't have a meeting time at all
                if len(days) == 0:
                    continue
                time = MeetingTime(days=days)
                # Not all meeting times have a specific start/end time
                if len(times_list) >= i:
                    timestring = times_list[i].strip()
                    if len(timestring) > 0:
                        start_time = timestring.split('-')[0]
                        if len(start_time) == 3:
                            start_time = '0' + start_time
                        end_time = timestring.split('-')[1]
                        if len(end_time) == 3:
                            end_time = '0' + end_time
                        start_time = datetime.datetime.strptime(start_time, '%H%M').time()
                        end_time = datetime.datetime.strptime(end_time, '%H%M').time()
                        time.start_time = start_time
                        time.end_time = end_time
                        # Add it to the database
                        try:
                            obj = MeetingTime.objects.get(days=days, start_time=time.start_time, end_time=time.end_time)
                            time = obj
                        except MeetingTime.DoesNotExist:
                            time.save()
                        meeting_times.append(time)

            location = row.getchildren()[9].text.strip()
            if location == 'ARR':
                location = None

            instructor = row.getchildren()[10].text.strip()

            # Parse the instructor
            if instructor and len(instructor) > 0:
                instructor = self.parse_instructor(instructor)
            else:
                instructor = None

            seats = int(row.getchildren()[11].xpath('span')[0].text.strip())
            statusstring = row.getchildren()[12].xpath('span')[0].text.strip()
            status = 1 if statusstring == 'Open' else 0 if statusstring == 'Closed' else -1

            # Create the course
            course = Course(term=term, crn=crn, course=course, course_link=course_link, section=section, title=title, bookstore_link=bookstore_link, hours=hours, attributes=attributes, ctype=ctype, location=location, instructor=instructor, seats=seats, status=status)

            # Add it to the database
            try:
                obj = Course.objects.get(term=term, crn=crn)
                if not course.instructor:
                    course.instructor = obj.instructor
                opts = obj._meta
                changed = False
                for f in opts.fields:
                    if f.name not in ['id', 'meeting_times']:
                        old_attr = getattr(obj, f.name)
                        new_attr = getattr(course, f.name)
                        if old_attr != new_attr:
                            logger.debug('Changed value ' + f.name + ': ' + str(old_attr) + ' -> ' + str(new_attr))
                            changed = True
                            setattr(obj, f.name, new_attr)
                if len([item for item in obj.meeting_times.all() if item not in meeting_times]) > 0:
                    logger.debug('Changed meeting times ' + str(obj.meeting_times.all()) + ' -> ' + str(meeting_times))
                    changed = True
                    obj.meeting_times = meeting_times
                if changed:
                    logger.debug('Course listed as changed: /' + str(obj.term.value) + '/' + str(obj.crn))
                    updated += 1
                    obj.save()
            except Course.DoesNotExist:
                course.save()
                course.meeting_times = meeting_times
                added += 1

        self.stdout.write('-> Parsed ' + str(len(rows) - 1) + ' courses. ' + str(added) + ' added, ' + str(updated) + ' updated.')
        self.total_parsed += len(rows) - 1
        self.total_added += added
        self.total_updated += updated
Ejemplo n.º 38
0
 def save(self, **kw):
     u = Course(name=kw['name'], purpose=kw['purpose'], techerId=kw['techerId'], techerNumber=kw['techerNumber'], techerName=kw['techerName'])
     u.save()