Commit ac15cbd2ccb40a7f07e70d74805775a2e337caff

Authored by Macartur Sousa
1 parent 7397ed19

Created import_widgets templatetag

- The template tag inserts the widgtes from an area in the html context

Signed-off-by: Luiz Oliveira <ziuloliveira@gmail.com>
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Signed-off-by: Matheus Faria <matheus.sousa.faria@gmail.com>
colab/accounts/templates/accounts/user_update_form.html
1 1 {% extends "base.html" %}
2   -{% load i18n gravatar plugins %}
  2 +{% load i18n gravatar plugins widgets_tag %}
  3 +
  4 +{% block html %}
  5 + {% import_widgets 'profile' %}
  6 + {{ block.super }}
  7 +{% endblock %}
3 8  
4 9 {% block head_js %}
5 10 <script>
... ... @@ -105,7 +110,7 @@ $(function() {
105 110 {% block head %}
106 111 {{ block.super }}
107 112  
108   - {% for widget in widgets %}
  113 + {% for widget in widgets_profile %}
109 114 {{ widget.get_header }}
110 115 {% endfor %}
111 116  
... ... @@ -129,7 +134,7 @@ $(function() {
129 134 <!-- Start of navs -->
130 135 <ul class="nav nav-tabs">
131 136 <li class="active"><a data-toggle="pill" href="#profile">Profile</a></li>
132   - {% for widget in widgets %}
  137 + {% for widget in widgets_profile %}
133 138 <li>
134 139 <a data-toggle="pill" href="#{{ widget.identifier }}">{{ widget.name }}</a>
135 140 </li>
... ... @@ -229,7 +234,7 @@ $(function() {
229 234 </div>
230 235 </form>
231 236 </div>
232   - {% for widget in widgets %}
  237 + {% for widget in widgets_profile %}
233 238 <div id="{{ widget.identifier }}" class="tab-pane fade">
234 239 <h2>{{ widget.name }}</h2>
235 240 {{ widget.get_body }}
... ...
colab/accounts/views.py
... ... @@ -15,7 +15,6 @@ from colab.super_archives.models import (EmailAddress,
15 15 EmailAddressValidation)
16 16 from colab.search.utils import get_collaboration_data, get_visible_threads
17 17 from colab.accounts.models import User
18   -from colab.widgets.widget_manager import WidgetManager
19 18  
20 19 from .forms import (UserCreationForm, ListsForm, UserUpdateForm)
21 20 from .utils import mailman
... ... @@ -43,12 +42,6 @@ class UserProfileUpdateView(UserProfileBaseMixin, UpdateView):
43 42  
44 43 return obj
45 44  
46   - def get_context_data(self, **kwargs):
47   - context = {}
48   - context['widgets'] = WidgetManager.get_widgets('profile', self.request)
49   - context.update(kwargs)
50   - return super(UserProfileUpdateView, self).get_context_data(**context)
51   -
52 45  
53 46 class UserProfileDetailView(UserProfileBaseMixin, DetailView):
54 47 template_name = 'accounts/user_detail.html'
... ...
colab/accounts/widgets/__init__.py 0 → 100644
colab/settings.py
... ... @@ -53,6 +53,7 @@ INSTALLED_APPS = (
53 53 'colab',
54 54 'colab.home',
55 55 'colab.plugins',
  56 + 'colab.widgets',
56 57 'colab.super_archives',
57 58 'colab.rss',
58 59 'colab.search',
... ...
colab/templates/base.html
... ... @@ -2,6 +2,7 @@
2 2 {% load i18n gravatar plugins %}
3 3 {% load static from staticfiles %}
4 4  
  5 +{% block html %}
5 6 <html>
6 7 <head>
7 8 {% block head %}
... ... @@ -101,3 +102,4 @@
101 102 {% block footer_js %}{% endblock %}
102 103 </body>
103 104 </html>
  105 +{% endblock %}
... ...
colab/widgets/templatetags/__init__.py 0 → 100644
colab/widgets/templatetags/widgets_tag.py 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +from django import template
  2 +from colab.widgets.widget_manager import WidgetManager
  3 +
  4 +
  5 +register = template.Library()
  6 +
  7 +
  8 +@register.simple_tag(takes_context=True)
  9 +def import_widgets(context, area_id, widget_var=None):
  10 + if not widget_var:
  11 + widget_var = "widgets_{}".format(area_id)
  12 + context[widget_var] = WidgetManager.get_widgets(area_id,
  13 + context['request'])
  14 + return ""
... ...