當前位置: 首頁>>代碼示例>>Python>>正文


Python Course.name方法代碼示例

本文整理匯總了Python中models.Course.name方法的典型用法代碼示例。如果您正苦於以下問題:Python Course.name方法的具體用法?Python Course.name怎麽用?Python Course.name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Course的用法示例。


在下文中一共展示了Course.name方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_class

# 需要導入模塊: from models import Course [as 別名]
# 或者: from models.Course import name [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

示例2: course_admin_update

# 需要導入模塊: from models import Course [as 別名]
# 或者: from models.Course import name [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

示例3: add_course

# 需要導入模塊: from models import Course [as 別名]
# 或者: from models.Course import name [as 別名]
def add_course(request):
    '''
    add new course object to the database
    '''
    course = request.GET.get('course').upper()
    section = request.GET.get('section')
    response_data = {}
    course_info = {}
    response_data['error'] = False
    response_data['error_msg'] = ''

    # add the course to the user's list of courses
    user = UserProfile.objects.get(user=request.user)
    profile = request.user.profile

    # print course
    # print section

    if len(section) != 4:
        if len(section) == 3:
            section = "0" + section
        else:
            response_data['error'] = True
            response_data['error_msg'] = 'Section ID is invalid!'
            return HttpResponse(json.dumps(response_data), mimetype="application/json")

    # Set URL for testudo course search, term, and other query data
    page_url = "https://ntst.umd.edu/soc/search?courseId=" + course + "&sectionId=" + section + "&termId=201308&_openSectionsOnly=on&courseLevelFilter=ALL&classStartTime=&_classDays=on&teachingCenter=ALL"
    page = urllib2.urlopen(page_url).read()
    soup = BeautifulSoup(page)

    if soup.find("div", {"class" : "no-courses-message"}) != None:
        response_data['error'] = True
        response_data['error_msg'] = 'That course does not exist!'
        return HttpResponse(json.dumps(response_data), mimetype="application/json")

    if len(course) <= 4:
        response_data['error'] = True
        response_data['error_msg'] = 'That course does not exist!'
        return HttpResponse(json.dumps(response_data), mimetype="application/json")

    course_container = soup.find("div", {"class" : "courses-container"})
    first_block = course_container.find("div", {"class" : "course"}, {"id": course})

    if first_block == None:
        response_data['error'] = True
        response_data['error_msg'] = 'That course does not exist!'
        return HttpResponse(json.dumps(response_data), mimetype="application/json")

    class_block = first_block.find('div', {'class' : 'class-days-container'})
    classes = class_block.findAll('div', {'class' : 'row'})
    response_data['courses'] = []
    
    # create the new course objects and add them to database
    for i in range(0, len(classes)):
        try:
            # set c to the matching course if it exists in DB
            room = classes[i].find('span', {'class' : 'class-room'}).text
            c = Course.objects.get(name=course, section=section, room_number=room)
        except: 
            # course does not exist in DB, create new course and add it to DB
            c = Course()
            c.name = course.upper()
            c.section = section
    
            room = classes[i].find('span', {'class' : 'class-room'}).text
            
            if room != None:
                if room == 'ONLINE':
                    response_data['error'] = True
                    response_data['error_msg'] = 'You cannot add online classes!'
                    return HttpResponse(json.dumps(response_data), mimetype="application/json")
                else:
                    c.room_number = room
            
            c.build_code = classes[i].find('span', {'class' : 'building-code'}).text
            
            class_start = classes[i].find('span', {'class' : 'class-start-time'}).text
            c.start_time =  parser.parse(class_start)
            
            class_end = classes[i].find('span', {'class' : 'class-end-time'}).text
            c.end_time = parser.parse(class_end)
            
            c.section_days = classes[i].find('span', {'class' : 'section-days'}).text
            c.link = page_url

            if classes[i].find('span', {'class' : 'class-type'}) != None:
                c.tag = classes[i].find('span', {'class' : 'class-type'}).text
            
            c.save()
        
        # add course to user's list of courses
        if not c in profile.courses.all():
            user.courses.add(c)
            user.save()
    
            course_info = {}
            course_info['name']         = c.name
            course_info['section']      = c.section
            course_info['build_code']   = c.build_code
#.........這裏部分代碼省略.........
開發者ID:unscsprt,項目名稱:umagellan,代碼行數:103,代碼來源:views.py


注:本文中的models.Course.name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。