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 {% extends "base.html" %} 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 {% block head_js %} 9 {% block head_js %}
5 <script> 10 <script>
@@ -105,7 +110,7 @@ $(function() { @@ -105,7 +110,7 @@ $(function() {
105 {% block head %} 110 {% block head %}
106 {{ block.super }} 111 {{ block.super }}
107 112
108 - {% for widget in widgets %} 113 + {% for widget in widgets_profile %}
109 {{ widget.get_header }} 114 {{ widget.get_header }}
110 {% endfor %} 115 {% endfor %}
111 116
@@ -129,7 +134,7 @@ $(function() { @@ -129,7 +134,7 @@ $(function() {
129 <!-- Start of navs --> 134 <!-- Start of navs -->
130 <ul class="nav nav-tabs"> 135 <ul class="nav nav-tabs">
131 <li class="active"><a data-toggle="pill" href="#profile">Profile</a></li> 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 <li> 138 <li>
134 <a data-toggle="pill" href="#{{ widget.identifier }}">{{ widget.name }}</a> 139 <a data-toggle="pill" href="#{{ widget.identifier }}">{{ widget.name }}</a>
135 </li> 140 </li>
@@ -229,7 +234,7 @@ $(function() { @@ -229,7 +234,7 @@ $(function() {
229 </div> 234 </div>
230 </form> 235 </form>
231 </div> 236 </div>
232 - {% for widget in widgets %} 237 + {% for widget in widgets_profile %}
233 <div id="{{ widget.identifier }}" class="tab-pane fade"> 238 <div id="{{ widget.identifier }}" class="tab-pane fade">
234 <h2>{{ widget.name }}</h2> 239 <h2>{{ widget.name }}</h2>
235 {{ widget.get_body }} 240 {{ widget.get_body }}
colab/accounts/views.py
@@ -15,7 +15,6 @@ from colab.super_archives.models import (EmailAddress, @@ -15,7 +15,6 @@ from colab.super_archives.models import (EmailAddress,
15 EmailAddressValidation) 15 EmailAddressValidation)
16 from colab.search.utils import get_collaboration_data, get_visible_threads 16 from colab.search.utils import get_collaboration_data, get_visible_threads
17 from colab.accounts.models import User 17 from colab.accounts.models import User
18 -from colab.widgets.widget_manager import WidgetManager  
19 18
20 from .forms import (UserCreationForm, ListsForm, UserUpdateForm) 19 from .forms import (UserCreationForm, ListsForm, UserUpdateForm)
21 from .utils import mailman 20 from .utils import mailman
@@ -43,12 +42,6 @@ class UserProfileUpdateView(UserProfileBaseMixin, UpdateView): @@ -43,12 +42,6 @@ class UserProfileUpdateView(UserProfileBaseMixin, UpdateView):
43 42
44 return obj 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 class UserProfileDetailView(UserProfileBaseMixin, DetailView): 46 class UserProfileDetailView(UserProfileBaseMixin, DetailView):
54 template_name = 'accounts/user_detail.html' 47 template_name = 'accounts/user_detail.html'
colab/accounts/widgets/__init__.py 0 → 100644
colab/settings.py
@@ -53,6 +53,7 @@ INSTALLED_APPS = ( @@ -53,6 +53,7 @@ INSTALLED_APPS = (
53 'colab', 53 'colab',
54 'colab.home', 54 'colab.home',
55 'colab.plugins', 55 'colab.plugins',
  56 + 'colab.widgets',
56 'colab.super_archives', 57 'colab.super_archives',
57 'colab.rss', 58 'colab.rss',
58 'colab.search', 59 'colab.search',
colab/templates/base.html
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 {% load i18n gravatar plugins %} 2 {% load i18n gravatar plugins %}
3 {% load static from staticfiles %} 3 {% load static from staticfiles %}
4 4
  5 +{% block html %}
5 <html> 6 <html>
6 <head> 7 <head>
7 {% block head %} 8 {% block head %}
@@ -101,3 +102,4 @@ @@ -101,3 +102,4 @@
101 {% block footer_js %}{% endblock %} 102 {% block footer_js %}{% endblock %}
102 </body> 103 </body>
103 </html> 104 </html>
  105 +{% endblock %}
colab/widgets/templatetags/__init__.py 0 → 100644
colab/widgets/templatetags/widgets_tag.py 0 → 100644
@@ -0,0 +1,14 @@ @@ -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 ""