Пример #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
Пример #2
0
def host_create(request, course_b36=None, additional_vars={}):
    course_id = base36_to_int(course_b36) 
    user = request.user
    places = None
    if request.user.is_authenticated():
        places = user.place.all()
    course = CourseInfo.objects.get(pk=course_id)
    if request.method == 'POST':
        post_data = request.POST
        session_form = CourseSessionForm(post_data) # this form captures basic info, MWF, start date, meeting time
        place_fm = VenueForm(post_data)
        if session_form.is_valid():
            if post_data['place'] == '-1':
                if place_fm.is_valid():
                    place = place_fm.save(request)
                else:
                    raise Exception("place not valid?")
            else:
                place = Place.objects.get(pk=int(post_data["place"]))
            hc = session_form.save(course, place)
            hc_member = HostClassMember(host_class=hc, user=request.user, editor=True)
            hc_member.save()
            sessions = course.course_info_session.all()
            if len(sessions) > 0:
                for course_info_session in sessions:
                    session = course_info_session.session
                    next_date = hc.next_available_date()
                    hcs = HostClassSession(host_class=hc, course_session=session, date=datetime.combine(next_date, hc.meeting_time))
                    hcs.save()
            next = request.POST.get('next', '')
            if next == '1':
                return HttpResponseRedirect('/h/meetings/%s/?next=1' % (int_to_base36(hc.id)))
            else:
                return HttpResponseRedirect('/h/v/%s/' % (int_to_base36(hc.pk)))
    else:
        session_form = CourseSessionForm()

    render_vars = {'course': course, 'places': places, 'session_form':session_form, 'class_creater': True}
    return render_to_response('host/make2.html', render_vars
        , context_instance=RequestContext(request))