Commit 09ba0ac4 authored by Jitka Novotna's avatar Jitka Novotna

commponent list as default

parent a639cb48
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0015_auto_20160208_1535'),
]
operations = [
migrations.AlterField(
model_name='profile',
name='dashboard_view',
field=models.CharField(default='your-subscriptions', max_length=100, verbose_name='Default dashboard view', choices=[('your-subscriptions', 'Your subscriptions'), ('your-languages', 'Your languages'), ('projects', 'All projects'), ('list', 'Component list')]),
),
]
......@@ -496,17 +496,18 @@ class Profile(models.Model):
default=False
)
DASHBOARD_SUBSCRIPTIONS = 0
DASHBOARD_LANGUAGES = 1
DASHBOARD_ALL = 2
DASHBOARD_COMPONENT_LIST = 3
DASHBOARD_SUBSCRIPTIONS = "your-subscriptions"
DASHBOARD_LANGUAGES = "your-languages"
DASHBOARD_ALL = "projects"
DASHBOARD_COMPONENT_LIST = "list"
DASHBOARD_CHOICES = (
(DASHBOARD_SUBSCRIPTIONS, _('Your subscriptions')),
(DASHBOARD_LANGUAGES, _('Your languages')),
(DASHBOARD_ALL, _('All projects')),
(DASHBOARD_COMPONENT_LIST, _('Component list')),
)
dashboard_view = models.IntegerField(
dashboard_view = models.CharField(
max_length = 100,
choices=DASHBOARD_CHOICES,
verbose_name=_('Default dashboard view'),
default=DASHBOARD_SUBSCRIPTIONS,
......
......@@ -22,7 +22,7 @@
<ul class="nav nav-pills">
<li class="dropdown active">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" id="views-title">
{{dashboard_default_view}}<span class="caret"></span>
{{active_tab_label}} <span class="caret"></span>
</a>
<ul class="dropdown-menu" id="views-menu">
<li><a href="#projects" data-toggle="tab">{% trans "All projects" %}</a></li>
......@@ -31,7 +31,7 @@
<li><a href="#your-subscriptions" data-toggle="tab">{% trans "Your subscriptions" %}</a></li>
{% endif %}
{% for componentlist in componentlists %}
<li><a href="#list-{{ componentlist.slug }}" data-toggle="tab">{{ componentlist.name }}</a></li>
<li><a href="#{{ componentlist.tab_slug }}" data-toggle="tab">{{ componentlist.name }}</a></li>
{% endfor %}
</ul>
</li>
......@@ -62,7 +62,7 @@ $("#views-menu li a").click(function(){
<div class="tab-content">
{% if user.is_authenticated %}
<div class="tab-pane active" id="your-subscriptions">
<div {% active_tab "your-subscriptions" %}>
{% if subscribed_projects %}
{% if usersubscriptions %}
{% with usersubscriptions as translations and 2 as show_language and user.profile.hide_completed as hide_completed %}
......@@ -82,7 +82,7 @@ $("#views-menu li a").click(function(){
</p>
</div>
<div class="tab-pane" id="your-languages">
<div {% active_tab "your-languages" %}>
{% if userlanguages %}
{% with userlanguages as translations and 2 as show_language and user.profile.hide_completed as hide_completed %}
{% include "list-translations.html" %}
......@@ -92,27 +92,20 @@ $("#views-menu li a").click(function(){
{% endif %} {# userlanguages #}
<p><a class="btn btn-default" href="{% url 'profile' %}#languages">{% trans "Manage your languages" %}</a></p>
</div>
<div class="tab-pane" id="projects">
{% else %} {# user.is_authenticated #}
<div class="tab-pane active" id="projects">
{% endif %} {# user.is_authenticated #}
{# All projects#}
<div {% active_tab "projects" %}>
{% include "list-projects.html" %}
<p>
{% include "legend.html" %}
</p>
<p>{% include "legend.html" %}</p>
{% if offer_hosting %}
<p><a class="btn btn-default" href="{% url 'hosting' %}">{% trans "Ask for project hosting" %}</a>
{% endif %}
</div>
{% for componentlist in componentlists %}
<div class="tab-pane" id="list-{{componentlist.slug}}">
<div {% active_tab componentlist.tab_slug %}>
{% if userlanguages %}
{% with userlanguages as translations and 2 as show_language and user.profile.hide_completed as hide_completed %}
{% include "list-translations.html" %}
......
......@@ -44,12 +44,21 @@ def weblate_context(request):
projects = Project.objects.all_acl(request.user)
componentlists = ComponentList.objects.all()
dashboard_choices = dict(Profile.DASHBOARD_CHOICES)
# Load user translations if user is authenticated
subscribed_projects = None
usersubscriptions = None
userlanguages = None
active_tab_slug = Profile.DASHBOARD_ALL
if request.user.is_authenticated():
active_tab_slug = request.user.profile.dashboard_view
if active_tab_slug == Profile.DASHBOARD_COMPONENT_LIST:
clist = request.user.profile.dashboard_component_list
active_tab_slug = clist.tab_slug()
dashboard_choices[active_tab_slug] = clist.name
subscribed_projects = request.user.profile.subscriptions.all()
usersubscriptions = Translation.objects.filter(
......@@ -101,5 +110,6 @@ def weblate_context(request):
'userlanguages': userlanguages,
'componentlists': componentlists,
'dashboard_default_view': dict(Profile.DASHBOARD_CHOICES)[request.user.profile.dashboard_view],
'active_tab_slug': active_tab_slug,
'active_tab_label': dashboard_choices.get(active_tab_slug)
}
......@@ -45,6 +45,9 @@ class ComponentList(models.Model):
components = models.ManyToManyField('SubProject')
def tab_slug(self):
return "list-" + self.slug
def clean(self):
if not self.name:
raise ValidationError(_('Name must be specified'))
......
......@@ -610,3 +610,8 @@ def whiteboard_messages(project=None, subproject=None, language=None):
)
return mark_safe('\n'.join(ret))
@register.simple_tag(takes_context=True)
def active_tab(context, slug):
active = "active" if slug==context['active_tab_slug'] else ""
return mark_safe('class="tab-pane %s" id="%s"' %(active,slug))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment