Skip to content

Commit

Permalink
Created import_widgets templatetag
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
macartur committed Nov 10, 2015
1 parent b9889d3 commit efa3fe4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
13 changes: 9 additions & 4 deletions colab/accounts/templates/accounts/user_update_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% extends "base.html" %}
{% load i18n gravatar plugins %}
{% load i18n gravatar plugins widgets_tag %}

{% block html %}
{% import_widgets 'profile' %}
{{ block.super }}
{% endblock %}

{% block head_js %}
<script>
Expand Down Expand Up @@ -105,7 +110,7 @@
{% block head %}
{{ block.super }}

{% for widget in widgets %}
{% for widget in widgets_profile %}
{{ widget.get_header }}
{% endfor %}

Expand All @@ -129,7 +134,7 @@ <h3>{% gravatar user_.email 50 %} {{ user_.get_full_name }} ({{ user_.username }
<!-- Start of navs -->
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="pill" href="#profile">Profile</a></li>
{% for widget in widgets %}
{% for widget in widgets_profile %}
<li>
<a data-toggle="pill" href="#{{ widget.identifier }}">{{ widget.name }}</a>
</li>
Expand Down Expand Up @@ -229,7 +234,7 @@ <h3 class="panel-title">
</div>
</form>
</div>
{% for widget in widgets %}
{% for widget in widgets_profile %}
<div id="{{ widget.identifier }}" class="tab-pane fade">
<h2>{{ widget.name }}</h2>
{{ widget.get_body }}
Expand Down
7 changes: 0 additions & 7 deletions colab/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
EmailAddressValidation)
from colab.search.utils import get_collaboration_data, get_visible_threads
from colab.accounts.models import User
from colab.widgets.widget_manager import WidgetManager

from .forms import (UserCreationForm, ListsForm, UserUpdateForm)
from .utils import mailman
Expand Down Expand Up @@ -43,12 +42,6 @@ def get_object(self, *args, **kwargs):

return obj

def get_context_data(self, **kwargs):
context = {}
context['widgets'] = WidgetManager.get_widgets('profile', self.request)
context.update(kwargs)
return super(UserProfileUpdateView, self).get_context_data(**context)


class UserProfileDetailView(UserProfileBaseMixin, DetailView):
template_name = 'accounts/user_detail.html'
Expand Down
Empty file.
1 change: 1 addition & 0 deletions colab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'colab',
'colab.home',
'colab.plugins',
'colab.widgets',
'colab.super_archives',
'colab.rss',
'colab.search',
Expand Down
2 changes: 2 additions & 0 deletions colab/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load i18n gravatar plugins %}
{% load static from staticfiles %}

{% block html %}
<html>
<head>
{% block head %}
Expand Down Expand Up @@ -101,3 +102,4 @@
{% block footer_js %}{% endblock %}
</body>
</html>
{% endblock %}
Empty file.
14 changes: 14 additions & 0 deletions colab/widgets/templatetags/widgets_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import template
from colab.widgets.widget_manager import WidgetManager


register = template.Library()


@register.simple_tag(takes_context=True)
def import_widgets(context, area_id, widget_var=None):
if not widget_var:
widget_var = "widgets_{}".format(area_id)
context[widget_var] = WidgetManager.get_widgets(area_id,
context['request'])
return ""

0 comments on commit efa3fe4

Please sign in to comment.