如何在 Pootle 中按总体完成情况显示排序列表
您好,我是 Django 新手,正在从事 Pootle 项目。
我想在 pootle 索引页面中默认按总体完成度排序。 例如,http://pootle.locamotion.org/ 列出语言并按名称排序。您可以单击排序按钮来查看按完成程度排序。但我想在加载页面时显示按完成排序的列表。
在 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 是我想要排序的键。
这就是项目和语言的定义方式:
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)
我应该如何更改此设置,以便默认情况下按整体完成度排序?
非常感谢你的任何建议
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改
为
(这与内置
cmp
函数配合良好,因为transper
字段由nice_percentage
函数,即作为add_percentages
的一部分调用)如果这不能产生您想要的顺序,只需切换对象
x
和y
即可。相反,如果您需要在模板中对其进行排序(弄乱第三方应用程序的源代码通常是一个坏主意),您可以使用
dictsort
过滤器:同样,如果这不是您想要的顺序,请使用
dictsortreversed
。Change
to
(This works well with the builtin
cmp
function because thetransper
fields are converted toint
s by thenice_percentage
function, which is called as part ofadd_percentages
)If that doesn't produce the order you wanted, simply switch objects
x
andy
.If instead you need to sort it in the template (it's typically a bad idea to mess with third-party apps' source code), you can use the
dictsort
filter:Again, if that's not the order you wanted, use
dictsortreversed
.Pootle 的最新开发版本(即 Pootle 2.2)现在可以记住您选择按哪一列进行排序。因此,页面重新加载现在会记住您上次使用的顺序。
The latest development version of Pootle, to become Pootle 2.2, now remembers which column you have selected to sort on. So a page reload will now remember the order you last used.