本文整理汇总了Python中courses.models.Course.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Course.get_by_id方法的具体用法?Python Course.get_by_id怎么用?Python Course.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courses.models.Course
的用法示例。
在下文中一共展示了Course.get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_by_id [as 别名]
def update(request,course_id):
cid=int(course_id)
course=Course.get_by_id(cid)
course_form=CourseForm(request.POST,instance=course)
if course_form.is_valid():
course=course_form.save()
return HttpResponseRedirect(reverse('course_path',args=[cid]))
else:
return render_to_response('courses/edit.html',{'form':course_form,'user':users.get_current_user()})
示例2: search
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_by_id [as 别名]
def search(cls, line, user):
count = {}
for word in line.lower().split():
for result in cls.all().filter(word=word):
key = (result.table, result.tblkey)
count[key] = count.get(key, 0) + result.weight
values = []
from courses.models import Course # cross referencing between files
for (table, key) in sorted(count, key=count.get, reverse=True):
if table == COURSE_TABLE:
course = Course.get_by_id(key)
if user.has_permission(course):
values.append((table, course))
else:
raise NotImplementedError
return values
示例3: content
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_by_id [as 别名]
def content(request,course_id):
cid=int(course_id)
course=Course.get_by_id(cid)
if request.method == 'GET':
form=EditContentForm({'content':course.content})
return render_to_response('courses/content.html',{'form':form,'course':course,'path':request.path,'user':users.get_current_user()})
elif request.method == 'POST':
form=EditContentForm(request.POST)
if form.is_valid():
text_content=form.cleaned_data['content']
#text_content=text_content.encode('utf-8')
bb=text_content.replace('\r\n','$')
text_content=bb.replace('$','\n')
course.content=text_content
lines=text_content.strip().splitlines()
course.content_count=len(lines)
# create course header
course_header="title:%s\n" % course.title
course_header+="key:%s\n" % str(course.key())
course_header+="language:%s\n" % course.lang_code
course_header+="region:%s\n" % course.region_code
course_header+="level:%s\n" % 'fundamental'
#course_header+="version:#{gen_course_file_at.to_i}\n"
course_header+="type:%s\n" % 'simple'
course_header+="content_count:%s\n" % len(lines)
course_header+="separator:10\n"
header_size_binary_str=pack('!h',len(course_header.encode('utf-8')))
content_str=header_size_binary_str+course_header.encode('utf-8')+text_content.encode('utf-8')
course.content_blob=db.Blob(content_str)
new_md5=md5.new(content_str).hexdigest()
if len(lines)>10:
course.ready=True
#logging.info(course.content)
if new_md5!=course.md5_digest:
course.md5_digest=new_md5
course.put()
return HttpResponseRedirect(reverse('course_path',args=[cid]))
示例4: edit
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_by_id [as 别名]
def edit(request,course_id):
cid=int(course_id)
course=Course.get_by_id(cid)
course_form=CourseForm(instance=course)
return render_to_response('courses/edit.html',{'form':course_form,'course':course,'user':users.get_current_user()})
示例5: show
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_by_id [as 别名]
def show(request,course_id):
cid=int(course_id)
course=Course.get_by_id(cid)
editable=(course==users.get_current_user() or users.is_current_user_admin())
return render_to_response('courses/show.html',{'course':course,'editable':editable})
示例6: destroy
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_by_id [as 别名]
def destroy(request,course_id):
cid=int(course_id)
course=Course.get_by_id(cid)
if course.creator==users.get_current_user() or users.is_current_user_admin():
db.delete(course)
return HttpResponseRedirect(reverse('courses.views.index'))