Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Imports
3from django.contrib.auth import get_user_model
4from django.contrib.auth.models import Group
5from django.utils.translation import ugettext_lazy as _
6from superdjango import ui
8UserModel = get_user_model()
10# Controls
13class UserControl(ui.controls.ForeignKeyControl):
14 pass
15 # def get_
17# Models
20class GroupUI(ui.ModelUI):
21 model = Group
22 icon = "fas fa-users"
24 controls = {
25 'permissions': ui.controls.ManyToManyControl(input_type="multiselectjs"),
26 }
28 ajax_auto_complete_options = ui.AjaxAutoCompleteOptions("name")
29 detail_options = ui.DetailOptions(
30 "name",
31 "permissions",
32 active_page="accounts",
33 active_subpage="groups"
34 )
35 form_options = ui.FormOptions(
36 "name",
37 "permissions",
38 active_page="accounts",
39 active_subpage="groups",
40 save_and_add=True
41 )
42 list_options = ui.ListOptions(
43 "name",
44 "permissions",
45 link_field="name",
46 active_page="accounts",
47 active_subpage="groups"
48 )
50 def get_verbose_name(self):
51 return _("Group")
53 def get_verbose_name_plural(self):
54 return _("Groups")
57class UserUI(ui.ModelUI):
58 model = UserModel
59 icon = "fas fa-user"
61 controls = {
62 'groups': ui.controls.ManyToManyControl(input_type="multiselectjs"),
63 'is_superuser': ui.controls.BooleanControl(css_icon=True),
64 'is_staff': ui.controls.BooleanControl(css_icon=True),
65 'is_active': ui.controls.BooleanControl(css_icon=True),
66 }
68 ajax_auto_complete_options = ui.AjaxAutoCompleteOptions(
69 "first_name",
70 "last_name",
71 "email",
72 "username",
73 )
74 detail_options = ui.DetailOptions(
75 UserModel.USERNAME_FIELD,
76 UserModel.EMAIL_FIELD,
77 "first_name",
78 "last_name",
79 "is_superuser",
80 "is_staff",
81 "is_active",
82 "date_joined",
83 "groups",
84 active_page="accounts",
85 active_subpage="users"
86 )
88 form_options = ui.FormOptions(
89 UserModel.USERNAME_FIELD,
90 UserModel.EMAIL_FIELD,
91 "first_name",
92 "last_name",
93 "is_superuser",
94 "is_staff",
95 "is_active",
96 "groups",
97 active_page="accounts",
98 active_subpage="users"
99 )
101 list_options = ui.ListOptions(
102 UserModel.USERNAME_FIELD,
103 UserModel.EMAIL_FIELD,
104 "first_name",
105 "last_name",
106 "is_superuser",
107 "is_staff",
108 "is_active",
109 "date_joined",
110 active_page="accounts",
111 active_subpage="users",
112 filtering=ui.Filtering("is_superuser", "is_staff", "is_active"),
113 link_field=UserModel.USERNAME_FIELD
114 )
116 def get_display_value(self, record, as_choice=False, label_field=None):
117 try:
118 return record.get_full_name() or getattr(record, UserModel.USERNAME_FIELD)
119 except AttributeError:
120 return getattr(record, UserModel.USERNAME_FIELD)
122 def get_verbose_name(self):
123 return _("User")
125 def get_verbose_name_plural(self):
126 return _("Users")
128# Menus
131class UsersMenu(ui.Menu):
132 icon = "fas fa-users"
133 items = [
134 UserUI,
135 GroupUI,
136 ]
137 label = _("Users")
138 prefix = "users"