-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow users to sort alphabetically and by organization on the users…
… page.
- Loading branch information
Showing
4 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,36 @@ | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
from django.views.generic import TemplateView | ||
|
||
from organizations.models import Organization | ||
|
||
|
||
class UsersView(LoginRequiredMixin, TemplateView): | ||
template_name = 'users.html' | ||
|
||
def get_context_data(self, **kwargs): | ||
users = self.request.user.get_users().prefetch_related('organizations') | ||
organizations = self.request.user.get_organizations() | ||
|
||
sort_order = self.request.GET.get('sort', None) | ||
if sort_order: | ||
if sort_order == 'Alphabetically': | ||
users = users.order_by('name') | ||
else: | ||
users = users.order_by('organizations__name') | ||
|
||
organization = self.request.GET.get('organization', None) | ||
if organization: | ||
try: | ||
organization = Organization.objects.get(name=organization) | ||
organization_users = organization.get_people(self.request.user) | ||
if organization_users: | ||
users = users.filter(pk__in=organization_users.values_list('pk')) | ||
else: | ||
users = [] | ||
except Exception as e: | ||
raise Exception("Could not find organization" + str(e)) | ||
|
||
return { | ||
'users': self.request.user.get_users().prefetch_related('organizations'), | ||
'organizations': self.request.user.get_organizations() | ||
'users': users, | ||
'organizations': organizations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters