示例#1
0
文件: helpers.py 项目: sobkulir/web
def get_latest_submits_for_task(task):
    description_submits = (
        task.submit_set.filter(
            submit_type=submit_constants.SUBMIT_TYPE_DESCRIPTION, time__lte=task.round.end_time
        )
        .exclude(testing_status=submit_constants.SUBMIT_STATUS_REVIEWED)
        .select_related("user")
    )

    source_submits = (
        task.submit_set.filter(
            submit_type=submit_constants.SUBMIT_TYPE_SOURCE, time__lte=task.round.end_time
        )
        .exclude(testing_status=submit_constants.SUBMIT_STATUS_REVIEWED)
        .select_related("user")
    )

    review_submits = task.submit_set.filter(
        submit_type=submit_constants.SUBMIT_TYPE_DESCRIPTION,
        testing_status=submit_constants.SUBMIT_STATUS_REVIEWED,
    ).select_related("user")

    submits_by_user = {}
    for submit in description_submits:
        if submit.user not in submits_by_user:
            submits_by_user[submit.user] = {"description": submit}
        elif submits_by_user[submit.user]["description"].time < submit.time:
            submits_by_user[submit.user]["description"] = submit

    for submit in source_submits:
        if submit.user in submits_by_user:
            if "sources" not in submits_by_user[submit.user]:
                submits_by_user[submit.user]["sources"] = [submit]
            else:
                submits_by_user[submit.user]["sources"].append(submit)

    for submit in review_submits:
        if submit.user not in submits_by_user:
            submits_by_user[submit.user] = {"review": submit}
        elif "review" not in submits_by_user[submit.user]:
            submits_by_user[submit.user]["review"] = submit
        elif submits_by_user[submit.user]["review"].time < submit.time:
            submits_by_user[submit.user]["review"] = submit

    return OrderedDict(
        sorted(
            submits_by_user.items(),
            key=lambda x: (czech_sort.key(x[0].last_name), czech_sort.key(x[0].first_name)),
        )
    )
示例#2
0
def test_pair(a, b):
    ka = key(a)
    kb = key(b)
    assert ka <= kb
    assert not ka > kb
    if a == b:
        assert ka == kb
        assert ka >= kb
        assert not ka < kb
        assert not ka != kb
    else:
        assert not ka == kb
        assert not ka >= kb
        assert ka < kb
        assert ka != kb
示例#3
0
文件: song.py 项目: lamanchy/songbook
 def get_sort_key(self):
     return [czech_sort.key(c)
             for c in self.categories] + [czech_sort.key(self.title)]
示例#4
0
文件: jobs.py 项目: messa/python.cz
 def item_key(item):
     return czech_sort.key(item[key])
示例#5
0
文件: jobs.py 项目: svagi/python.cz
 def item_key(item):
     return czech_sort.key(item[key])
示例#6
0
def sort_key(supporter):
    return czech_sort.key(supporter.last_name)