1 from django.contrib.auth import authenticate, login, logout
2 from django.template import RequestContext
3 from django.shortcuts import render, render_to_response
5 from manifoldapi.manifoldresult import ManifoldResult
6 from ui.topmenu import topmenu_items, the_user
7 from myslice.configengine import ConfigEngine
8 from manifold.core.query import Query
9 from unfold.page import Page
10 from manifoldapi.manifoldapi import execute_admin_query
11 from unfold.loginrequired import LoginRequiredAutoLogoutView
13 from myslice.theme import ThemeView
16 class UsersView (LoginRequiredAutoLogoutView, ThemeView):
17 template_name = 'usersview.html'
19 # expose this so we can mention the backend URL on the welcome page
20 def default_env (self):
22 'MANIFOLD_URL':ConfigEngine().manifold_url(),
25 def post (self,request):
26 env = self.default_env()
27 env['theme'] = self.theme
28 return render_to_response(self.template, env, context_instance=RequestContext(request))
30 def get (self, request, state=None):
31 env = self.default_env()
39 user_query = Query().get('local:user').select('email','status','config')
40 user_details = execute_admin_query(self.request, user_query)
42 for user in user_details:
44 email_list.append(user['email'])
46 if user['status'] == 0:
47 user_status = 'Disabled'
48 elif user['status'] == 1:
49 user_status = 'Validation Pending'
50 elif user['status'] == 2:
51 user_status = 'Enabled'
55 status_list.append(user_status)
57 if user['config'] is not None:
58 user_config = json.loads(user['config'])
59 user_authority = user_config.get('authority','N/A')
60 authority_list.append(user_authority)
62 user_list = [{'email': t[0], 'status': t[1], 'authority':t[2]}
63 for t in zip(email_list, status_list, authority_list)]
65 if request.user.is_authenticated():
66 env['person'] = self.request.user
70 env['theme'] = self.theme
71 env['user_list']= user_list
73 env['username']=the_user(request)
74 env['topmenu_items'] = topmenu_items(None, request)
75 if state: env['state'] = state
76 elif not env['username']: env['state'] = None
77 # use one or two columns for the layout - not logged in users will see the login prompt
78 env['layout_1_or_2']="layout-unfold2.html" if not env['username'] else "layout-unfold1.html"
81 return render_to_response(self.template, env, context_instance=RequestContext(request))