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 | 1 | from django import template |
| 2 | 2 | from colab.widgets.widget_manager import WidgetManager |
| 3 | +from django.template import Template | |
| 3 | 4 | |
| 4 | 5 | |
| 5 | 6 | register = template.Library() |
| ... | ... | @@ -9,5 +10,10 @@ register = template.Library() |
| 9 | 10 | def import_widgets(context, area_id, widget_var=None): |
| 10 | 11 | if not widget_var: |
| 11 | 12 | widget_var = "widgets_{}".format(area_id) |
| 13 | + | |
| 12 | 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 | 19 | return "" | ... | ... |
colab/widgets/widget_manager.py
| ... | ... | @@ -28,7 +28,7 @@ class Widget(object): |
| 28 | 28 | head = self.content[start + len('<head>'):end] |
| 29 | 29 | return mark_safe(head) |
| 30 | 30 | |
| 31 | - def generate_content(self, **kwarg): | |
| 31 | + def generate_content(self, **kwargs): | |
| 32 | 32 | self.content = '' |
| 33 | 33 | |
| 34 | 34 | |
| ... | ... | @@ -50,11 +50,11 @@ class WidgetManager(object): |
| 50 | 50 | WidgetManager.widget_categories[category].remove(widget) |
| 51 | 51 | |
| 52 | 52 | @staticmethod |
| 53 | - def get_widgets(category, **kargs): | |
| 53 | + def get_widgets(category, **kwargs): | |
| 54 | 54 | if category not in WidgetManager.widget_categories: |
| 55 | 55 | return [] |
| 56 | 56 | |
| 57 | 57 | widgets = WidgetManager.widget_categories[category][:] |
| 58 | 58 | for widget in widgets: |
| 59 | - widget.generate_content(**kargs) | |
| 59 | + widget.generate_content(**kwargs) | |
| 60 | 60 | return widgets | ... | ... |