Example #1
0
def courses_lessons(request):
    queryset = Lesson.objects.none()
    
    if request.GET:
        queryset = Lesson.objects.all()
        form = LessonSearchForm(request.GET)
        if form.is_valid():
            queryset = _search_lessons(queryset, form)
    else:
        form = LessonSearchForm()
    
    return django_object_list(request, queryset=queryset, template_name='courses/lesson_list.html', extra_context={'form':form})
Example #2
0
def lesson_list_json(request):
#    course = get_object_or_404(Course, pk=course_id)
    form = LessonSearchForm(request.GET)
    lessons = Lesson.objects.none()
    if form.is_valid():
        lessons = Lesson.objects.all()
        lessons = _search_lessons(lessons, form)
    lessons = [{'id':a.pk,
                'start':format(a.start, 'Y-m-d\TH:i:s.000O'),
                'end':format(a.end, 'Y-m-d\TH:i:s.000O'),
                'title':u'%s - %s' % (a.classroom, a.course),
                'replan_url':reverse(lesson_replan, kwargs={'course_id':a.course.pk, 'object_id':str(a.pk)})} 
                for a in lessons]
    text = simplejson.dumps(lessons)
    return HttpResponse(text, mimetype='application/json')
Example #3
0
def lesson_list_ical(request):
    form = LessonSearchForm(request.GET)
    lessons = Lesson.objects.none()
    if form.is_valid():
        lessons = Lesson.objects.all()
        lessons = _search_lessons(lessons, form)
    cal = vobject.iCalendar()
    cal.add('method').value = 'PUBLISH'  # IE/Outlook needs this
    for lesson in lessons:
        vevent = cal.add('vevent')
        vevent.add('dtstart').value = lesson.start
        vevent.add('dtend').value = lesson.end
        vevent.add('location').value = unicode(lesson.classroom)
        vevent.add('summary').value = unicode(lesson.course)
        vevent.add('created').value = lesson.created
        vevent.add('last-modified').value = lesson.updated
    icalstream = cal.serialize()
    response = HttpResponse(icalstream, mimetype='text/calendar')
    response['Filename'] = 'lekcie.ics'  # IE needs this
    response['Content-Disposition'] = 'attachment; filename=filename.ics'
    return response