コード例 #1
0
def show_courses_by_category(category_slug):
    categories = contentful().categories(api_id(), locale().code)

    active_category = None
    for category in categories:
        if category.slug == category_slug:
            active_category = category
            break
    if active_category is None:
        raise EntryNotFoundError('errorMessage404Category')

    courses = contentful().courses_by_category(
        active_category.id,
        api_id(),
        locale().code
    )

    if should_attach_entry_state(api_id(), session):
        for course in courses:
            attach_entry_state(course)

    return render_with_globals(
        'courses',
        title='{0} ({1})'.format(active_category.title, len(courses)),
        courses=courses,
        categories=categories,
        current_category=active_category,
        breadcrumbs=refine(raw_breadcrumbs(), active_category)
    )
コード例 #2
0
    def test_true_if_current_api_is_cpa_and_entry_is_pending_changes(self):
        entry = MockEntry('id')
        attach_entry_state(
            entry,
            MockService(datetime.datetime(2017, 12, 14),
                        datetime.datetime(2017, 12, 18)))

        self.assertTrue(should_show_entry_state(entry, 'cpa'))
コード例 #3
0
ファイル: index.py プロジェクト: SuneelMaurya/the-example-app
def show_index():
    landing_page = contentful().landing_page('home', api_id(), locale().code)

    if should_attach_entry_state(api_id(), session):
        attach_entry_state(landing_page)

    return render_with_globals(
        'landingPage',
        title='Home',
        landing_page=landing_page,
        breadcrumbs=refine(
            raw_breadcrumbs(),
            landing_page
        )
    )
コード例 #4
0
def show_courses():
    courses = contentful().courses(api_id(), locale().code)
    categories = contentful().categories(api_id(), locale().code)

    if should_attach_entry_state(api_id(), session):
        for course in courses:
            attach_entry_state(course)

    return render_with_globals(
        'courses',
        title='{0} ({1})'.format(
            translate('allCoursesLabel', locale().code),
            len(courses)
        ),
        courses=courses,
        categories=categories
    )
コード例 #5
0
def find_courses_by_slug(slug):
    course = contentful().course(slug, api_id(), locale().code)
    lessons = course.lessons if 'lessons' in course.fields(locale().code) else []

    visited_lessons = session.get('visited_lessons', [])
    if course.id not in visited_lessons:
        visited_lessons.append(course.id)
    session['visited_lessons'] = visited_lessons

    if should_attach_entry_state(api_id(), session):
        attach_entry_state(course)

    return render_with_globals(
        'course',
        title=course.title,
        course=course,
        lessons=lessons,
        lesson=None,
        next_lesson=lessons[0] if len(lessons) > 0 else None,
        visited_lessons=visited_lessons,
        breadcrumbs=refine(raw_breadcrumbs(), course)
    )
コード例 #6
0
def find_lesson_by_slug(course_slug, lesson_slug):
    course = contentful().course(course_slug, api_id(), locale().code)
    lessons = course.lessons if 'lessons' in course.fields(locale().code) else []

    lesson = None
    for l in lessons:
        if l.slug == lesson_slug:
            lesson = l
            break
    if lesson is None:
        raise EntryNotFoundError('errorMessage404Lesson')

    visited_lessons = session.get('visited_lessons', [])
    if lesson.id not in visited_lessons:
        visited_lessons.append(lesson.id)
    session['visited_lessons'] = visited_lessons

    next_lesson = find_next_lesson(lessons, lesson.slug)

    if should_attach_entry_state(api_id(), session):
        attach_entry_state(course)
        attach_entry_state(lesson)

    return render_with_globals(
        'course',
        title=course.title,
        course=course,
        lessons=lessons,
        lesson=lesson,
        next_lesson=next_lesson,
        visited_lessons=visited_lessons,
        breadcrumbs=refine(
            refine(
                raw_breadcrumbs(),
                course
            ),
            lesson
        )
    )
コード例 #7
0
    def test_true_if_current_api_is_cpa_and_entry_is_draft(self):
        entry = MockEntry('id')
        attach_entry_state(entry,
                           MockService(None, datetime.datetime(2017, 12, 14)))

        self.assertTrue(should_show_entry_state(entry, 'cpa'))