当前位置: 首页>>代码示例>>Python>>正文


Python Course.save方法代码示例

本文整理汇总了Python中courses.models.Course.save方法的典型用法代码示例。如果您正苦于以下问题:Python Course.save方法的具体用法?Python Course.save怎么用?Python Course.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在courses.models.Course的用法示例。


在下文中一共展示了Course.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DeleteCourseViewTest

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
class DeleteCourseViewTest(TestCase):
    def setUp(self):
        self.new_course = Course(
            id='c0001',
            name='test_course',
            college='CS',
            classroom='Z2101',
            score=2.0,
            max_student_number=50,
            remark='',
        )
        self.new_course.save()

        manager_user = User.objects.create_user(username='m0001', password='')

        self.test_manager = Manager.objects.create(
            id='m0001',
            name='test_manager',
            user=manager_user,
            )

        manager_user.user_permissions = MANAGER_PERMISSION

    def test_manager_can_delete_a_exists_course(self):
        self.client.login(username=self.test_manager.id, password='')
        self.client.post('/courses/delete/', {'id': self.new_course.id, 'name': self.new_course.name})

        with self.assertRaises(exceptions.ObjectDoesNotExist):
            Course.objects.get(id=self.new_course.id)
开发者ID:dsdshcym,项目名称:course-pick,代码行数:31,代码来源:tests.py

示例2: test_lecture_cant_have_not_youtube_url

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
    def test_lecture_cant_have_not_youtube_url(self):
        course = Course()
        course.title = "Yet another title"
        course.save()

        week = Week()
        week.number = 1
        week.course = course
        week.save()

        data = {"title": "My lecture", "week": week, "order_id": 1,
                "embed_video_url": "https://www.youtube.com/embed/lXn7XKLA6Vg", }

        # For easy use
        _assert_true = self.assertTrue
        _assert_false = self.assertFalse
        urls = (
            ("http://habrahabr.ru", _assert_false), ("https://www.google.com.ua/", _assert_false),
            ("https://www.youtube.com/watch?v=lXn7XKLA6Vg", _assert_true)
        )

        for url, suggested_func in urls:
            data["video_url"] = url
            lecture = NewLectureForm(data=data)
            suggested_func(lecture.is_valid())
开发者ID:Cybran111,项目名称:Learning-system,代码行数:27,代码来源:tests.py

示例3: course_add

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
def course_add(request):
	
	#POST request signifies that someone is trying to add a course
	if request.method == 'POST':
		errors = []
		#add/edit the course to the db
		short_name = request.POST['short_name']
		name = request.POST['name']
		description = request.POST.get('description', '')
		c = Course(short_name=short_name, name=name, description=description)
		c.save()
		try:
			course_order = CourseOrder.objects.get(course=c)
		except CourseOrder.DoesNotExist:
			course_order = CourseOrder(course=c)
			course_orders = CourseOrder.objects.order_by('-order')[:1]
			if course_orders:
				course_order.order = course_orders[0].order + 1
			else:
				course_order.order=0
		course_order.save()
		return render_to_response('course/add.html', {'errors': errors}, context_instance=RequestContext(request))
	
	#GET request signifies that someone is asking for the form to add courses
	elif request.method == 'GET':
		return render_to_response('course/add.html', {}, context_instance=RequestContext(request))
	
	#We cannot process any request besides GET and POST
	else:
		logging.error("%s requested" % (request.method))
开发者ID:adaptives,项目名称:adaptivelearning,代码行数:32,代码来源:views.py

示例4: create_test_course

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
def create_test_course(name, owner, instructors=(), students=()):
    course = Course()
    course.name = name
    course.owner = owner
    course.save()
    course.instructors.add(*instructors)
    course.students.add(*students)
开发者ID:lockhawksp,项目名称:beethoven,代码行数:9,代码来源:tests.py

