Source

django-depts / depts / scholars / views.py

Full commit
# -*- coding: utf-8 -*-


# django
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _

# 3rd-party
from courses.models import Course
from view_shortcuts.decorators import render_to

# this app
from models import Scholar


@render_to()
def scholar_list(request):
    qs = Scholar.objects.all()
    return {'object_list': qs}
scholar_list.navigation = _('employees')


_get_scholar = lambda slug: get_object_or_404(Scholar, slug=slug)

@render_to()
def scholar_detail(request, slug):
    obj = _get_scholar(slug)
    courses = Course.objects.filter(lecturers__person=obj)
    return {'object': obj, 'courses': courses}
scholar_detail.navigation = lambda request, slug: unicode(_get_scholar(slug))