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()})
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
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]))
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()})
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})
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'))