Beispiel #1
0
def widget(parser, token):
    '''
    {% widgetcontent CT_ID.PK PAGE_ID [get_data] %}{json_config}{% endwidgetcontent %}

    TODO:
    add [using TEMPLATE_NAME] option
    and use select_template in widget.html - maybe not needed any more because of cached select_template
    '''
    valid_syntax = 'valid syntax is: {% widgetcontent CT_ID.PK PAGE_ID [get_data] %}{json_config}{% endwidgetcontent %}'

    bits = token.split_contents()
    l = len(bits)

    widget = None
    page_id = None
    get_data = False

    if l < 3:
        raise template.TemplateSyntaxError("too short\n%s" % valid_syntax)
    if bits[1].count('.') == 1:
        # variant: widgetcontent CT_ID.PK PAGE_ID ...
        widget = bits[1].split('.')
        page_id = bits[2]

        try:
            widget = get_object(*widget)
        except ObjectDoesNotExist, e:
            raise template.TemplateSyntaxError("invalid widget's type,pk\n%s" %
                                               valid_syntax)
Beispiel #2
0
def widget(parser, token):
    '''
    {% widgetcontent CT_ID.PK PAGE_ID [get_data] %}{json_config}{% endwidgetcontent %}

    TODO:
    add [using TEMPLATE_NAME] option
    and use select_template in widget.html - maybe not needed any more because of cached select_template
    '''
    valid_syntax = 'valid syntax is: {% widgetcontent CT_ID.PK PAGE_ID [get_data] %}{json_config}{% endwidgetcontent %}'

    bits = token.split_contents()
    l = len(bits)

    widget = None
    page_id = None
    get_data = False

    if l < 3:
        raise template.TemplateSyntaxError("too short\n%s" % valid_syntax)
    if bits[1].count('.') == 1:
        # variant: widgetcontent CT_ID.PK PAGE_ID ...
        widget = bits[1].split('.')
        page_id = bits[2]

        try:
            widget = get_object(*widget)
        except ObjectDoesNotExist, e:
            raise template.TemplateSyntaxError("invalid widget's type,pk\n%s" % valid_syntax)
Beispiel #3
0
def widget(parser, token):
    '''
    {% widget WIDGET_VAR WIDGETINPAGE_VAR [get_data] %}

    or

    {% widget CT_ID.PK PAGE_ID [get_data] %}
    '''
    valid_syntax = 'valid syntax is: {% widget WIDGET_VAR WIDGETINPAGE_VAR [get_data] %} || {% widget CT_ID.PK PAGE_ID [get_data] %}'

    bits = token.split_contents()
    l = len(bits)

    widget = None
    widget_in_page = None
    get_data = False

    if l < 3:
        raise template.TemplateSyntaxError("too short\n%s" % valid_syntax)
    if not '.' in bits[1]:
        # variant: widget WIDGET_VAR WIDGETINPAGE_VAR ...
        widget = template.Variable(bits[1])
        widget_in_page = template.Variable(bits[2])
    elif bits[1].count('.') == 1:
        # variant: widget CT_ID.PK PAGE_ID ...
        widget = bits[1].split('.')
        page_id = bits[2]

        try:
            widget = get_object(*widget)
            widget_in_page = widget.widgetinpage_set.get(page=page_id)
        except ObjectDoesNotExist, e:
            raise template.TemplateSyntaxError(
                "invalid id for page or widget's type,pk\n%s" % valid_syntax)
Beispiel #4
0
 def modify_data(self, data=None, config={}):
     rss_widgets = self.config.get("rss-widgets", [])
     items = []
     for ct, pk, count in rss_widgets:
         widget = get_object(ct, pk)
         items.extend(widget.get_data({"item_count": count})["entries"])
     return self.add_categories(items)
