Commit 3a0e7f7f authored by Jitka Novotna's avatar Jitka Novotna

id instead slug in database

parent 1ecae4e5
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0014_dashboard_settings'),
]
operations = [
migrations.AlterField(
model_name='profile',
name='dashboard_view',
field=models.IntegerField(default=1, verbose_name='Default dashboard view', choices=[(1, 'Your subscriptions'), (2, 'Your languages'), (3, 'All projects'), (4, 'Component list')]),
),
migrations.AlterField(
model_name='profile',
name='secondary_languages',
field=models.ManyToManyField(help_text='Choose languages you can understand, strings in those languages will be shown in addition to the source string.', related_name='secondary_profile_set', verbose_name='Secondary languages', to='lang.Language', blank=True),
),
]
......@@ -500,18 +500,30 @@ class Profile(models.Model):
default=False
)
DASHBOARD_SUBSCRIPTIONS = "your-subscriptions"
DASHBOARD_LANGUAGES = "your-languages"
DASHBOARD_ALL = "projects"
DASHBOARD_COMPONENT_LIST = "list"
DASHBOARD_SUBSCRIPTIONS = 1
DASHBOARD_LANGUAGES = 2
DASHBOARD_ALL = 3
DASHBOARD_COMPONENT_LIST = 4
DASHBOARD_CHOICES = (
(DASHBOARD_SUBSCRIPTIONS, _('Your subscriptions')),
(DASHBOARD_LANGUAGES, _('Your languages')),
(DASHBOARD_ALL, _('All projects')),
(DASHBOARD_COMPONENT_LIST, _('Component list')),
)
dashboard_view = models.CharField(
max_length=100,
DASHBOARD_SLUGS = {
DASHBOARD_SUBSCRIPTIONS: 'your-subscriptions',
DASHBOARD_LANGUAGES: 'your-languages',
DASHBOARD_ALL: 'projects',
DASHBOARD_COMPONENT_LIST: 'list',
}
DASHBOARD_SLUGMAP = {
d[1]: d[0] for d in DASHBOARD_SLUGS.items()
}
dashboard_view = models.IntegerField(
choices=DASHBOARD_CHOICES,
verbose_name=_('Default dashboard view'),
default=DASHBOARD_SUBSCRIPTIONS,
......
......@@ -92,17 +92,20 @@ def home(request):
# Dashboard project/subproject view
componentlists = ComponentList.objects.all()
# dashboard_choices is dict with labels of choices as a keys
dashboard_choices = dict(Profile.DASHBOARD_CHOICES)
usersubscriptions = None
userlanguages = None
active_tab_slug = Profile.DASHBOARD_ALL
active_tab_id = Profile.DASHBOARD_ALL
active_tab_slug = Profile.DASHBOARD_SLUGS.get(active_tab_id)
if request.user.is_authenticated():
active_tab_slug = request.user.profile.dashboard_view
if active_tab_slug == Profile.DASHBOARD_COMPONENT_LIST:
active_tab_id = request.user.profile.dashboard_view
active_tab_slug = Profile.DASHBOARD_SLUGS.get(active_tab_id)
if active_tab_id == Profile.DASHBOARD_COMPONENT_LIST:
clist = request.user.profile.dashboard_component_list
active_tab_slug = clist.tab_slug()
dashboard_choices[active_tab_slug] = clist.name
dashboard_choices[active_tab_id] = clist.name
subscribed_projects = request.user.profile.subscriptions.all()
......@@ -136,7 +139,7 @@ def home(request):
'userlanguages': userlanguages,
'componentlists': componentlists,
'active_tab_slug': active_tab_slug,
'active_tab_label': dashboard_choices.get(active_tab_slug)
'active_tab_label': dashboard_choices.get(active_tab_id)
}
)
......
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