コード例 #1
0
def get_rank_title(context):
    request = context['request']

    if request.user.is_anonymous:
        return False

    username = get_user(request.user).split(' ')[0]
    user = MyUser(username)

    return user.get_rank_title()
コード例 #2
0
def index(request):
    """
    `rank` dict should look like this:

     ranks = {
        'osx11': {
        'rank': ('rankosx', 'Гл. Администратор'),
        'online': 1024.0,
        'rating': (4.8, 10),
        'applications_considered': 123,
        'additional': [('expert', 'Эксперт'), ('paperwork', 'Бумажная работа')]
     },
    """

    ranks = {}

    for django_user in User.objects.all().exclude(username='******'):
        username = django_user.username
        user = MyUser(username)

        if user.has_access('staff'):
            continue

        ranks[username] = {'rank': (str, str),
                           'online': str,
                           'rating': str,
                           'additional': list}

        ranks[username]['rank'] = (user.get_rank_name(), user.get_rank_title())
        ranks[username]['online'] = user.get_online()
        ranks[username]['rating'] = (user.get_rating(), user.get_vote_count())
        ranks[username]['applications_considered'] = user.get_applications_considered()
        ranks[username]['additional'] = user.get_additional_ranks()

    ranks = dict(sorted(ranks.items(), key=lambda item: item[1]['rank'][0], reverse=True))

    return render(request, 'our_team/our_team.html', {'messages': messages.get_messages(request),
                                                      'ranks': ranks})