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): ...@@ -496,17 +496,18 @@ class Profile(models.Model):
default=False default=False
) )
DASHBOARD_SUBSCRIPTIONS = 0 DASHBOARD_SUBSCRIPTIONS = "your-subscriptions"
DASHBOARD_LANGUAGES = 1 DASHBOARD_LANGUAGES = "your-languages"
DASHBOARD_ALL = 2 DASHBOARD_ALL = "projects"
DASHBOARD_COMPONENT_LIST = 3 DASHBOARD_COMPONENT_LIST = "list"
DASHBOARD_CHOICES = ( DASHBOARD_CHOICES = (
(DASHBOARD_SUBSCRIPTIONS, _('Your subscriptions')), (DASHBOARD_SUBSCRIPTIONS, _('Your subscriptions')),
(DASHBOARD_LANGUAGES, _('Your languages')), (DASHBOARD_LANGUAGES, _('Your languages')),
(DASHBOARD_ALL, _('All projects')), (DASHBOARD_ALL, _('All projects')),
(DASHBOARD_COMPONENT_LIST, _('Component list')), (DASHBOARD_COMPONENT_LIST, _('Component list')),
) )
dashboard_view = models.IntegerField( dashboard_view = models.CharField(
max_length = 100,
choices=DASHBOARD_CHOICES, choices=DASHBOARD_CHOICES,
verbose_name=_('Default dashboard view'), verbose_name=_('Default dashboard view'),
default=DASHBOARD_SUBSCRIPTIONS, default=DASHBOARD_SUBSCRIPTIONS,
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<li class="dropdown active"> <li class="dropdown active">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" id="views-title"> <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> </a>
<ul class="dropdown-menu" id="views-menu"> <ul class="dropdown-menu" id="views-menu">
<li><a href="#projects" data-toggle="tab">{% trans "All projects" %}</a></li> <li><a href="#projects" data-toggle="tab">{% trans "All projects" %}</a></li>
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<li><a href="#your-subscriptions" data-toggle="tab">{% trans "Your subscriptions" %}</a></li> <li><a href="#your-subscriptions" data-toggle="tab">{% trans "Your subscriptions" %}</a></li>
{% endif %} {% endif %}
{% for componentlist in componentlists %} {% 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 %} {% endfor %}
</ul> </ul>
</li> </li>
...@@ -62,7 +62,7 @@ $("#views-menu li a").click(function(){ ...@@ -62,7 +62,7 @@ $("#views-menu li a").click(function(){
<div class="tab-content"> <div class="tab-content">
{% if user.is_authenticated %} {% if user.is_authenticated %}
<div class="tab-pane active" id="your-subscriptions"> <div {% active_tab "your-subscriptions" %}>
{% if subscribed_projects %} {% if subscribed_projects %}
{% if usersubscriptions %} {% if usersubscriptions %}
{% with usersubscriptions as translations and 2 as show_language and user.profile.hide_completed as hide_completed %} {% 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(){ ...@@ -82,7 +82,7 @@ $("#views-menu li a").click(function(){
</p> </p>
</div> </div>
<div class="tab-pane" id="your-languages"> <div {% active_tab "your-languages" %}>
{% if userlanguages %} {% if userlanguages %}
{% with userlanguages as translations and 2 as show_language and user.profile.hide_completed as hide_completed %} {% with userlanguages as translations and 2 as show_language and user.profile.hide_completed as hide_completed %}
{% include "list-translations.html" %} {% include "list-translations.html" %}
...@@ -92,27 +92,20 @@ $("#views-menu li a").click(function(){ ...@@ -92,27 +92,20 @@ $("#views-menu li a").click(function(){
{% endif %} {# userlanguages #} {% endif %} {# userlanguages #}
<p><a class="btn btn-default" href="{% url 'profile' %}#languages">{% trans "Manage your languages" %}</a></p> <p><a class="btn btn-default" href="{% url 'profile' %}#languages">{% trans "Manage your languages" %}</a></p>
</div> </div>
<div class="tab-pane" id="projects">
{% else %} {# user.is_authenticated #}
<div class="tab-pane active" id="projects">
{% endif %} {# user.is_authenticated #} {% endif %} {# user.is_authenticated #}
{# All projects#}
<div {% active_tab "projects" %}>
{% include "list-projects.html" %} {% include "list-projects.html" %}
<p>{% include "legend.html" %}</p>
<p>
{% include "legend.html" %}
</p>
{% if offer_hosting %} {% if offer_hosting %}
<p><a class="btn btn-default" href="{% url 'hosting' %}">{% trans "Ask for project hosting" %}</a> <p><a class="btn btn-default" href="{% url 'hosting' %}">{% trans "Ask for project hosting" %}</a>
{% endif %} {% endif %}
</div> </div>
{% for componentlist in componentlists %} {% for componentlist in componentlists %}
<div class="tab-pane" id="list-{{componentlist.slug}}"> <div {% active_tab componentlist.tab_slug %}>
{% if userlanguages %} {% if userlanguages %}
{% with userlanguages as translations and 2 as show_language and user.profile.hide_completed as hide_completed %} {% with userlanguages as translations and 2 as show_language and user.profile.hide_completed as hide_completed %}
{% include "list-translations.html" %} {% include "list-translations.html" %}
......
...@@ -44,12 +44,21 @@ def weblate_context(request): ...@@ -44,12 +44,21 @@ def weblate_context(request):
projects = Project.objects.all_acl(request.user) projects = Project.objects.all_acl(request.user)
componentlists = ComponentList.objects.all() componentlists = ComponentList.objects.all()
dashboard_choices = dict(Profile.DASHBOARD_CHOICES)
# Load user translations if user is authenticated # Load user translations if user is authenticated
subscribed_projects = None subscribed_projects = None
usersubscriptions = None usersubscriptions = None
userlanguages = None userlanguages = None
active_tab_slug = Profile.DASHBOARD_ALL
if request.user.is_authenticated(): 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() subscribed_projects = request.user.profile.subscriptions.all()
usersubscriptions = Translation.objects.filter( usersubscriptions = Translation.objects.filter(
...@@ -101,5 +110,6 @@ def weblate_context(request): ...@@ -101,5 +110,6 @@ def weblate_context(request):
'userlanguages': userlanguages, 'userlanguages': userlanguages,
'componentlists': componentlists, '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): ...@@ -45,6 +45,9 @@ class ComponentList(models.Model):
components = models.ManyToManyField('SubProject') components = models.ManyToManyField('SubProject')
def tab_slug(self):
return "list-" + self.slug
def clean(self): def clean(self):
if not self.name: if not self.name:
raise ValidationError(_('Name must be specified')) raise ValidationError(_('Name must be specified'))
......
...@@ -610,3 +610,8 @@ def whiteboard_messages(project=None, subproject=None, language=None): ...@@ -610,3 +610,8 @@ def whiteboard_messages(project=None, subproject=None, language=None):
) )
return mark_safe('\n'.join(ret)) 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