Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing charts #142

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ python-memcached==1.53
django-hitcounter==0.1.1
Pillow==2.2.1
django-i18n-model==0.0.7
pygal==1.2.1

gunicorn==18.0
gevent==0.13.8
Expand Down
12 changes: 8 additions & 4 deletions src/accounts/templates/accounts/user_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


{% block head_js %}
{% include "pizza-chart.html" with chart_data=type_count chart_div="collabs" chart_height=300 %}
{% include "pizza-chart.html" with chart_data=list_activity chart_div="collabs2" chart_height=300 %}
<script type="text/javascript" src="{{ STATIC_URL }}third-party/pygal/js/svg.jquery.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}third-party/pygal/js/pygal-tooltips.js"></script>
{% endblock %}

{% block main-content %}
Expand Down Expand Up @@ -79,7 +79,9 @@ <h1>
<h3 class="panel-title">{% trans "Contributions by Type" %}</h3>
</div>
<div class="panel-body">
<div id="collabs"></div>
<div>
<figure>{{ contributions_chart|safe }}</figure>
</div>
</div>
</div>
</div>
Expand All @@ -91,7 +93,9 @@ <h3 class="panel-title">{% trans "Contributions by Type" %}</h3>
<h3 class="panel-title">{% trans "Participation by Group" %}</h3>
</div>
<div class="panel-body">
<div id="collabs2"></div>
<div>
<figure>{{ list_activity_chart|safe }}</figure>
</div>
</div>
</div>
</div>
Expand Down
18 changes: 16 additions & 2 deletions src/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# encoding: utf-8

import datetime
import pygal

from collections import OrderedDict

Expand All @@ -20,6 +21,7 @@
from conversejs.models import XMPPAccount
from haystack.query import SearchQuerySet

from colab.utils.pygal_render import render_pie_chart
from super_archives.models import EmailAddress, Message
from super_archives.utils.email import send_email_lists
from search.utils import trans
Expand Down Expand Up @@ -89,7 +91,14 @@ def get_context_data(self, **kwargs):
sqs = sqs.filter_or(type=type, **filter_or)
count_types[trans(type)] = sqs.count()

context['type_count'] = count_types
PIE_WIDTH = 350
PIE_HEIGHT = 300
NO_DATA_TEXT = _(u'No data found')

context['contributions_chart'] = render_pie_chart(
count_types, width=PIE_WIDTH, height=PIE_HEIGHT,
no_data_text=NO_DATA_TEXT
)

sqs = SearchQuerySet()
for filter_or in fields_or_lookup:
Expand All @@ -103,10 +112,15 @@ def get_context_data(self, **kwargs):
context['emails'] = query[:10]

