def render(self, context):
     slug = self.slug.resolve(context)
     request = context.get('request', None)
     if request is None:  # pragma: no cover
         if settings.DEBUG:
             msg = '"django.template.context_processors.request" is required to use django-scribbler'
             raise ImproperlyConfigured(msg)
         else:
             return ''
     if self.url:
         url = self.url.resolve(context)
     else:
         url = request.path
     key = CACHE_KEY_FUNCTION(slug=slug, url=url)
     scribble = cache.get(key, None)
     if scribble is None:
         try:
             scribble = Scribble.objects.get(slug=slug, url=url)
         except Scribble.DoesNotExist:
             scribble = Scribble(slug=slug, url=url, content=self.raw)
         if CACHE_TIMEOUT:
             cache.set(key, scribble, CACHE_TIMEOUT)
     if scribble.pk:
         if hasattr(template, 'engines'):
             scribble_template = template.engines['django'].from_string(scribble.content)
         else:
             scribble_template = template.Template(scribble.content)
     else:
         scribble.content = self.raw
         if hasattr(template, 'engines'):
             scribble_template = template.engines['django'].from_string(self.raw)
         else:
             scribble_template = template.Template(self.raw)
     scribble_context = build_scribble_context(scribble)
     content = scribble_template.render(scribble_context, request)
     wrapper_template = template.loader.get_template('scribbler/scribble-wrapper.html')
     context['scribble'] = scribble
     context['rendered_scribble'] = content
     user = context.get('user', None)
     show_controls = False
     can_edit = False
     can_add = False
     can_delete = False
     if user:
         can_edit = scribble.pk and user.has_perm('scribbler.change_scribble')
         can_add = (not scribble.pk) and user.has_perm('scribbler.add_scribble')
         can_delete = scribble.pk and user.has_perm('scribbler.delete_scribble')
     show_controls = can_edit or can_add or can_delete
     if can_edit or can_add:
         context['scribble_form'] = ScribbleForm(instance=scribble, prefix=slug)
     context['show_controls'] = show_controls
     context['can_add_scribble'] = can_add
     context['can_edit_scribble'] = can_edit
     context['can_delete_scribble'] = can_delete
     context['raw_content'] = self.raw
     # render() takes a dict, so we have to extract the context dict from the object
     context_data = context.dicts[-1]
     return wrapper_template.render(context_data, request)
 def render(self, context):
     slug = self.slug.resolve(context)
     request = context.get('request', None)
     if request is None:  # pragma: no cover
         if settings.DEBUG:
             msg = '"django.core.context_processors.request" is required to use django-scribbler'
             raise ImproperlyConfigured(msg)
         else:
             return ''
     if self.url:
         url = self.url.resolve(context)
     else:
         url = request.path
     key = CACHE_KEY_FUNCTION(slug=slug, url=url)
     scribble = cache.get(key, None)
     if scribble is None:
         try:
             scribble = Scribble.objects.get(slug=slug, url=url)
         except Scribble.DoesNotExist:
             scribble = Scribble(slug=slug, url=url, content=self.raw)
         if CACHE_TIMEOUT:
             cache.set(key, scribble, CACHE_TIMEOUT)
     if scribble.pk:
         scribble_template = template.Template(scribble.content)
     else:
         scribble.content = self.raw
         scribble_template = self.nodelist_default
     scribble_context = build_scribble_context(scribble, request)
     content = scribble_template.render(scribble_context)
     wrapper_template = template.loader.get_template(
         'scribbler/scribble-wrapper.html')
     context['scribble'] = scribble
     context['rendered_scribble'] = content
     user = context.get('user', None)
     show_controls = False
     can_edit = False
     can_add = False
     can_delete = False
     if user:
         can_edit = scribble.pk and user.has_perm(
             'scribbler.change_scribble')
         can_add = (
             not scribble.pk) and user.has_perm('scribbler.add_scribble')
         can_delete = scribble.pk and user.has_perm(
             'scribbler.delete_scribble')
     show_controls = can_edit or can_add or can_delete
     if can_edit or can_add:
         context['scribble_form'] = ScribbleForm(instance=scribble,
                                                 prefix=slug)
     context['show_controls'] = show_controls
     context['can_add_scribble'] = can_add
     context['can_edit_scribble'] = can_edit
     context['can_delete_scribble'] = can_delete
     context['raw_content'] = self.raw
     return wrapper_template.render(context)
 def render(self, context):
     slug = self.slug.resolve(context)
     request = context.get('request', None)
     if request is None: # pragma: no cover
         if settings.DEBUG:
             msg = '"django.core.context_processors.request" is required to use django-scribbler'
             raise ImproperlyConfigured(msg)
         else:
             return ''
     url = request.path
     key = CACHE_KEY_FUNCTION(slug=slug, url=url)
     scribble = cache.get(key, None)
     if scribble is None:
         try:
             scribble = Scribble.objects.get(slug=slug, url=url)
         except Scribble.DoesNotExist:
             scribble = Scribble(slug=slug, url=url, content=self.raw)
         if CACHE_TIMEOUT:
             cache.set(key, scribble, CACHE_TIMEOUT)
     if scribble.pk:
         scribble_template = template.Template(scribble.content)
     else:
         scribble.content = self.raw
         scribble_template = self.nodelist_default
     scribble_context = build_scribble_context(scribble, request)
     content = scribble_template.render(scribble_context)
     wrapper_template = template.loader.get_template('scribbler/scribble-wrapper.html')
     context['scribble'] = scribble
     context['rendered_scribble'] = content
     user = context.get('user', None)
     show_controls = False
     can_edit = False
     can_add = False
     can_delete = False
     if user:
         can_edit = scribble.pk and user.has_perm('scribbler.change_scribble')
         can_add = (not scribble.pk) and user.has_perm('scribbler.add_scribble')
         can_delete = scribble.pk and user.has_perm('scribbler.delete_scribble')
     show_controls = can_edit or can_add or can_delete
     if can_edit or can_add:
         context['scribble_form'] = ScribbleForm(instance=scribble, prefix=slug)
     context['show_controls'] = show_controls
     context['can_add_scribble'] = can_add
     context['can_edit_scribble'] = can_edit
     context['can_delete_scribble'] = can_delete
     context['raw_content'] = self.raw
     return wrapper_template.render(context)
