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


Python Course.save方法代码示例

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


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

示例1: setup

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def setup(self):  
  user1 = User(username="test1", email="[email protected]", first_name="john", last_name="smith")
  user2 = User(username="test2", email="[email protected]", first_name="sally", last_name="smith")
  user1.save()
  user2.save()
  
  teacher1 = Teacher()
  teacher1.teacher = user1
  teacher1.save()
  teacher2 = Teacher()
  teacher2.teacher = user2
  teacher2.save()  

  course1 = Course(teacher=teacher1, name="Intro1", position=1)
  course2 = Course(teacher=teacher2, name="Advanced2", position=2)
  course1.save()
  course2.save()
  
  lesson1 = Lesson(course=course1, name="Lesson1", description="Intro1 - Lesson1", position=1)
  lesson2 = Lesson(course=course1, name="Lesson2", description="Intro1 - Lesson2", position=2)
  lesson1.save()
  lesson2.save()

  slide1 = Slide(lesson=lesson1, name="Slide1", content="<h1>Slide1</h1>", position=1, googleStyles=" ")
  slide2 = Slide(lesson=lesson1, name="Slide2", content="<h1>Slide2</h1>", position=2, googleStyles=" ")
  slide1.save()
  slide2.save()
开发者ID:Darkmer,项目名称:masterchief,代码行数:29,代码来源:tests.py

示例2: _course_exists

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def _course_exists(request):
    form = CourseInitialForm(request.POST, request.FILES)
    if form.is_valid():
        section_number = ""
        if request.user.get_profile().school.title == "James Madison University":
            section_number = request.POST['course_id'].zfill(4)
        else:
            section_number = request.POST['course_id']
        try:
            course = Course.objects.get(
                number__iexact=request.POST['course_number'],
                course_id__iexact=section_number,
                institution__iexact=request.user.get_profile().school.title)
            return (True, course)
        except Course.DoesNotExist:
            wall = ConvoWall(wall_type=3)
            wall.save()
            course = Course(
                wall=wall,
                number=request.POST['course_number'],
                course_id=section_number,
                institution=request.user.get_profile().school.title)
            course.save()
        return (False, course)
    return (False, None)
开发者ID:mdavoodi,项目名称:konkourse-python,代码行数:27,代码来源:views.py

示例3: parse_schedule

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def parse_schedule():
    html = open("switcher/schedule.txt")
    counter = 0
    department = ""
    for line in html:
        print counter
        counter += 1
        if re.findall(r'\S+', line) == []:
            continue
        x = re.findall('([A-Z]+[\s,/&]*?[A-Z]+)\s\s+([0-9A-Z]+)\s+([\s\S]+[\S])', line)
        if x == []:
            department = line.strip()
            #print department
            #"""
            d = Department()
            d.init(department)
            d.save()
            #"""
        else:
            #print x
            code = x[0][0] + "." + x[0][1] + ".Spring.2014"
            #"""
            c = Course()
            c.init(code, d)
            c.save()
开发者ID:young-geng,项目名称:sectionswitcher,代码行数:27,代码来源:parse_schedule.py

示例4: test_create_course

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
 def test_create_course(self):
     c = Course(title = 'Some Course',
                start_time='09:00',
                slots=20)
     c.save()
     self.assertQuerysetEqual(Course.objects.all(),
                             ['<Course: Some Course>'])
     
开发者ID:regisan,项目名称:eventex-regisan,代码行数:9,代码来源:tests.py

示例5: test_course_insert

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
  def test_course_insert(self):
    print "in test_course_insert"
    setup(self)

    self.assertEqual(Course.objects.count(), 2)
    course3 = Course(teacher=Teacher.objects.get(pk=1), name="Grad3", position=3)
    course3.save()
    self.assertEqual(Course.objects.count(), 3)
开发者ID:Darkmer,项目名称:masterchief,代码行数:10,代码来源:tests.py

示例6: populate

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def populate(line):
	overall = line.split('#')
	forCourses = overall[0].strip().split(',')
	y = [y.strip() for y in overall[1].strip().split('$')]
	c = Course(course_name=forCourses[0], course_ID=forCourses[1], course_acronym=forCourses[2], course_credits=int(forCourses[3]))
	c.save()
	c = Course.objects.get(pk=c.pk)
	for x in y:
		temp = [e.strip() for e in x.split(',')]
		c.offered_set.create(class_day=temp[0],start_time=str(1+TIME_CHOICES.index(temp[1])),end_time=str(1+TIME_CHOICES.index(temp[2])))
