Example #1
0
def edit_class(request, host_b36):
    host_id = base36_to_int(host_b36) 
    host_class = HostClass.objects.get(pk=host_id)
    user = request.user

    places = None
    if request.user.is_authenticated():
        places = user.place.all()

    if host_class.is_admin(user):
        course = host_class.course
        if request.method == 'POST':
            post_data = request.POST
            course_form = MakeCourseForm(request.POST)
            session_form = CourseSessionForm(request.POST)
            place_form = VenueForm(post_data)
            if post_data['place'] == '-1':
                if place_form.is_valid():
                    place = place_form.save(request)
                else:
                    raise Exception("place not valid")
            else:
                place = Place.objects.get(pk=int(post_data["place"]))
            if course_form.is_valid() and session_form.is_valid():
                if not course.published: # and course.is_editor(request.user):
                    course.title = course_form.cleaned_data['title']
                    course.description = course_form.cleaned_data['description']
                    course.prereqs = course_form.cleaned_data['prerequisites']
                    #course.from_date = course_form.cleaned_data['from_date']
                    #course.course_number = course_form.cleaned_data['course_number']
                    course.url = course_form.cleaned_data['url']
                    course.save()
                hc = session_form.save(course, place, host_class)
                return HttpResponseRedirect('/h/e/%s/' % int_to_base36(hc.pk))
        else:
            course_form = MakeCourseForm({'title':course.title, 
                'description':course.description,
                'prerequisites':course.prereqs,
                #'from_date':course.from_date,
                #'course_number':course.course_number,
                'url':course.url })
            session_form = CourseSessionForm({'starting_date':host_class.disp_start_date, 
                'time':host_class.meeting_time, 
                'check_sunday': host_class.sunday,
                'check_monday': host_class.monday,
                'check_tuesday': host_class.tuesday,
                'check_wednesday': host_class.wednesday,
                'check_thursday': host_class.thursday,
                'check_friday': host_class.friday,
                'check_saturday': host_class.saturday,
                'privacy':host_class.privacy})

        return render_to_response('host/edit.html', {
            'host_class': host_class, 'course_form': course_form,
            'places': places, 'session_form': session_form
            }, context_instance=RequestContext(request))
    else:
        raise Http404
Example #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))