Esempio n. 1
0
def category(request, cat_id, class_id=None):
    r"""
    This is the view for category and base_category (``/class/<class_id>/category/<cat_id>`` and ``/category/<cat_id>``).  It generates the category page which has a table of all the content in all of its ``child_atoms`` and all of the ``child_atoms`` in all categories under it.
    """
    if class_id is not None:
        template = 'web/home/class/category.html'
        category_object = get_object_or_404(ClassCategory, id=cat_id)
        class_object = get_object_or_404(Class, id=class_id)
        # Check if user is allowed to see this page
        if has_class_access(class_object, request.user):
            return HttpResponseRedirect(reverse('class_index')) # Redirect
    else:
        template = 'web/home/base/category.html'
        category_object = get_object_or_404(BaseCategory, id=cat_id)
        class_object = None # We aren't in a class
    context = get_navbar_context(category_object, class_object)
    context.update( # Add the breadrumbs to the context
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    context.update( # Add the category specific content to the context
        get_context_for_category(category_object)
    )
    context.update({
        'class_object':class_object,
        'category_object':category_object,
    })

    return render(request, template, context)
Esempio n. 2
0
def atom(request, cat_id, atom_id, class_id=None):
    r"""
    This is the view for both the ``atom`` view and the ``base_atom`` view (``/class/<class_id>/category/<cat_id>/atom/<atom_id>`` and ``/category/<cat_id>/atom/<atom_id>``).  It generates the content that is contained in the atom.
    """
    if class_id is not None:
        template = 'web/home/class/category.html'
        class_object = get_object_or_404(Class, id=class_id)
        category_object = get_object_or_404(ClassCategory, id=cat_id)
        # Check if user is allowed to see this page
        if has_class_access(class_object, request.user):
            return HttpResponseRedirect(reverse('class_index')) # Redirect
    else:
        template = 'web/home/base/category.html'
        class_object = None
        category_object = get_object_or_404(BaseCategory, id=cat_id)
    atom_object = get_object_or_404(Atom, id=atom_id) 
    context = get_navbar_context(category_object, class_object)
    context.update( # Add the breadcrumbs to the context
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    context.update( # Add the atom specific content to the context
        get_context_for_atom(atom_object)
    )
    context.update({
        'atom_object': atom_object,
        'class_object':class_object,
        'forum': Forum.objects.get(atom=atom_object),
    })
    return render(request, template, context)
Esempio n. 3
0
def classes(request, class_id):
    r"""
    This is the view for the class home page.  It shows the class summary.
    """
    class_object = get_object_or_404(Class, id=class_id)
    # Check if user is allowed to see this page
    if has_class_access(class_object, request.user):
        return HttpResponseRedirect(reverse('class_index')) # If not redirect
    context = get_navbar_context(None, class_object)
    context.update( # Add breadcrumbs to context
        get_breadcrumbs(request.path, web_breadcrumb_dict)
    )
    context.update({ # Add the class_objet to the context
        'class_object': class_object
    })
    return render(request, 'web/home/class/index.html', context)