Commit 07862201 authored by Jitka Novotna's avatar Jitka Novotna

lots of things from context_processors->basic.py

parent 89fb9370
......@@ -83,11 +83,11 @@
<div class="collapse navbar-collapse" id="wl-navbar-main">
<ul class="nav navbar-nav">
<li><a href="{% url 'home' %}">{% trans "Dashboard" %}</a></li>
{% if usertranslations %}
{% if subscribed_projects %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Your translations" %}<b class="caret"></b></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Your subscriptions" %}<b class="caret"></b></a>
<ul class="dropdown-menu">
{% for project in usertranslations %}
{% for project in subscribed_projects %}
<li><a href="{{ project.get_absolute_url }}">{{ project }}</a></li>
{% endfor %}
</ul>
......
......@@ -23,7 +23,6 @@ from datetime import datetime
import weblate
from weblate import appsettings
from weblate.trans.site import get_site_url
from weblate.trans.models.componentlist import ComponentList
from weblate.trans.models.project import Project
from weblate.trans.models.translation import Translation
from weblate.accounts.models import Profile
......@@ -42,48 +41,12 @@ def weblate_context(request):
login_redirect_url = request.get_full_path()
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(
language__in=request.user.profile.languages.all(),
subproject__project__in=subscribed_projects
).order_by(
'subproject__project__name', 'subproject__name'
).select_related()
userlanguages = Translation.objects.filter(
language__in=request.user.profile.languages.all(),
subproject__project__in=projects,
).order_by(
'subproject__project__name', 'subproject__name'
).select_related()
for componentlist in componentlists:
componentlist.translations = Translation.objects.filter(
language__in=request.user.profile.languages.all(),
subproject__in=componentlist.components.all()
).order_by(
'subproject__project__name', 'subproject__name'
).select_related()
return {
'version': weblate.VERSION,
......@@ -113,10 +76,4 @@ def weblate_context(request):
'registration_open': appsettings.REGISTRATION_OPEN,
'acl_projects': projects,
'subscribed_projects': subscribed_projects,
'usersubscriptions': usersubscriptions,
'userlanguages': userlanguages,
'componentlists': componentlists,
'active_tab_slug': active_tab_slug,
'active_tab_label': dashboard_choices.get(active_tab_slug)
}
......@@ -33,7 +33,7 @@ from django.utils import timezone
import django.views.defaults
from weblate.trans.models import (
Project, SubProject, Translation, Check,
Project, SubProject, Translation, Check, ComponentList,
Dictionary, Change, Unit, WhiteboardMessage
)
from weblate.requirements import get_versions, get_optional_versions
......@@ -89,6 +89,45 @@ def home(request):
top_suggestions = Profile.objects.order_by('-suggested')[:10]
last_changes = Change.objects.last_changes(request.user)[:10]
# Dashboard project/subproject view
componentlists = ComponentList.objects.all()
dashboard_choices = dict(Profile.DASHBOARD_CHOICES)
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(
language__in=request.user.profile.languages.all(),
subproject__project__in=subscribed_projects
).order_by(
'subproject__project__name', 'subproject__name'
).select_related()
userlanguages = Translation.objects.filter(
language__in=request.user.profile.languages.all(),
subproject__project__in=projects,
).order_by(
'subproject__project__name', 'subproject__name'
).select_related()
for componentlist in componentlists:
componentlist.translations = Translation.objects.filter(
language__in=request.user.profile.languages.all(),
subproject__in=componentlist.components.all()
).order_by(
'subproject__project__name', 'subproject__name'
).select_related()
return render(
request,
'index.html',
......@@ -100,6 +139,11 @@ def home(request):
'last_changes_url': '',
'search_form': SiteSearchForm(),
'whiteboard_messages': wb_messages,
'usersubscriptions': usersubscriptions,
'userlanguages': userlanguages,
'componentlists': componentlists,
'active_tab_slug': active_tab_slug,
'active_tab_label': dashboard_choices.get(active_tab_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