Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Context Processor for Django Site
  2. def add_wedding_context(request):
  3.     id_ = request.GET.get('wedding_id', None)
  4.     wedding = None
  5.     if id_ is not None:
  6.         try:
  7.             wedding = Wedding.objects.get(id=id_)
  8.         except Wedding.DoesNotExist:
  9.             pass
  10.     return {'wedding':wedding}
  11.        
  12. from django.utils.functional import SimpleLazyObject
  13. from functools import partial
  14.  
  15. def get_wedd_or_none(id_):
  16.     try:
  17.         return Wedding.objects.get(id=id_)
  18.     except Wedding.DoesNotExist:
  19.         return None
  20.  
  21. def add_wedding_context(request):
  22.     id_ = request.GET.get('wedding_id', None)
  23.     if id_ is not None:
  24.         lazy = SimpleLazyObject(partial(get_wedd_or_none, id_))
  25.         return {'wedding': lazy}
  26.     else:
  27.         return {'wedding': None}
  28.        
  29. class ViewWedding(DetailView):
  30.   model = Wedding
  31.   pk_url_kwarg = 'wedding_id'
  32.   template_name = 'you-template.html'
  33.   context_object_name = 'wedding'
  34.        
  35. import re
  36.  
  37. def add_wedding_ring(request):
  38.   if re.match('.*/id=.*',request.get_full_path()):
  39.      return {'wid':Wedding.objects.get(id=wedding_id)}
  40.   return {}