Beispiel #5
0
def widget(parser, token):
    '''
    {% widget WIDGET_VAR WIDGETINPAGE_VAR [get_data] %}

    or

    {% widget CT_ID.PK PAGE_ID [get_data] %}
    '''
    valid_syntax = 'valid syntax is: {% widget WIDGET_VAR WIDGETINPAGE_VAR [get_data] %} || {% widget CT_ID.PK PAGE_ID [get_data] %}'

    bits = token.split_contents()
    l = len(bits)

    widget = None
    widget_in_page = None
    get_data = False

    if l < 3:
        raise template.TemplateSyntaxError("too short\n%s" % valid_syntax)
    if not '.' in bits[1]:
        # variant: widget WIDGET_VAR WIDGETINPAGE_VAR ...
        widget = template.Variable(bits[1])
        widget_in_page = template.Variable(bits[2])
    elif bits[1].count('.') == 1:
        # variant: widget CT_ID.PK PAGE_ID ...
        widget = bits[1].split('.')
        page_id = bits[2]

        try:
            widget = get_object(*widget)
            widget_in_page = widget.widgetinpage_set.get(page=page_id)
        except ObjectDoesNotExist, e:
            raise template.TemplateSyntaxError("invalid id for page or widget's type,pk\n%s" % valid_syntax)
Beispiel #6
0
def get_widget_or_404(page, content_type_id, object_id):
    """
    Return a widget using the ct_id and obj_id pair
    """
    try:
        widget = get_object(content_type_id, object_id)
    except ObjectDoesNotExist, e:
        raise http.Http404
Beispiel #7
0
def get_widget_or_404(page, content_type_id, object_id):
    """
    Return a widget using the ct_id and obj_id pair
    """
    try:
        widget = get_object(content_type_id, object_id)
    except ObjectDoesNotExist, e:
        raise http.Http404
Beispiel #8
0
 def modify_data(self, data=None, config={}):
     rss_widgets = self.config.get('rss-widgets', [])
     items = []
     for ct, pk, count in rss_widgets:
         widget = get_object(ct, pk)
         items.extend(widget.get_data({
             'item_count': count,
         })['entries'])
     return self.add_categories(items)
Beispiel #9
0
    def arrange_widgets(self, containers):
        """
        Updates widggets positions in containers

        Widgets can be placed and removed via this method.
        """
        new_containers = []
        for container in containers:
            new_container = Container(self, [])
            for widget_ct_id, widget_id in container:
                try:
                    wil = self.get_widget(widget_ct_id, widget_id)
                except self.WidgetInLayoutDoesNotExist, e:
                    widget = get_object(widget_ct_id, widget_id)  # existence check
                    wil = WidgetInLayout.factory(new_container, widget)
                new_container.append(wil)
            new_containers.append(new_container)
Beispiel #10
0
    def arrange_widgets(self, containers):
        """
        Updates widggets positions in containers

        Widgets can be placed and removed via this method.
        """
        new_containers = []
        for container in containers:
            new_container = Container(self, [])
            for widget_ct_id, widget_id in container:
                try:
                    wil = self.get_widget(widget_ct_id, widget_id)
                except self.WidgetInLayoutDoesNotExist, e:
                    widget = get_object(widget_ct_id,
                                        widget_id)  # existence check
                    wil = WidgetInLayout.factory(new_container, widget)
                new_container.append(wil)
            new_containers.append(new_container)
Beispiel #11
0
def print_layout(page):
    for c in ('containers', 'static_containers'):
        for i, j in enumerate(page.layout[c]):
            print '%s-%d' % (c, i), [repr(get_object(*k)) for k in j]
Beispiel #12
0
 def widget(self):
     return get_object(self.widget_ct_id, self.widget_id)
Beispiel #13
0
def print_layout(page):
    for c in ('containers', 'static_containers'):
        for i,j in enumerate(page.layout[c]):
            print '%s-%d' % (c, i), [repr(get_object(*k)) for k in j]
Beispiel #14
0
 def widget(self):
     return get_object(self.widget_ct_id, self.widget_id)