update email for teachers
[edumed.git] / edumed / views.py
1 # -*- coding: utf-8 -*-
2 from django.conf import settings
3 from django.contrib.flatpages.models import FlatPage
4 from django.contrib.flatpages.views import render_flatpage
5 from django.contrib.sites.models import get_current_site
6 from django.http.response import Http404, HttpResponsePermanentRedirect
7 from django.shortcuts import get_object_or_404
8 from django.views.generic import TemplateView
9
10
11 def flatpage_with_template(request, url, template_name):
12     """
13     Public interface to the flat page view.
14
15     Models: `flatpages.flatpages`
16     Templates: Uses the template defined by the ``template_name`` field,
17         or :template:`flatpages/default.html` if template_name is not defined.
18     Context:
19         flatpage
20             `flatpages.flatpages` object
21     """
22     if not url.startswith('/'):
23         url = '/' + url
24     site_id = get_current_site(request).id
25     try:
26         f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
27     except Http404:
28         if not url.endswith('/') and settings.APPEND_SLASH:
29             url += '/'
30             get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
31             return HttpResponsePermanentRedirect('%s/' % request.path)
32         else:
33             raise
34     f.template_name = template_name
35     return render_flatpage(request, f)