8c87979e86b401e8be1ad66602e61aa7ec0c73de
[laas.git] / src / booking / lib.py
1 ##############################################################################
2 # Copyright (c) 2019 Parker Berberian, Sawyer Bergeron, and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 from account.models import UserProfile
11
12
13 def get_user_field_opts():
14     return {
15         'show_from_noentry': False,
16         'show_x_results': 5,
17         'results_scrollable': True,
18         'selectable_limit': -1,
19         'placeholder': 'Search for other users',
20         'name': 'users',
21         'disabled': False
22     }
23
24
25 def get_user_items(exclude=None):
26     qs = UserProfile.objects.filter(public_user=True).select_related('user').exclude(user=exclude)
27     items = {}
28     for up in qs:
29         item = {
30             'id': up.id,
31             'expanded_name': up.full_name if up.full_name else up.user.username,
32             'small_name': up.user.username,
33             'string': up.email_addr if up.email_addr else up.user.username,
34         }
35         items[up.id] = item
36     return items