Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sorting of organization's user list #1977

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions judge/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
from judge.forms import EditOrganizationForm
from judge.models import Class, Organization, OrganizationRequest, Profile
from judge.utils.ranker import ranker
from judge.utils.views import TitleMixin, generic_message
from judge.utils.views import QueryStringSortMixin, TitleMixin, generic_message

__all__ = ['OrganizationList', 'OrganizationHome', 'OrganizationUsers', 'OrganizationMembershipChange',
'JoinOrganization', 'LeaveOrganization', 'EditOrganization', 'RequestJoinOrganization',
'OrganizationRequestDetail', 'OrganizationRequestView', 'OrganizationRequestLog',
'KickUserWidgetView', 'ClassHome', 'RequestJoinClass']


def users_for_template(users):
return ranker(users.filter(is_unlisted=False).order_by('-performance_points', '-problem_count')
def users_for_template(users, order):
return ranker(users.filter(is_unlisted=False).order_by(order)
.select_related('user').defer('about', 'user_script', 'notes'))


Expand Down Expand Up @@ -107,16 +107,20 @@ def get_context_data(self, **kwargs):
return context


class OrganizationUsers(OrganizationDetailView):
class OrganizationUsers(QueryStringSortMixin, OrganizationDetailView):
template_name = 'organization/users.html'
all_sorts = frozenset(('problem_count', 'rating', 'performance_points'))
default_desc = all_sorts
default_sort = '-performance_points'

def get_context_data(self, **kwargs):
context = super(OrganizationUsers, self).get_context_data(**kwargs)
context['title'] = _('%s Members') % self.object.name
context['users'] = users_for_template(self.object.members)
context['users'] = users_for_template(self.object.members, self.order)
context['partial'] = True
context['is_admin'] = self.can_edit_organization()
context['kick_url'] = reverse('organization_user_kick', args=[self.object.id, self.object.slug])
context.update(self.get_sort_context())
return context


Expand Down Expand Up @@ -395,14 +399,18 @@ def get(self, request, *args, **kwargs):
return self.render_to_response(context)


class ClassHome(ClassMixin, DetailView):
class ClassHome(QueryStringSortMixin, ClassMixin, DetailView):
template_name = 'organization/class.html'
all_sorts = frozenset(('problem_count', 'rating', 'performance_points'))
default_desc = all_sorts
default_sort = '-performance_points'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['logo_override_image'] = self.object.organization.logo_override_image
context['users'] = users_for_template(self.object.members)
context['users'] = users_for_template(self.object.members, self.order)
context['is_admin'] = False # Don't allow kicking here
context.update(self.get_sort_context())
return context

def get_content_title(self):
Expand Down
12 changes: 12 additions & 0 deletions resources/users.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ th.header.rank {
background: #fff897;
}
}

th a {
color: white;

&:link, &:visited {
color: white;
}

&:hover {
color: #0F0;
}
}
}

#search-form {
Expand Down
8 changes: 0 additions & 8 deletions templates/contest/ranking.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@
display: inline !important;
}

#users-table th a, #users-table th a:link, #users-table th a:visited {
color: white;
}

#users-table th a:hover {
color: #0F0;
}

#users-table td a:hover {
text-decoration: underline;
}
Expand Down
4 changes: 0 additions & 4 deletions templates/user/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
border-right: none;
text-align: left;
}

#users-table th a {
color: white;
}
</style>
{% endblock %}

Expand Down