开发者ID:MayankVachher,项目名称:kron,代码行数:12,代码来源:populateScript.py

示例7: create_course

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def create_course(request):
    slug = slugify(request.POST['title_of_new_course'])
    course = Course(title=request.POST['title_of_new_course'], slug=slug)
    course.save()    
    course_author = CourseAuthorRelationship(course=course, author=request.user, order=1)
    course_author.save()
    #course.authors.add(course_author)
    course.save()
    response_data = {'url': course.get_admin_url()} 
    
    return HttpResponse(json.dumps(response_data), mimetype="application/json")
开发者ID:Robocademy,项目名称:robocademy,代码行数:13,代码来源:views.py

示例8: create_course

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def create_course(request, name, description, price, discount, init_date, end_date):

    s = Session.objects.get(session_key=request.session["auth_token"])
    user = User.objects.get(login=s.get_decoded()['login'])
    if user.user_type != 'Creator':
        return HttpResponseBadRequest('User is not Creator')
    init_date_parsed = dateutil.parser.parse(init_date)
    end_date_parsed = dateutil.parser.parse(end_date)
    course = Course(creator=user, name=name, description=description, price=price, discount=discount,
                    init_date=init_date_parsed, end_date=end_date_parsed)
    course.save()
    return HttpResponse('Course created successful')
开发者ID:tak30,项目名称:coursapi,代码行数:14,代码来源:views.py

示例9: add_class

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def add_class(request):
    name = request.POST['name']
    teacher = request.POST['teacher name']
    availability = request.POST['availability']
    description = request.POST['description']
    max_cap = request.POST['max_cap']
    c = Course()
    c.name = name
    c.teacher = teacher
    c.available = availability
    c.max_cap = max_cap
    c.description = description
    c.save()
    return HttpResponseRedirect(reverse('teacher'))
开发者ID:jkaashoek,项目名称:Iceblock,代码行数:16,代码来源:views.py

示例10: create_sample_courses

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def create_sample_courses():
    for y in range(2009,2012):
        create_semester('Fall', y, 9, 1, 12, 31)
        create_semester('Spring', y, 1, 1, 5, 30)
    semesters = Semester.objects.all()

    for co,nm in [("CS 101", "Fundamentals of Computer Science"),
                  ("CS 102", "Programming I"),
                  ("CS 117", "Programming II"),
                  ("CS 150", "Operating Systems"),
                  ("CS 164", "Software Engineering"),
                  ("CS 130", "Algorithms & Data Structures")]:
        for sem in random.sample(semesters, 3):
            tag = co.replace(' ', '').lower() + sem.tag
            grp = Group(name=tag)
            grp.save()
            key = '%x' % random.getrandbits(24)
            c = Course(tag=tag, name=nm, code=co, semester=sem,
                       group=grp, key=key,
                       is_active=_flip())
            c.save()

            us = random.sample(User.objects.all(), random.randrange(4,8))
            num_instructors = random.choice([1,2])
            instrs = us[:num_instructors]
            studs = us[num_instructors:]

            for u in us:
                e = Enrollment(course=c, user=u,
                               kind = 'I' if u in instrs
                               else random.choice(['A', 'G']),
                               notify_on_commit = _flip(),
                               notify_new_grades = _flip())
                e.save()

            ln = CourseLink(course=c, kind='H',
                            url='http://liucs.net/%s/' % tag)
            ln.save()

            if _flip():
                ln = CourseLink(course=c, kind='T',
                                url='http://amazon.com/%s' % nm)
                ln.save()

            if _flip():
                fmt = random.choice(['http://liucs.net/svn/%s/',
                                     'http://github.com/league/%s'])
                ln = CourseLink(course=c, kind='R', url=fmt % tag)
                ln.save()
开发者ID:league,项目名称:l3ms,代码行数:51,代码来源:tests.py

示例11: test_1

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
    def test_1(self):
        """Basic creation/update of Course and default language"""
        course_id = dummy_course_id_2
        c1 = Course(id=course_id, cat=self.cc0, description=dummy_course_description_2)
        self.assertEquals(c1.language, 'en')
        c1.save()

        desc2 = 'desc2'
        c2 = Course(id=course_id, cat=self.cc0, description=desc2)
        c2.save()

        obj = Course.objects.get(id=course_id)
        self.assertEquals(obj.description, desc2)

        self.assertEquals(obj.language, 'en')
