def getNCommunicationsbyPageIndex(self, commType, n=0, index=0): try: Pages = getCache(commType + "Cache") if (Pages is None): print "Cache Not Found" PostCommunicationFnx().setCommunicationCache(commType) Pages = getCache(commType + "Cache") Page = Pages.page(1) M = Page.object_list if (index != 0): if (index in Pages.page_range): Page = Pages.page(index) M = Page.object_list else: error_msg = 'Error @ getNCommunicationsbyPageIndex in Business Functions:Page Index does not exist' self.CommunicationLogger.exception( '[%s] == Exception ==' % ('getNCommunicationsbyPageIndex')) return (-1, error_msg) if (n != 0): M = M[:n] return [M, Page.has_next(), Page.has_previous(), Pages.page_range] except: error_msg = 'Error @ getNCommunicationsbyPageIndex in Business Functions' self.CommunicationLogger.exception( '[%s] == Exception ==' % ('getNCommunicationsbyPageIndex')) return (-5, error_msg)
def getCommunicationTemplate(self): CACHE_COMMUNICATION_TEMPLATE = 'CACHE_COMMUNICATION_TEMPLATE' CommTemplateList = getCache(CACHE_COMMUNICATION_TEMPLATE) if CommTemplateList is None: CommTemplateList = CommunicationTemplates.objects.all() setCache(CACHE_COMMUNICATION_TEMPLATE, CommTemplateList) return CommTemplateList
def getCommunicationTemplate(self): CACHE_COMMUNICATION_TEMPLATE = 'CACHE_COMMUNICATION_TEMPLATE' CommTemplateList = getCache(CACHE_COMMUNICATION_TEMPLATE) if CommTemplateList is None: CommTemplateList = CommunicationTemplates.objects.all() setCache(CACHE_COMMUNICATION_TEMPLATE,CommTemplateList) return CommTemplateList
def getCommunicationTypes(self): CACHE_COMMUNICATION_TYPES = 'CACHE_COMMUNICATION_TYPES' CommTypeList = getCache(CACHE_COMMUNICATION_TYPES) if CommTypeList is None: CommTypeList = CommunicationType.objects.all() setCache(CACHE_COMMUNICATION_TYPES, CommTypeList) return CommTypeList
def getGroupFromCache(self,name=-1,groupid = -1): GroupList = getCache(self.CACHE_KEY_ALL_GROUPS) try: if GroupList is not -1 and GroupList is not None: return (1,GroupList) else: return (-1,'ERROR in Retrieveing groups from cache') except Exception, ex: self.UserLogger.exception('getGroupFromCache') return (-2,self.MakeExceptionMessage(str(ex)))
def getSystemEntity(): s_entity = -1 try: s_entity = getCache(CACHE_KEY_SYSTEM_ENTITY) if s_entity is None or s_entity == -1: e_obj = Entity.objects.get(EntityName=SYSTEM_ENTITY) setCache(CACHE_KEY_SYSTEM_ENTITY,e_obj.id) s_entity = e_obj.id return s_entity except: return s_entity
def getSystemGroup_NewUsers(): s_entity = -1 try: s_entity = getCache(CACHE_KEY_NEW_USERS_GROUP) if s_entity is None or s_entity == -1: e_obj = Group.objects.get(GroupName=SYSTEM_DAEMON_CREATE_USER_GROUP) setCache(CACHE_KEY_NEW_USERS_GROUP,e_obj.id) s_entity = e_obj.id return s_entity except: return s_entity
def getSystemGroup_EmailAU(): s_entity = -1 try: s_entity = getCache(CACHE_KEY_SYSTEM_DAEMON_USERAU_USER_GROUP) if s_entity is None or s_entity == -1: e_obj = Group.objects.get(GroupName=SYSTEM_DAEMON_USERAU_USER_GROUP) setCache(CACHE_KEY_SYSTEM_DAEMON_USERAU_USER_GROUP,e_obj.id) s_entity = e_obj.id return s_entity except: return s_entity
def getNCommunicationsbyPageIndex(self,commType,n=0, index=0): try: Pages=getCache(commType+"Cache") if(Pages is None): print "Cache Not Found" PostCommunicationFnx().setCommunicationCache(commType) Pages=getCache(commType+"Cache") Page=Pages.page(1) M=Page.object_list if(index!=0): if(index in Pages.page_range): Page=Pages.page(index) M=Page.object_list else: error_msg = 'Error @ getNCommunicationsbyPageIndex in Business Functions:Page Index does not exist' self.CommunicationLogger.exception('[%s] == Exception =='%('getNCommunicationsbyPageIndex')) return (-1,error_msg) if(n!=0): M=M[:n] return [M,Page.has_next(),Page.has_previous(), Pages.page_range] except: error_msg = 'Error @ getNCommunicationsbyPageIndex in Business Functions' self.CommunicationLogger.exception('[%s] == Exception =='%('getNCommunicationsbyPageIndex')) return (-5,error_msg)
def getMenuListFromCache(self): try: MenuList = getCache(self.CACHEKEY) if MenuList is not -1 and MenuList is not None: return (1,MenuList) else: return (-1,'Error in Retrieveing Menu from cache.') except Exception, ex: frame = inspect.currentframe() args, _, _, values = inspect.getargvalues(frame) msg = '' for i in args: msg += "[%s : %s]" % (i,values[i]) self.UserLogger.exception('%s : %s' % (inspect.getframeinfo(frame)[2],msg)) return (-2,str(ex))
def getSystemUser_DaemonCreateUser(): s_entity = -1 print 'DaemonCreateUser %d' % (s_entity) print CACHE_KEY_SYSTEM_DAEMON_CREATE_USER , SYSTEM_DAEMON_CREATE_USER try: s_entity = getCache(CACHE_KEY_SYSTEM_DAEMON_CREATE_USER) if s_entity is None or s_entity == -1: e_obj = User.objects.get(UserEmail=SYSTEM_DAEMON_CREATE_USER) print 'DaemonCreateUser %d' % (e_obj.id) setCache(CACHE_KEY_SYSTEM_DAEMON_CREATE_USER,e_obj.id) s_entity = e_obj.id print 'DaemonCreateUser %d' % (s_entity) return s_entity except: UserLogger.exception(' Exception occured in getSystemUser_DaemonCreateUser') return s_entity
def getMenuListFromCache(self): try: MenuList = getCache(self.CACHEKEY) if MenuList is not -1 and MenuList is not None: return (1, MenuList) else: return (-1, 'Error in Retrieveing Menu from cache.') except Exception, ex: frame = inspect.currentframe() args, _, _, values = inspect.getargvalues(frame) msg = '' for i in args: msg += "[%s : %s]" % (i, values[i]) self.UserLogger.exception('%s : %s' % (inspect.getframeinfo(frame)[2], msg)) return (-2, str(ex))
def getListFromCache(self, groupid): try: GroupMenuList = getCache(self.getKey(groupid)) if GroupMenuList is not -1 and GroupMenuList is not None: #print '===== CACHE RETURN :: %d ====== ' % (groupid) return (1,GroupMenuList) else: return (-1,'ERROR in Retrieveing GroupMenuList from cache') except Exception, ex: frame = inspect.currentframe() args, _, _, values = inspect.getargvalues(frame) msg = '' for i in args: msg += "[%s : %s]" % (i,values[i]) self.UserLogger.exception('%s : %s' % (inspect.getframeinfo(frame)[2],msg)) return (-2,str(ex))
def UserContextProcessor(request): try: logindetails = GetLoginDetails(request) GroupMenuFnxObj = GroupMenuFnx() if( logindetails["userid"] != -1): # USER IS LOGGED IN, GET THE MENU LISTS AND PASS HERE # get the groupid AllUsersGid = getCache(ALL_LOGGED_IN_USERS_GROUP) if AllUsersGid == None or AllUsersGid == -1: GroupFnxObj = GroupFnx() gobj = GroupFnxObj.getGroupObjectByName(ALL_LOGGED_IN_USERS_GROUP) if (gobj[0] == 1): AllUsersGid = gobj[1].id else: return {'loggedin':False} setCache(ALL_LOGGED_IN_USERS_GROUP,AllUsersGid) #get the menulist AllUsersChildMenuList = GroupMenuFnxObj.getGroupMenuObjectByGroupID(AllUsersGid)[1] AllUsersParentMenuList = GroupMenuFnxObj.getParentGroupMenuObjectByGroupID(AllUsersGid)[1] GroupChildMenuList = GroupMenuFnxObj.getGroupMenuObjectByGroupID(int(logindetails['groupid']))[1] GroupParentMenuList = GroupMenuFnxObj.getParentGroupMenuObjectByGroupID(int(logindetails['groupid']))[1] return_dict = { "userid":logindetails['userid'], "groupid":logindetails['groupid'], "loginid":logindetails['loginid'], "fname":logindetails["fname"], "loggedin":True, "AllUsersChildMenuList":AllUsersChildMenuList, "AllUsersParentMenuList":AllUsersParentMenuList, "GroupChildMenuList":GroupChildMenuList, "GroupParentMenuList":GroupParentMenuList, } #print return_dict return return_dict else: # USER IS NOT LOGGED IN, GET ANONYMOUS LISTS AND PASS HERE AnonymousUsersGid = getCache(ANONYMOUS_GROUP) if AnonymousUsersGid == None or AnonymousUsersGid == -1: GroupFnxObj = GroupFnx() gobj = GroupFnxObj.getGroupObjectByName(ANONYMOUS_GROUP) if (gobj[0] == 1): AnonymousUsersGid = gobj[1].id else: return {'loggedin':False} setCache(ANONYMOUS_GROUP,AnonymousUsersGid) #get the menulist AnonymousChildMenuList = GroupMenuFnxObj.getGroupMenuObjectByGroupID(AnonymousUsersGid)[1] AnonymousParentMenuList = GroupMenuFnxObj.getParentGroupMenuObjectByGroupID(AnonymousUsersGid)[1] return_dict = { "loggedin":False, "AnonymousChildMenuList":AnonymousChildMenuList, "AnonymousParentMenuList":AnonymousParentMenuList, } #print return_dict return return_dict except Exception, ex: frame = inspect.currentframe() args, _, _, values = inspect.getargvalues(frame) msg = '' for i in args: msg += "[%s : %s]" % (i,values[i]) Logger_User.exception('%s : %s' % (inspect.getframeinfo(frame)[2],msg)) return {'loggedin':False}
def getGroupTypeFromCache(self): GroupTypeList = getCache(self.CACHEKEY) if GroupTypeList is not -1 and GroupTypeList is not None: return (1,GroupTypeList) else: return (-1,'ERROR in Retrieveing grouptypes from cache')
def getGroupTypeFromCache(self): GroupTypeList = getCache(self.CACHEKEY) if GroupTypeList is not -1 and GroupTypeList is not None: return (1, GroupTypeList) else: return (-1, 'ERROR in Retrieveing grouptypes from cache')
def UserContextProcessor(request): try: logindetails = GetLoginDetails(request) GroupMenuFnxObj = GroupMenuFnx() if (logindetails["userid"] != -1): # USER IS LOGGED IN, GET THE MENU LISTS AND PASS HERE # get the groupid AllUsersGid = getCache(ALL_LOGGED_IN_USERS_GROUP) if AllUsersGid == None or AllUsersGid == -1: GroupFnxObj = GroupFnx() gobj = GroupFnxObj.getGroupObjectByName( ALL_LOGGED_IN_USERS_GROUP) if (gobj[0] == 1): AllUsersGid = gobj[1].id else: return {'loggedin': False} setCache(ALL_LOGGED_IN_USERS_GROUP, AllUsersGid) #get the menulist AllUsersChildMenuList = GroupMenuFnxObj.getGroupMenuObjectByGroupID( AllUsersGid)[1] AllUsersParentMenuList = GroupMenuFnxObj.getParentGroupMenuObjectByGroupID( AllUsersGid)[1] GroupChildMenuList = GroupMenuFnxObj.getGroupMenuObjectByGroupID( int(logindetails['groupid']))[1] GroupParentMenuList = GroupMenuFnxObj.getParentGroupMenuObjectByGroupID( int(logindetails['groupid']))[1] return_dict = { "userid": logindetails['userid'], "groupid": logindetails['groupid'], "loginid": logindetails['loginid'], "fname": logindetails["fname"], "loggedin": True, "AllUsersChildMenuList": AllUsersChildMenuList, "AllUsersParentMenuList": AllUsersParentMenuList, "GroupChildMenuList": GroupChildMenuList, "GroupParentMenuList": GroupParentMenuList, } #print return_dict return return_dict else: # USER IS NOT LOGGED IN, GET ANONYMOUS LISTS AND PASS HERE AnonymousUsersGid = getCache(ANONYMOUS_GROUP) if AnonymousUsersGid == None or AnonymousUsersGid == -1: GroupFnxObj = GroupFnx() gobj = GroupFnxObj.getGroupObjectByName(ANONYMOUS_GROUP) if (gobj[0] == 1): AnonymousUsersGid = gobj[1].id else: return {'loggedin': False} setCache(ANONYMOUS_GROUP, AnonymousUsersGid) #get the menulist AnonymousChildMenuList = GroupMenuFnxObj.getGroupMenuObjectByGroupID( AnonymousUsersGid)[1] AnonymousParentMenuList = GroupMenuFnxObj.getParentGroupMenuObjectByGroupID( AnonymousUsersGid)[1] return_dict = { "loggedin": False, "AnonymousChildMenuList": AnonymousChildMenuList, "AnonymousParentMenuList": AnonymousParentMenuList, } #print return_dict return return_dict except Exception, ex: frame = inspect.currentframe() args, _, _, values = inspect.getargvalues(frame) msg = '' for i in args: msg += "[%s : %s]" % (i, values[i]) Logger_User.exception('%s : %s' % (inspect.getframeinfo(frame)[2], msg)) return {'loggedin': False}