示例5: save

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
    def save(self):
        if self.cleaned_data['school']:
            school = self.cleaned_data['school']
        else:
            # Obtain and save the new school
            s_name = self.cleaned_data['school_name']
            s_url = self.cleaned_data['school_url']
            s_email = self.cleaned_data['school_email']
            s_phone = self.cleaned_data['school_phone']
            s_address = self.cleaned_data['school_address']
            s_city = self.cleaned_data['school_city']
            s_country = self.cleaned_data['school_country']
            
            new_s = School(name=s_name, url=s_url, email=s_email,
                           phone=s_phone, address=s_address, 
                           city=s_city, country=s_country)
            new_s.save()
            school = new_s

        # Get all the information
        name = self.cleaned_data['name']
        url = self.cleaned_data['url']
        description = self.cleaned_data['description']
        language = self.cleaned_data['language']
        level = self.cleaned_data['level']
        type = self.cleaned_data['type']
        lecturer = self.cleaned_data['lecturer']
        
        # Save the new course
        new_c = Course(name=name, url=url, description=description, language=language,
                       level=level, type=type, school=school, lecturer=lecturer)
        new_c.save()
开发者ID:marianabb,项目名称:REBUS,代码行数:34,代码来源:forms.py

示例6: open_course

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
def open_course(owner, name, short_description=None):
    course = Course()
    course.owner = owner
    course.name = name
    if short_description is not None:
        course.short_description = short_description
    course.save()
    return course
开发者ID:lockhawksp,项目名称:beethoven,代码行数:10,代码来源:services.py

示例7: AttachmentViewTests

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
class AttachmentViewTests(TestCase):
    """Test views for user interaction with attachments"""

    course1_data = {
        'code': 'EDU02',
        'name': 'A Course of Leeches',
        'abstract': 'Learn practical benefits of leeches',
    }
    lesson1_data = {
        'name': 'Introduction to Music',
        'abstract': 'A summary of what we cover',
    }
    att1_data = {
        'name': 'Reading List',
        'desc': 'Useful stuff you might need',
        'seq': 3,
        'attachment': 'empty_attachment_test.txt',
    }
    att2_data = {
        'name': 'Grammar Guide',
        'desc': 'How do you even spell grammer?',
        'seq': 2,
        'attachment': 'empty_attachment_test.txt',
    }

    def setUp(self):
        self.user1 = User.objects.create_user(
            'bertie', '[email protected]', 'bertword')
        self.user1.is_active = True
        self.user1.save()
        self.user2 = User.objects.create_user('dave', '[email protected]', 'dave')
        self.user2.is_active = True
        self.user2.save()
        self.course1 = Course(**self.course1_data)
        self.course1.organiser = self.user1
        self.course1.instructor = self.user1
        self.course1.save()
        self.lesson1 = Lesson(course=self.course1, **self.lesson1_data)
        self.lesson1.save()
        
        self.uc = UserCourse(course=self.course1, user=self.user2)
        self.uc.save()
        
        self.att1 = Attachment(course=self.course1, **self.att1_data)
        self.att2 = Attachment(lesson=self.lesson1, **self.att2_data)
        self.att1.save()
        self.att2.save()        
        
    def test_view_metadata(self):
        """Verify that the relevant metadata get rendered"""

        response = self.client.get(self.att1.get_metadata_url())
        self.assertEqual(response.status_code, 200)
        self.assertTrue(x in response.context
            for x in ['attachment'])
        self.assertIn("Reading List", response.content, 
                      u"detail missing from response")
开发者ID:chrismcginlay,项目名称:eduduck,代码行数:59,代码来源:test_views.py