开发者ID:trawick,项目名称:edurepo,代码行数:17,代码来源:tests.py

示例12: addcourse

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def addcourse(request):
    category = 'Course'
    if request.method == 'POST':
        form = CourseForm(request.POST)
        if form.is_valid():
            s = Course(name=form.cleaned_data["name"],
                       code=form.cleaned_data["code"],
                       classroom=form.cleaned_data["classroom"],
                       times=form.cleaned_data["times"]
                       )
            s.save()
            return HttpResponseRedirect('/all_courses/')
    else:
        form = CourseForm()

    return render_to_response('add.html', {'form': form, 'type': category}, RequestContext(request))
开发者ID:mrtbz,项目名称:homework4,代码行数:18,代码来源:views.py

示例13: create_course

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def create_course(request):
    if  request.method == 'POST':
        name=request.POST.get('course-name','')
     #   print "course is : ", name
	number = request.POST.get('max-number','')
        try:
            c = Course.objects.get(name__exact=name)
            if c:
	        message="Class Already Exist!"
	        return render_to_response('home.html',RequestContext(request,{'title':'TeacherHome','message':message}))

        except:
           print "course does not exists"
        user = request.user
        
	cou = Course(name=name,teacher=user.id)#,max_number=number)
        cou.save()
        #yield render_to_response('home.html',RequestContext(request,{'title':'TeacherHome','message':'Create Success!'}))
        return HttpResponseRedirect(reverse('teacher_home'))
开发者ID:CharlesCliff,项目名称:SC,代码行数:21,代码来源:teacherViews.py

示例14: course_admin_update

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
def course_admin_update(request, course_id, prefix):
    if request.is_ajax():
        form = CourseForm(request.POST) if prefix == 'None' else CourseForm(request.POST, prefix=prefix) 
        if form.is_valid():
            try:
                course = Course.objects.get(pk=course_id)
                course.teacher = form.cleaned_data['teacher']
                course.name = form.cleaned_data['name'] 
                course.save()
                return HttpResponse('OK')
                
            except ObjectDoesNotExist:
                # create new object
                position = None
                if Course.objects.count() > 0:
                    course = Course.objects.order_by('-position').all()[0]
                    position = course.position

                else:
                    position = 1

                newcourse = Course()
                newcourse.teacher = form.cleaned_data['teacher']
                newcourse.name = form.cleaned_data['name']
                newcourse.position = position
                newcourse.save()
                response = {'created_object_id': newcourse.pk}
                return HttpResponse(json.dumps(response), mimetype="application/json") 
        else:
            errors_dict = {}
            if form.errors:
                for error in form.errors:
                    e = form.errors[error]
                    field = prefix+"-"+error;
                    errors_dict[field] = unicode(e)
            print errors_dict
            return HttpResponseBadRequest(json.dumps(errors_dict))
    else:
        return HttpResponseNotFound('You do not have permission to access this page!')
开发者ID:Darkmer,项目名称:masterchief,代码行数:41,代码来源:views.py

示例15: save

# 需要导入模块: from models import Course [as 别名]
# 或者: from models.Course import save [as 别名]
 def save(self):
     cour = Course.query.get(self.code.data)
     if cour is None:
         cour = Course(
             code=self.code.data,
             desp=self.desp.data,
             major=self.major.data,
             additional=self.additional.data,
             num=self.num.data,
             credit=self.credit.data,
         )
     else:
         cour.modify(
             code=self.code.data,
             desp=self.desp.data,
             major=self.major.data,
             additional=self.additional.data,
             num=self.num.data,
             credit=self.credit.data,
         )
     cour.save()
     t = transline2times(self.coursetime.data)
     if t != False and t is not None and len(t) != 0:
         cdel = Timeplace.query.filter(Timeplace.code == self.code.data)
         cdel.delete()
         for st in t:
             ta = Timeplace(
                 code=self.code.data, weekday=st[0], starttime=st[1], durtime=st[2], place=st[3], additional=st[4]
             )
             ta.save()
     tea = transline2tea(self.teas.data)
     if tea is not None and len(tea) != 0:
         tdel = Emp.query.filter(Emp.code == self.code.data)
         tdel.delete()
         for st in tea:
             ta = Emp(code=self.code.data, teaid=st)
             ta.save()
     return cour
开发者ID:jt-wang,项目名称:xk-database,代码行数:40,代码来源:admin.py


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