Пример #1
0
def show_settings():
    current_space_id = space_id()
    current_delivery_token = delivery_token()
    current_preview_token = preview_token()

    errors = check_errors(current_space_id, current_delivery_token,
                          current_preview_token)

    if errors:
        restore_session_to_last_valid_values()

    space = contentful().space(api_id())
    return render_with_globals(
        'settings',
        title=translate('settingsLabel',
                        locale().code),
        errors=errors,
        has_errors=bool(errors),
        success=False,
        space=space,
        is_using_custom_credentials=is_using_custom_credentials(session),
        space_id=current_space_id,
        delivery_token=current_delivery_token,
        preview_token=current_preview_token,
        host=request.url_root)
Пример #2
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)
    )
Пример #3
0
def render_entry_error(status_code, error, stacktrace):
    return render_with_globals('error',
                               error=error,
                               known_resource=True,
                               from_contentful=True,
                               stacktrace=stacktrace,
                               status=status_code,
                               environment=environ.get('APP_ENV',
                                                       None)), status_code
Пример #4
0
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
        )
    )
Пример #5
0
def reset_settings():
    session.pop('space_id', None)
    session.pop('delivery_token', None)
    session.pop('preview_token', None)
    session.pop('editorial_features', None)

    space = contentful().space(api_id())

    return render_with_globals('settings',
                               title=translate('settingsLabel',
                                               locale().code),
                               errors={},
                               has_errors=False,
                               success=False,
                               space=space,
                               host=request.url_root)
Пример #6
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
    )
Пример #7
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)
    )
Пример #8
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
        )
    )
Пример #9
0
def save_settings():
    space_id = request.values.get('spaceId', None)
    delivery_token = request.values.get('deliveryToken', None)
    preview_token = request.values.get('previewToken', None)
    editorial_features = bool(request.values.get('editorialFeatures', False))

    errors = check_errors(space_id, delivery_token, preview_token)

    if not errors:
        update_session_for('space_id', space_id)
        update_session_for('delivery_token', delivery_token)
        update_session_for('preview_token', preview_token)
        update_session_for('editorial_features', editorial_features)

    space = contentful().space(api_id())
    return render_with_globals(
        'settings',
        title=translate('settingsLabel',
                        locale().code),
        errors=errors,
        has_errors=bool(errors),
        success=not bool(errors),
        space=space,
        host=request.url_root), 201 if not errors else 409
Пример #10
0
def show_imprint():
    return render_with_globals(
        'imprint',
        title=translate('imprintLabel', locale().code)
    )