Hi I am new to Django and working on Pootle project.
I would like to sort by Overall completion by default in the pootle index page. for example, http://pootle.locamotion.org/ lists the languages and sorted by names. you can click sort buttons to see sort by completion. but I would like to show this list sorted by completion whenever load a page.
in pootle/local_apps/pootle_app/templates/index/index.html,
<table class="sortable">
<tr>
<th>{% trans 'Language' %}</th>
<th>{% trans 'Overall Completion' %}</th>
<th>{% trans 'Last Activity' %}</th>
</tr>
{% for item in languages %}
{% ifnotequal item.total 0 %}
<tr class="{% cycle 'even' 'odd' %}">
<td class="language">
<a href="{% filter l %}/{{ item.code }}/{% endfilter %}">{{ item.name }}</a></td>
<td>
<div class="sortkey">{{ item.transper }}</div>
<div class="graph" title="{{ item.completed_title }}" dir="{% if LANGUAGE_BIDI %}rtl{% else %}ltr{% endif %}">
<div class="translated" style="width: {{ item.transper }}px"></div>
{% if item.fuzzy %}
<div class="fuzzy" style="{%if LANGUAGE_BIDI%}right{%else%}left{%endif%}: {{ item.transper }}px; width: {{ item.fuzzyper }}px"></div>
{% endif %}
{% if item.untrans %}
<div class="untranslated" style="{% if LANGUAGE_BIDI %}right{% else %}left{% endif %}: {{ item.transper|add:item.fuzzyper }}px; width: {{ item.untransper }}px"></div>
{% endif %}
</div>
</td>
<td>{{ item.lastactivity }}</td>
</tr>
{% endifnotequal %}
{% endfor %}
</table>
item.transper is the key that I want to sort by.
and this is how item and language is defined:
def get_items(request, model, get_last_action, name_func):
items = []
if not check_permission('view', request):
return items
for item in model.objects.iterator():
stats = item.getquickstats()
stats = add_percentages(stats)
lastact = get_last_action(item)
items.append({
'code': item.code,
'name': name_func(item.fullname),
'lastactivity': lastact,
'trans': stats["translatedsourcewords"],
'fuzzy': stats["fuzzysourcewords"],
'untrans': stats["untranslatedsourcewords"],
'total': stats["totalsourcewords"],
'transper': stats["translatedpercentage"],
'fuzzyper': stats["fuzzypercentage"],
'untransper': stats["untranslatedpercentage"],
'completed_title': _("%(percentage)d%% complete",
{'percentage': stats['translatedpercentage']}),
})
items.sort(lambda x, y: locale.strcoll(x['name'], y['name']))
return items
def getlanguages(request):
def get_last_action(item):
try:
return Submission.objects.filter(translation_project__language=item).latest()
except Submission.DoesNotExist:
return ''
return get_items(request, Language, get_last_action, tr_lang)
what should I change this so that I see sort by Overall Completion by default?
thank you so much for any suggestions