Exemple #4
0
 def render(self, context):
     slug = self.slug.resolve(context)
     request = context.get('request', None)
     if request is None:  # pragma: no cover
         if settings.DEBUG:
             msg = '"django.template.context_processors.request" is required to use django-scribbler'
             raise ImproperlyConfigured(msg)
         else:
             return ''
     if self.url:
         url = self.url.resolve(context)
     else:
         url = request.path
     key = CACHE_KEY_FUNCTION(slug=slug, url=url)
     scribble = cache.get(key, None)
     if scribble is None:
         try:
             scribble = Scribble.objects.get(slug=slug, url=url)
         except Scribble.DoesNotExist:
             scribble = Scribble(slug=slug, url=url, content=self.raw)
         if CACHE_TIMEOUT:
             cache.set(key, scribble, CACHE_TIMEOUT)
     if scribble.pk:
         if hasattr(template, 'engines'):
             scribble_template = template.engines['django'].from_string(
                 scribble.content)
         else:
             scribble_template = template.Template(scribble.content)
     else:
         scribble.content = self.raw
         if hasattr(template, 'engines'):
             scribble_template = template.engines['django'].from_string(
                 self.raw)
         else:
             scribble_template = template.Template(self.raw)
     scribble_context = build_scribble_context(scribble)
     content = scribble_template.render(scribble_context, request)
     if self.readonly:
         return content
     wrapper_template = template.loader.get_template(
         'scribbler/scribble-wrapper.html')
     context['scribble'] = scribble
     context['rendered_scribble'] = content
     user = context.get('user', None)
     show_controls = False
     can_edit = False
     can_add = False
     can_delete = False
     if user:
         can_edit = scribble.pk and user.has_perm(
             'scribbler.change_scribble')
         can_add = (
             not scribble.pk) and user.has_perm('scribbler.add_scribble')
         can_delete = scribble.pk and user.has_perm(
             'scribbler.delete_scribble')
     show_controls = can_edit or can_add or can_delete
     if can_edit or can_add:
         context['scribble_form'] = ScribbleForm(instance=scribble,
                                                 prefix=slug)
     context['show_controls'] = show_controls
     context['can_add_scribble'] = can_add
     context['can_edit_scribble'] = can_edit
     context['can_delete_scribble'] = can_delete
     context['raw_content'] = self.raw
     # render() takes a dict, so we have to extract the context dict from the object
     context_data = context.dicts[-1]
     return wrapper_template.render(context_data, request)