cms.plugins.inherit.cms_plugins: 55 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/cms/plugins/inherit/cms_plugins.py

Stats: 0 executed, 46 missed, 9 excluded, 29 ignored

  1. from cms.plugin_base import CMSPluginBase
  2. from cms.utils.moderator import get_cmsplugin_queryset
  3. from cms.utils import get_language_from_request
  4. from cms.plugin_pool import plugin_pool
  5. from django.utils.translation import ugettext_lazy as _
  6. from models import InheritPagePlaceholder
  7. from django.conf import settings
  8. from cms.plugins.inherit.forms import InheritForm
  9. import copy
  10. class InheritPagePlaceholderPlugin(CMSPluginBase):
  11. """
  12. Locates the plugins associated with the "from_page" of an InheritPagePlaceholder instance
  13. and renders those plugins sequentially
  14. """
  15. model = InheritPagePlaceholder
  16. name = _("Inherit Plugins from Page")
  17. render_template = "cms/plugins/inherit_plugins.html"
  18. form = InheritForm
  19. admin_preview = False
  20. page_only = True
  21. def render(self, context, instance, placeholder):
  22. template_vars = {
  23. 'placeholder': placeholder,
  24. }
  25. template_vars['object'] = instance
  26. lang = instance.from_language
  27. request = context.get('request', None)
  28. if not lang:
  29. if context.has_key('request'):
  30. lang = get_language_from_request(request)
  31. else:
  32. lang = settings.LANGUAGE_CODE
  33. if instance.from_page:
  34. page = instance.from_page
  35. else:
  36. page = instance.page
  37. if not instance.page.publisher_is_draft and page.publisher_is_draft:
  38. page = page.publisher_public
  39. plugins = get_cmsplugin_queryset(request).filter(
  40. placeholder__page=page,
  41. language=lang,
  42. placeholder__slot__iexact=placeholder,
  43. parent__isnull=True
  44. ).order_by('position').select_related()
  45. plugin_output = []
  46. template_vars['parent_plugins'] = plugins
  47. for plg in plugins:
  48. tmpctx = copy.copy(context)
  49. tmpctx.update(template_vars)
  50. inst, name = plg.get_plugin_instance()
  51. outstr = inst.render_plugin(tmpctx, placeholder)
  52. plugin_output.append(outstr)
  53. template_vars['parent_output'] = plugin_output
  54. context.update(template_vars)
  55. return context
  56. def get_form(self, request, obj=None, **kwargs):
  57. Form = super(InheritPagePlaceholderPlugin, self).get_form(request, obj, **kwargs)
  58. # this is bit tricky, since i don't wont override add_view and
  59. # change_view
  60. class FakeForm(object):
  61. def __init__(self, Form, site):
  62. self.Form = Form
  63. self.site = site
  64. # base fields are required to be in this fake class, this may
  65. # do some troubles, with new versions of django, if there will
  66. # be something more required
  67. self.base_fields = Form.base_fields
  68. def __call__(self, *args, **kwargs):
  69. # instanciate the form on call
  70. form = self.Form(*args, **kwargs)
  71. # tell form we are on this site
  72. form.for_site(self.site)
  73. return form
  74. return FakeForm(Form, self.cms_plugin_instance.page.site or self.page.site)
  75. plugin_pool.register_plugin(InheritPagePlaceholderPlugin)