Class-based view mixin for flatpages

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from django.contrib.flatpages.models import FlatPage
 
 
class FlatPageMixin(object):
    """
    Retrieves the FlatPage object for the specified url, and includes it in the
    context.
 
    If no url is specified, request.path is used.
    """
    url = None
 
    def get_context_data(self, **kwargs):
        if not self.url:
            self.url = self.request.path
 
        context = super(FlatPageMixin, self).get_context_data(**kwargsG)
        try:
            flatpage = FlatPage.objects.get(url=self.url)
            flatpage.title = mark_safe(flatpage.title)
            flatpage.content = mark_safe(flatpage.content)
            context["flatpage"] = flatpage
        except FlatPage.DoesNotExist:
            context["flatpage"] = None
 
        return context

More like this

  1. template tag for highlighting currently active page by adunar 4 years, 7 months ago
  2. Class-based process form view. by I159 1 year, 5 months ago
  3. Easier and Faster than flatpages. Rendering templates by simpling calling by his path on the URL by mariocesar 1 year, 2 months ago
  4. View mixin and utils to generate PDF documents from html using xhtml2pdf by frankban 1 year, 8 months ago
  5. Class-Based AJAX fallback view by fahhem 2 years, 4 months ago

Comments

ecigarette-france (on May 20, 2013):

comment fonctionne la e-cigarette , pour plus d'infos , rdv sur la boutique de cigarette électronique rechargeable

#

(Forgotten your password?)