Commit 9787e097722b2a87f0ba1cdc946a0f225c2bd9f3
1 parent
0df355e5
Exists in
master
and in
4 other branches
Fixed kwargs and added template render
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
2 changed files
with
9 additions
and
3 deletions
Show diff stats
colab/widgets/templatetags/widgets_tag.py
| 1 | from django import template | 1 | from django import template |
| 2 | from colab.widgets.widget_manager import WidgetManager | 2 | from colab.widgets.widget_manager import WidgetManager |
| 3 | +from django.template import Template | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | register = template.Library() | 6 | register = template.Library() |
| @@ -9,5 +10,10 @@ register = template.Library() | @@ -9,5 +10,10 @@ register = template.Library() | ||
| 9 | def import_widgets(context, area_id, widget_var=None): | 10 | def import_widgets(context, area_id, widget_var=None): |
| 10 | if not widget_var: | 11 | if not widget_var: |
| 11 | widget_var = "widgets_{}".format(area_id) | 12 | widget_var = "widgets_{}".format(area_id) |
| 13 | + | ||
| 12 | context[widget_var] = WidgetManager.get_widgets(area_id, context=context) | 14 | context[widget_var] = WidgetManager.get_widgets(area_id, context=context) |
| 15 | + | ||
| 16 | + for widget in context[widget_var]: | ||
| 17 | + widget.content = Template(widget.content).render(context) | ||
| 18 | + | ||
| 13 | return "" | 19 | return "" |
colab/widgets/widget_manager.py
| @@ -28,7 +28,7 @@ class Widget(object): | @@ -28,7 +28,7 @@ class Widget(object): | ||
| 28 | head = self.content[start + len('<head>'):end] | 28 | head = self.content[start + len('<head>'):end] |
| 29 | return mark_safe(head) | 29 | return mark_safe(head) |
| 30 | 30 | ||
| 31 | - def generate_content(self, **kwarg): | 31 | + def generate_content(self, **kwargs): |
| 32 | self.content = '' | 32 | self.content = '' |
| 33 | 33 | ||
| 34 | 34 | ||
| @@ -50,11 +50,11 @@ class WidgetManager(object): | @@ -50,11 +50,11 @@ class WidgetManager(object): | ||
| 50 | WidgetManager.widget_categories[category].remove(widget) | 50 | WidgetManager.widget_categories[category].remove(widget) |
| 51 | 51 | ||
| 52 | @staticmethod | 52 | @staticmethod |
| 53 | - def get_widgets(category, **kargs): | 53 | + def get_widgets(category, **kwargs): |
| 54 | if category not in WidgetManager.widget_categories: | 54 | if category not in WidgetManager.widget_categories: |
| 55 | return [] | 55 | return [] |
| 56 | 56 | ||
| 57 | widgets = WidgetManager.widget_categories[category][:] | 57 | widgets = WidgetManager.widget_categories[category][:] |
| 58 | for widget in widgets: | 58 | for widget in widgets: |
| 59 | - widget.generate_content(**kargs) | 59 | + widget.generate_content(**kwargs) |
| 60 | return widgets | 60 | return widgets |