Пример #1
0
    @classmethod
    def get_category(cls):
        return 'viewlet'

    def render_viewlet(self, request, template_name='viewlet.html', context=None):
        if context is None:
            context = {}
        viewlet_context = {
            'registered_viewlet': self.get_registered_item(),
            'viewlet': self,
            'template_base': 'viewlet.html',
        }
        for key, value in viewlet_context.items():
            if key not in context:
                context[key] = value  # only set if key does not already exist
        return render_to_string(template_name, context,
                                context_instance=RequestContext(request))

    def render(self, request, context=None):
        raise NotImplementedError('You have to override this method')


def registered_viewlet(sender, **kwargs):
    if issubclass(sender, Viewlet):
        registered_item = kwargs['registered_item']
        registered_item.name = sender.name
        registered_item.save()


item_registered.connect(registered_viewlet)
Пример #2
0
    default_place = 'leftsidebar'

    def render(self, request, place, section, context,
               *args, **kwargs):
        raise NotImplementedError()


def registered_block(sender, **kwargs):
    if issubclass(sender, BaseBlock):
        registered_item = kwargs['registered_item']
        registered_item.placed_at = sender.default_place
        registered_item.name = sender.name

        # optional block settings
        if hasattr(sender, 'is_fixed'):
            registered_item.is_fixed = sender.is_fixed
        if hasattr(sender, 'fixed_place'):
            registered_item.fixed_place = sender.fixed_place

        registered_item.save()


item_registered.connect(registered_block)


def reset_block_debug_info(**kwargs):
    """ Resets the block information (for debug) when a Django request is started."""
    global block_debug_info
    block_debug_info = {}
signals.request_started.connect(reset_block_debug_info)
Пример #3
0
    def render_viewlet(self,
                       request,
                       template_name='viewlet.html',
                       context=None):
        if context is None:
            context = {}
        viewlet_context = {
            'registered_viewlet': self.get_registered_item(),
            'viewlet': self,
            'template_base': 'viewlet.html',
        }
        for key, value in viewlet_context.items():
            if key not in context:
                context[key] = value  # only set if key does not already exist
        return render_to_string(template_name,
                                context,
                                context_instance=RequestContext(request))

    def render(self, request, context=None):
        raise NotImplementedError('You have to override this method')


def registered_viewlet(sender, **kwargs):
    if issubclass(sender, Viewlet):
        registered_item = kwargs['registered_item']
        registered_item.name = sender.name
        registered_item.save()


item_registered.connect(registered_viewlet)
Пример #4
0
    def render(self, request, place, section, context, *args, **kwargs):
        raise NotImplementedError()


def registered_block(sender, **kwargs):
    if issubclass(sender, BaseBlock):
        registered_item = kwargs['registered_item']
        registered_item.placed_at = sender.default_place
        registered_item.name = sender.name

        # optional block settings
        if hasattr(sender, 'is_fixed'):
            registered_item.is_fixed = sender.is_fixed
        if hasattr(sender, 'fixed_place'):
            registered_item.fixed_place = sender.fixed_place

        registered_item.save()


item_registered.connect(registered_block)


def reset_block_debug_info(**kwargs):
    """ Resets the block information (for debug) when a Django request is started."""
    global block_debug_info
    block_debug_info = {}


signals.request_started.connect(reset_block_debug_info)