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)
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)
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)
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)
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
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)
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)
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]
def widget(self): return get_object(self.widget_ct_id, self.widget_id)
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]