如何在 Pootle 中按总体完成情况显示排序列表

发布于 2024-10-01 20:48:28 字数 4309 浏览 7 评论 0原文

您好,我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆萌少年 2024-10-08 20:48:28

更改

items.sort(lambda x, y: locale.strcoll(x['name'], y['name']))

items.sort(lambda x, y: cmp(x['transper'], y['transper']))

(这与内置 cmp 函数配合良好,因为 transper 字段由 nice_percentage 函数,即作为 add_percentages 的一部分调用)

如果这不能产生您想要的顺序,只需切换对象 xy 即可。


相反,如果您需要在模板中对其进行排序(弄乱第三方应用程序的源代码通常是一个坏主意),您可以使用 dictsort 过滤器

{% for item in languages|dictsort:"transper" %}

同样,如果这不是您想要的顺序,请使用 dictsortreversed

Change

items.sort(lambda x, y: locale.strcoll(x['name'], y['name']))

to

items.sort(lambda x, y: cmp(x['transper'], y['transper']))

(This works well with the builtin cmp function because the transper fields are converted to ints by the nice_percentage function, which is called as part of add_percentages)

If that doesn't produce the order you wanted, simply switch objects x and y.


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:

{% for item in languages|dictsort:"transper" %}

Again, if that's not the order you wanted, use dictsortreversed.

无风消散 2024-10-08 20:48:28

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文