count_by = 'thread__mailinglist__name'
context['list_activity'] = dict(messages.values_list(count_by)\
list_activity_count = dict(messages.values_list(count_by)\
.annotate(Count(count_by))\
.order_by(count_by))

context['list_activity_chart'] = render_pie_chart(
list_activity_count, width=PIE_WIDTH, height=PIE_HEIGHT,
no_data_text=NO_DATA_TEXT
)

context.update(kwargs)
return super(UserProfileDetailView, self).get_context_data(**context)

Expand Down
22 changes: 22 additions & 0 deletions src/colab/utils/pygal_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

import pygal

from colab.utils.pygal_style import CustomLightStyle


def render_pie_chart(count_dict, style=CustomLightStyle, width=None,
height=None, no_data_text='', value_font_size=15,
explicit_size=True):

pie_chart = pygal.Pie(style=style, width=width, height=height,
no_data_text=no_data_text,
value_font_size=value_font_size,
explicit_size=explicit_size)

for count in tuple(count_dict.items()):
pie_chart.add(count[0], count[1])

return pie_chart.make_instance(
overrides={'disable_xml_declaration': True}
).render(is_unicode=True)
16 changes: 16 additions & 0 deletions src/colab/utils/pygal_style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-

from pygal.style import Style


CustomLightStyle = Style(
background = 'transparent',
plot_background = 'transparent',
foreground='rgba(0, 0, 0, 0.7)',
foreground_light='rgba(0, 0, 0, 0.9)',
foreground_dark='rgba(0, 0, 0, 0.5)',
colors=('#0f9517', '#3366cc', '#dc3912',
'#ff9900', '#990099', '#22aa99',
'#aaaa11', '#dd4477', '#316395',
'#7A2F16', '#4A0149', '#cccccc')
)
17 changes: 13 additions & 4 deletions src/home/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# -*- coding: utf-8 -*-

import pygal

from collections import OrderedDict

from django.core.cache import cache
from django.shortcuts import render
from django.utils.translation import ugettext as _

from search.utils import trans
from haystack.query import SearchQuerySet

from proxy.models import WikiCollabCount, TicketCollabCount
from super_archives.models import Thread
from colab.utils.pygal_render import render_pie_chart


def index(request):
Expand All @@ -18,8 +23,8 @@ def index(request):
latest_threads = Thread.objects.all()[:6]
hottest_threads = Thread.highest_score.from_haystack()[:6]

count_types = cache.get('home_chart')
if count_types is None:
home_chart = cache.get('home_chart')
if home_chart is None:
count_types = OrderedDict()
for type in ['thread', 'changeset', 'attachment']:
count_types[trans(type)] = SearchQuerySet().filter(
Expand All @@ -33,12 +38,16 @@ def index(request):
count_types[trans('wiki')] = sum([
wiki.count for wiki in WikiCollabCount.objects.all()
])
cache.set('home_chart', count_types)

home_chart = render_pie_chart(count_types, width=500, height=350,
no_data_text=_(u'No data found')
)
cache.set('home_chart', home_chart)

context = {
'hottest_threads': hottest_threads[:6],
'latest_threads': latest_threads,
'type_count': count_types,
'home_chart': home_chart,
'latest_results': SearchQuerySet().all().order_by(
'-modified', '-created'
)[:6],
Expand Down
Binary file modified src/locale/pt_BR/LC_MESSAGES/django.mo
Binary file not shown.
57 changes: 30 additions & 27 deletions src/locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-12-10 16:24+0000\n"
"POT-Creation-Date: 2013-12-13 17:48+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -59,26 +59,30 @@ msgstr ""

#: accounts/models.py:61
msgid "Enter a valid username."
msgstr ""
msgstr "Entre um nome de usuário válido"

#: accounts/views.py:96 home/views.py:43
msgid "No data found"
msgstr "Nenhum dado encontrado"

#: accounts/views.py:144
#: accounts/views.py:158
msgid "Your profile has been created!"
msgstr "Seu perfil foi criado!"

#: accounts/views.py:145
#: accounts/views.py:159
msgid ""
"You must login to validated your profile. Profiles not validated are deleted "
"in 24h."
msgstr ""
"Você deve se logar para validar seu perfil. Perfis não validados serão "
"deletados em 24h."

#: accounts/views.py:226
#: accounts/views.py:240
msgid "Could not change your password. Please, try again later."
msgstr ""
"Não conseguimos alterar sua senha. Por favor, tente novamente mais tarde."

#: accounts/views.py:235
#: accounts/views.py:249
msgid "You've changed your password successfully!"
msgstr "Senha alterada com sucesso!"

Expand Down Expand Up @@ -156,36 +160,36 @@ msgstr "Grupos: "
msgid "Contributions by Type"
msgstr "Contribuições por tipo"

#: accounts/templates/accounts/user_detail.html:91
#: accounts/templates/accounts/user_detail.html:93
msgid "Participation by Group"
msgstr "Participação por grupo"

#: accounts/templates/accounts/user_detail.html:104 badger/models.py:70
#: accounts/templates/accounts/user_detail.html:108 badger/models.py:70
msgid "Badges"
msgstr "Medalhas"

#: accounts/templates/accounts/user_detail.html:123
#: accounts/templates/accounts/user_detail.html:127
msgid "Latest posted"
msgstr "Últimas postagens"

#: accounts/templates/accounts/user_detail.html:128
#: accounts/templates/accounts/user_detail.html:132
msgid "There are no posts by this user so far."
msgstr "Não há posts deste usuário até agora."

#: accounts/templates/accounts/user_detail.html:132 templates/home.html:57
#: templates/home.html.py:76
#: accounts/templates/accounts/user_detail.html:136 templates/home.html:59
#: templates/home.html.py:78
msgid "View more discussions..."
msgstr "Ver mais discussões..."

#: accounts/templates/accounts/user_detail.html:138
#: accounts/templates/accounts/user_detail.html:142
msgid "Other Collaborations"
msgstr "Outras Colaborações"

#: accounts/templates/accounts/user_detail.html:143
#: accounts/templates/accounts/user_detail.html:147
msgid "No contributions of this user so far."
msgstr "Não há posts deste usuário até agora."

#: accounts/templates/accounts/user_detail.html:147
#: accounts/templates/accounts/user_detail.html:151
msgid "View more contributions..."
msgstr "Ver mais colaborações..."

Expand Down Expand Up @@ -279,7 +283,7 @@ msgstr "Imagem"

#: badger/forms.py:30
msgid "You must add an Image"
msgstr ""
msgstr "Você deve adicionar uma imagem"

#: badger/models.py:12
msgid "Greater than or equal"
Expand Down Expand Up @@ -1003,46 +1007,45 @@ msgstr "O conteúdo deste site está publicado sob a licença"
msgid "Creative Commons - attribution, non-commercial"
msgstr "Creative Commons - atribuição e não-comercial"

#: templates/home.html:17
#: templates/home.html:18
msgid "Latest Collaborations"
msgstr "Últimas Colaborações"

#: templates/home.html:21
#: templates/home.html:22
msgid "RSS - Latest collaborations"
msgstr "RSS - Últimas Colaborações"

#: templates/home.html:30
#: templates/home.html:31
msgid "View more collaborations..."
msgstr "Ver mais colaborações..."

#: templates/home.html:37
msgid "Collaboration Graph"
msgstr "Gráfico de Colaborações"

#: templates/home.html:45
#: templates/home.html:47
msgid "Most Relevant Threads"
msgstr "Discussões Mais Relevantes"

#: templates/home.html:49
#: templates/home.html:51
msgid "RSS - Most Relevant Threads"
msgstr "RSS - Discussões Mais Relevantes"

#: templates/home.html:64
#: templates/home.html:66
msgid "Latest Threads"
msgstr "Últimas Discussões"

#: templates/home.html:68
#: templates/home.html:70
msgid "RSS - Latest Threads"
msgstr "RSS - Últimas Discussões"

#: templates/pizza-chart.html:26
msgid "Willing to help"
msgstr "Vontade de ajudar"

#: templates/includes/big_header.html:9
msgid "INTERLEGIS COMMUNITIES"
msgstr "COMUNIDADES INTERLEGIS"

#~ msgid "Willing to help"
#~ msgstr "Vontade de ajudar"

#~ msgid "Community Blogs"
#~ msgstr "Blogs da comunidade"

Expand Down
Loading