Ejemplo n.º 1
0
def youtube_playlist_to_course(playlist_url):
    playlist_id = playlist_extract_id(playlist_url)
    feed = srv.GetYouTubePlaylistVideoFeed(playlist_id=playlist_id)
    title = feed.title.text
    if feed.subtitle:
        subtitle = feed.subtitle.text
    else:
        subtitle = ' '
    from classes.models import CourseInfo, Session, CourseInfoSession, SessionLink
    ci = CourseInfo(title=title, description=subtitle)
    ci.url = 'http://www.youtube.com/view_play_list?p=' + playlist_id
    ci.save()
    for i, entry in enumerate(feed.entry):
        title = entry.title.text    
        if entry.location:
            location = entry.location.text
        if entry.content:
            content = entry.content.text
        else:
            content = ' '
        link = entry.link[0].href
        session = Session(title=title, description=content, video_url=link)
        session.save()
        cis = CourseInfoSession(course_info=ci, session=session, session_number=i+1)
        cis.save()
        #cisv = SessionLink(course_info_session=session, url=link)
        #cisv.save()
    return ci
Ejemplo n.º 2
0
def host_search(request):
    from classes.course_miners import youtube_playlist_to_data
    details = None
    if request.GET.has_key('q'):
        additional_vars = search_form(request.GET)
    if request.method == 'POST':
        course_form = MakeCourseForm(request.POST)
        if course_form.is_valid():
            clean_form = course_form.cleaned_data
            ci = CourseInfo(title=clean_form['title'], 
                    description=clean_form['description'], 
                    prereqs=clean_form['prerequisites'],
                    #from_date = course_form.cleaned_data['from_date'],
                    #course_number = course_form.cleaned_data['course_number'],
                    url = course_form.cleaned_data['url'])
            ci.save()
            try:
                if int(request.POST.get('links','0')) > 0:
                    course_data = youtube_playlist_to_data(clean_form['url'])
                    for i, entry in enumerate(course_data['links']):
                        title = entry.title.text    
                        if entry.location:
                            location = entry.location.text
                        content = entry.content.text
                        link = entry.link[0].href
                        session = Session(title=title, description=content, video_url=link)
                        session.save()
                        cis = CourseInfoSession(course_info=ci, session=session, session_number=i+1)
                        cis.save()
                        print 'session', session
            except: pass 
            ceditor = CourseInfoEditor(course_info=ci, editor=request.user, creator=True)
            ceditor.save()
            return HttpResponseRedirect('/h/create/%s/' % int_to_base36(ci.id))
    else:
        if request.GET.has_key('playlist_url'):
            course_data = youtube_playlist_to_data(request.GET.get('playlist_url', ''))
            course_form = MakeCourseForm(course_data)
            lenlinks = len(course_data['links'])
            details = mark_safe('This course has %d video lectures.  You can modify these in step 3.<input type="hidden" name="links" value="%s" />' % (lenlinks, lenlinks))
            if request.GET.has_key('a'):
                return render_to_response('host/incl/make_form.html', {'details': details, 'course_form': course_form}, context_instance=RequestContext(request))
        else:
            course_form = MakeCourseForm()
    render_vars = {'course_form': course_form, 
            'class_creater': True, 
            'playlist_url': request.GET.get('playlist_url', 'http://www.youtube.com/view_play_list?p=....')}
    if details:
        render_vars['details'] = details
    return render_to_response('host/make.html', render_vars, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def fork_class(request, host_b36):
    host_id = base36_to_int(host_b36) 
    host_class = HostClass.objects.get(pk=host_id)
    course = host_class.course
    if host_class.is_admin(request.user) and course.published: 
        ci = CourseInfo(title=course.title,
                description=course.description,
                prereqs=course.prereqs,
                #from_date=course.from_date,
                #course_number=course.course_number,
                url=course.url, previous_version=course)
        ci.save()
        i = 0
        for cis in course.course_info_session.all():
                cis = CourseInfoSession(course_info=ci, session=cis.session, session_number=i+1)
                i += 1
                cis.save()
        CourseInfoEditor(course_info=ci, editor=request.user, creator=True)
        host_class.course = ci
        host_class.save()
    return HttpResponseRedirect('/h/e/%s/' % (host_b36))