Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.
Open
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
8 changes: 7 additions & 1 deletion osmtm/templates/home.mako
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ sorts = [('priority', 'asc', _('High priority first')),
<%
import markdown
import bleach
from sqlalchemy.orm import joinedload
from osmtm.models import DBSession, Project, ProjectTranslation

priority = priorities[project.priority]
project = DBSession.query(Project).\
options(joinedload(Project.translations[request.locale_name])).\
filter(Project.id == project.id).first()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.get(project.id) isn’t used here cause it causes to be loaded from the Session and not from database, ending in translations not loaded.

if request.locale_name:
project.locale = request.locale_name
priority = priorities[project.priority]

if project.status == project.status_archived:
status = 'Archived'
Expand Down
19 changes: 6 additions & 13 deletions osmtm/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
or_,
and_,
)
from sqlalchemy.orm import joinedload

from ..models import (
DBSession,
Expand All @@ -29,6 +30,7 @@

@view_config(route_name='home', renderer='home.mako')
def home(request):

check_task_expiration()
check_project_expiration()

Expand Down Expand Up @@ -63,22 +65,13 @@ def home(request):
search_filter = or_(PT.name.ilike('%%%s%%' % s),
PT.short_description.ilike('%%%s%%' % s),
PT.description.ilike('%%%s%%' % s),)
ids = DBSession.query(ProjectTranslation.id) \
.filter(search_filter) \
.all()
filter = and_(Project.id.in_(ids), filter)
query.options(joinedload(Project.translations))
filter = and_(filter, search_filter)

# filter projects on which the current user worked on
if request.params.get('my_projects', '') == 'on':
ids = DBSession.query(TaskLock.project_id) \
.filter(TaskLock.user_id == user_id) \
.all()

if len(ids) > 0:
filter = and_(Project.id.in_(ids), filter)
else:
# IN-predicate with emty sequence can be expensive
filter = and_(False == True) # noqa
query.join(TaskLock, Project.id==TaskLock.project_id)
filter = and_(filter, TaskLock.user_id==user_id)

sort_by = 'project.%s' % request.params.get('sort_by', 'priority')
direction = request.params.get('direction', 'asc')
Expand Down