20 from django.views.generic.list_detail import object_list |
20 from django.views.generic.list_detail import object_list |
21 from django.contrib.auth.decorators import login_required |
21 from django.contrib.auth.decorators import login_required |
22 from cm.views import get_keys_from_dict |
22 from cm.views import get_keys_from_dict |
23 from cm.security import has_global_perm |
23 from cm.security import has_global_perm |
24 from cm.exception import UnauthorizedException |
24 from cm.exception import UnauthorizedException |
|
25 from tagging.models import Tag |
25 import sys |
26 import sys |
26 import re |
27 import re |
27 |
28 |
28 USER_PAGINATION = 10 |
29 USER_PAGINATION = 10 |
29 |
30 |
30 @has_global_perm('can_manage_workspace') |
31 @has_global_perm('can_manage_workspace') |
31 def user_list(request): |
32 def user_list(request): |
32 display_suspended_users = get_int(request.GET, 'display', 0) |
33 display_suspended_users = get_int(request.GET, 'display', 0) |
|
34 tag_selected = request.GET.get('tag_selected', 0) |
33 paginate_by = get_int(request.GET, 'paginate', USER_PAGINATION) |
35 paginate_by = get_int(request.GET, 'paginate', USER_PAGINATION) |
34 order_by = get_among(request.GET, 'order', ('user__username', |
36 order_by = get_among(request.GET, 'order', ('user__username', |
35 'user__email', |
37 'user__email', |
36 '-user__username', |
38 '-user__username', |
37 '-user__email', |
39 '-user__email', |
103 context = { |
105 context = { |
104 'anon_role' : anon_role, |
106 'anon_role' : anon_role, |
105 'all_roles' : Role.objects.all(), |
107 'all_roles' : Role.objects.all(), |
106 'anon_roles' : Role.objects.filter(anon=True), |
108 'anon_roles' : Role.objects.filter(anon=True), |
107 'display_suspended_users' : display_suspended_users, |
109 'display_suspended_users' : display_suspended_users, |
|
110 'tag_list' : Tag.objects.usage_for_model(UserProfile), |
|
111 'tag_selected': tag_selected, |
108 } |
112 } |
109 |
113 |
110 query = UserRole.objects.filter(text=None).filter(~Q(user=None)).order_by(order_by) |
114 query = UserRole.objects.select_related().filter(text=None).filter(~Q(user=None)).order_by(order_by) |
111 if not display_suspended_users: |
115 if not display_suspended_users: |
112 query = query.exclude(Q(user__userprofile__is_suspended=True) & Q(user__is_active=True)) |
116 query = query.exclude(Q(user__userprofile__is_suspended=True) & Q(user__is_active=True)) |
113 |
117 |
|
118 if tag_selected: |
|
119 tag_ids = Tag.objects.filter(name=tag_selected) |
|
120 if tag_ids: |
|
121 content_type_id = ContentType.objects.get_for_model(UserProfile).pk |
|
122 # table cm_userprofile is not present if display_suspended_users: fix this |
|
123 tables = ['tagging_taggeditem', 'cm_userprofile'] if display_suspended_users else ['tagging_taggeditem'] |
|
124 query = query.extra(where=['tagging_taggeditem.object_id = cm_userprofile.id', |
|
125 'tagging_taggeditem.content_type_id = %i' %content_type_id, |
|
126 'tagging_taggeditem.tag_id = %i' %tag_ids[0].id], |
|
127 tables=tables, |
|
128 ) |
|
129 |
114 return object_list(request, query, |
130 return object_list(request, query, |
115 template_name='site/user_list.html', |
131 template_name='site/user_list.html', |
116 paginate_by=paginate_by, |
132 paginate_by=paginate_by, |
117 extra_context=context, |
133 extra_context=context, |
118 ) |
134 ) |
181 self.fields['role'] = role_field |
197 self.fields['role'] = role_field |
182 |
198 |
183 class UserProfileForm(ModelForm): |
199 class UserProfileForm(ModelForm): |
184 class Meta: |
200 class Meta: |
185 model = UserProfile |
201 model = UserProfile |
186 fields = ('allow_contact', 'preferred_language', 'is_suspended') |
202 fields = ('allow_contact', 'preferred_language', 'is_suspended', 'tags') |
187 |
203 |
188 class MyUserProfileForm(ModelForm): |
204 class MyUserProfileForm(ModelForm): |
189 class Meta: |
205 class Meta: |
190 model = UserProfile |
206 model = UserProfile |
191 fields = ('allow_contact', 'preferred_language') |
207 fields = ('allow_contact', 'preferred_language') |
192 |
208 |
193 class UserProfileAddForm(ModelForm): |
209 class UserProfileAddForm(ModelForm): |
194 class Meta: |
210 class Meta: |
195 model = UserProfile |
211 model = UserProfile |
196 fields = ('preferred_language',) |
212 fields = ('preferred_language', 'tags') |
197 |
213 |
198 class UserAddForm(forms.Form): |
214 class UserAddForm(forms.Form): |
199 note = forms.CharField(label=ugettext_lazy(u'Note'), |
215 note = forms.CharField(label=ugettext_lazy(u'Note'), |
200 help_text=ugettext_lazy(u'Optional text to add to invitation email'), |
216 help_text=ugettext_lazy(u'Optional text to add to invitation email'), |
201 widget=forms.Textarea, |
217 widget=forms.Textarea, |