def users_data(request): if LOGIN_ID not in request.session \ or LOGIN_TYPE not in request.session: return JsonResponse("") if request.session[LOGIN_TYPE] != LoginType.ORG \ or not 'name' in request.GET: return JsonResponse("") name = request.GET['name'] name = name.lower() if name == "": return JsonResponse("") org_id = request.session[LOGIN_ID] org = OrganizationDB.organization(uno=org_id) if not org.valid(): return JsonResponse("") users = UserDB.all() josn_string = '{"users_data":[' nou = 0 for user in users: if user['name'].lower().startswith(name): nou += 1 if nou != 1: josn_string += ', ' josn_string += '{"id":"'+user['_id']+'", "name":"'+user['name']+'", "email":"'+user['email']+'"' if user['organization']: josn_string += ', "available": false' else: josn_string += ', "available": true' josn_string += '}' josn_string += '], "no_of_users":'+str(nou)+'}' if nou == 0: return JsonResponse("") else: return JsonResponse(josn_string, safe=False)
def employees(self, etype=None): from db.user_database import UserDB from .user import User if etype == self.EmpType.GN: userdb = UserDB.all() role = self.EmpType.GN gn_arr = self.get('employees')[role.name] return [ User(doc) for doc in userdb if doc['_id'] in gn_arr and doc['role'] == role.name ] elif etype == self.EmpType.HR: return UserDB.user(uno=self.get('employees')[self.EmpType.HR.name]) elif etype == self.EmpType.SU: return UserDB.user(uno=self.get('employees')[self.EmpType.SU.name]) elif etype == self.EmpType.PS: return UserDB.user(uno=self.get('employees')[self.EmpType.PS.name]) return User()