示例8: test_json_courses

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
    def test_json_courses(self):
        """
        Test the /api/courses/ endpoint
        """
        temp_course = Course(name='Advanced Pottery III')
        temp_course.save()

        response = self.client.get('/api/courses/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue('Advanced Pottery III' in response.content)
开发者ID:DanielGarcia-Carrillo,项目名称:courseowl,代码行数:12,代码来源:tests.py

示例9: setUp

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
 def setUp(self):
     """Sets up the test case by creating a sample text and user"""
     self.u = User.objects.create_user("Mittens", "[email protected]", "meow")
     self.u.save()
     
     c = Course()
     c.save()
     l = Lesson(course=c)
     l.save()
     self.s = Section(lesson=l)
     self.s.save()
开发者ID:RossBrunton,项目名称:RThing,代码行数:13,代码来源:tests.py

示例10: create

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
def create(request, course_name):
  exists = Course.objects.filter(name=course_name)
  if len(exists) > 0:
    return HttpResponse('Class already exists')
    
  try:
    des = request.GET['description']
  except:
    des = "Class for " + course_name
  c = Course(name=course_name,description=des)
  c.save()
  return HttpResponse('Course ' + c.name + ' created.')
开发者ID:vpong,项目名称:ShyGuyHack,代码行数:14,代码来源:views.py

示例11: populate_courses

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
def populate_courses():
    prereq_map = {}
    sec_map = {}
    
    def clean(string):
        return unicode(string.strip().replace('\n',''))
    def lookup_section(name):
        return Section.objects.get(abbreviation=name)
    def add_prereqs():
        patstr = '(?:%s) \d{3}' % '|'.join(s.abbreviation for s in Section.objects.all())
        pat = re.compile(patstr)
        for course_id, prereqs in prereq_map.items():
            course = Course.objects.get(pk=course_id)
            for cstr in pat.findall(prereqs):
                sec, num = cstr.strip().rsplit(' ', 1)
                if sec not in sec_map:
                    try:
                        sec_map[sec] = Section.objects.get(abbreviation=sec)
                    except:
                        print 'EXITING:', cstr
                        exit()
                try:
                    prereq = Course.objects.get(section=sec_map[sec], number=num)
                    course.prereqs.add(prereq)
                except:
                    print 'ERROR: ', sec, num
                    
    #remove old courses
    for course in Course.objects.all():
        #print 'course %s %s is being deleted' % (course.section.abbreviation, course.number)
        course.delete()
    
    with open('data/courses.csv', 'r') as f:
        for line in f:
            line = line.replace('", "', '|').replace('"', '').replace('\n', '')
            section_name, number, title, descr, prereqs, credits = line.split('|')
            
            section = lookup_section(clean(section_name))
            if section is None:
                print 'Unknown section: %s' % section_name
                exit()
            
            course = Course(title = clean(title),
                            section = section,
                            number = int(clean(number)),
                            description = descr,
                            credits = int(clean(credits)))
            course.save()

            prereq_map[course.id] = prereqs
            
    add_prereqs()
开发者ID:emef,项目名称:gradpath,代码行数:54,代码来源:imports.py

示例12: UserLessonViewTests

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
class UserLessonViewTests(TestCase):
    """Test userlesson views"""

    def setUp(self):
        self.user1 = User.objects.create_user('bertie', '[email protected]', 'bertword')
        self.user1.is_active = True
        self.user1.save()
        self.user2 = User.objects.create_user('Van Gogh', '[email protected]', 'vancode')
        self.user2.is_active = True
        self.user2.save()
        self.user3 = User.objects.create_user('Chuck Norris', '[email protected]', 'dontask')
        self.user3.is_active = True
        self.user3.save()
        self.user4 = User.objects.create_user('James Maxwell', '[email protected]', 'pdq')
        self.user4.is_active = True
        self.user4.save()
        self.course1 = Course(**course1_data)
        self.course1.organiser = self.user1
        self.course1.instructor = self.user1
        self.course1.save()
        self.course2 = Course(**course2_data)
        self.course2.organiser = self.user2
        self.course2.instructor = self.user2
        self.course2.save()     
        self.uc = UserCourse(course=self.course1, user=self.user2)
        self.uc.save()
        self.lesson1 = Lesson(name="Test Lesson 1", course = self.course1)
        self.lesson1.save()
        self.ul = UserLesson(user=self.user2, lesson=self.lesson1)
        self.ul.save()

    def test_userlesson_single(self):
        """View contains correct context variables"""

        u2 = self.user2.id
        l1 = self.lesson1.id
        url1 = "/interaction/user/{0}/lesson/{1}/".format(u2,l1)

        #Not logged in
        response = self.client.get(url1)
        self.assertEqual(response.status_code, 302)

        #Now logged in
        self.client.login(username='Van Gogh', password='vancode')
        response = self.client.get(url1)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(x in response.context
            for x in ['ul', 'history'])

        #non existent record
        response = self.client.get('/interaction/user/2/lesson/4000/')
        self.assertEqual(response.status_code, 404)
开发者ID:chrismcginlay,项目名称:eduduck,代码行数:54,代码来源:test_views.py

示例13: create_course_view

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
def create_course_view(request):
    if request.method == 'POST':
        form = NewCourseForm(request.POST)
        if form.is_valid():
            new_course = Course()
            new_course.title = request.POST['title']
            new_course.short_description = request.POST['short_desc']
            new_course.full_description = request.POST['full_desc']
            new_course.save()
            return redirect(reverse('courses:course_page', args=(new_course.id,)))
    else:
        form = NewCourseForm()
        return render(request, 'new_course.html', {"new_course_form": form})
开发者ID:Cybran111,项目名称:Learning-system,代码行数:15,代码来源:views.py

示例14: handle

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
 def handle(self, *args, **options):
     # getting the DRPS page which list all the schools
     schools_index = requests.get(DRPS_URL + 'cx_schindex.htm')
     schools_index_tree = html.fromstring(schools_index.text)
     # After view-page-source we notice that school links share cx_s_su start
     schools_index_nodes = schools_index_tree.xpath('//a[starts-with(@href, "cx_s_su")]')
     for school_index_node in schools_index_nodes:
         school_title = re.search("^([^\(]+)", school_index_node.text).groups()[0]
         school_url = DRPS_URL + school_index_node.attrib['href']
         print school_title, school_index_node.attrib['href']
         old_school_set = School.objects.filter(title=school_title)
         # if school already exists update its URL
         if old_school_set:
             current_school = old_school_set.first()
             current_school.url = school_url
         else:
             current_school = School(title=school_title, url=school_url)
         current_school.save()
         school_detail = requests.get(school_url)
         school_detail_tree = html.fromstring(school_detail.text)
         # After view-page-source we notice that school subschools links share cx_sb start
         schools_detail_nodes = school_detail_tree.xpath('//a[starts-with(@href, "cx_sb")]')
         for school_detail_node in schools_detail_nodes:
             print "-----", school_detail_node.text, school_detail_node.attrib['href']
             course_index = requests.get(DRPS_URL + school_detail_node.attrib['href'])
             course_index_tree = html.fromstring(course_index.text)
             # After view-page-source we notice that school courses links pattern can be found by
             # looking at the schools url and extracting its initials with regex.
             course_code_prefix = re.search("cx_sb_([^\.]+).htm", school_detail_node.attrib['href'])
             if course_code_prefix:
                 prefix = course_code_prefix.groups()[0]
                 course_index_nodes = course_index_tree.xpath(('//a[starts-with(@href, "cx%s")]' % prefix))
                 for course_index_node in course_index_nodes:
                     td_node = course_index_node.getparent()
                     tr_node = td_node.getparent()
                     td_code_node = tr_node.getchildren()[0]
                     course_title = course_index_node.text
                     course_url = DRPS_URL + course_index_node.attrib['href']
                     course_code = td_code_node.text
                     old_course_set = Course.objects.filter(school=current_school, title=course_title)
                     if old_course_set:
                         current_course = old_course_set.first()
                         current_course.url = course_url
                         current_course.code = course_code
                         course_status = "OLD"
                     else:
                         current_course = Course(school=current_school, title=course_title, url=course_url,
                                                 code=course_code)
                         course_status = "NEW"
                     print "----------", course_status, course_title, course_index_node.attrib['href'], course_code
                     current_course.save()
开发者ID:ioannisk,项目名称:unicoursebook,代码行数:53,代码来源:scrapedrps.py

示例15: test_json_complete_course

# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import save [as 别名]
    def test_json_complete_course(self):
        """
        Test the /api/complete_course/ endpoint for a logged in user
        """
        login_successful = self.client.login(username='bob12345', password='bob123456')
        self.assertTrue(login_successful)

        temp_course = Course(name='Pottery')
        temp_course.save()
        response = self.client.post('/api/complete_course/', data={'completed_course': temp_course.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": true}', response.content)
        response = self.client.post('/api/complete_course/', data={'completed_course': 1234567890})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": false}', response.content)
开发者ID:DanielGarcia-Carrillo,项目名称:courseowl,代码行数:17,代码来源:tests.py


注:本文中的courses.models.Course.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。