def _add(self, _group_uuid, _user_uuid):
        _redis = self.application.redis
        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid
        if _redis.sismember(_key, _user_uuid) == True:
            logging.info("user: %s already in group:%s" % (_user_uuid, _group_uuid))
            return

        _row = OrgGroupUserData(uuid=str(uuid.uuid1()), group_uuid=_group_uuid, user_uuid=_user_uuid)
        _row.async_add(_redis)
        _row.create_redis_keys(_redis)
        return
    def _remove(self, _group_uuid, _user_uuid):
        _redis = self.application.redis
        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid
        if _redis.sismember(_key, _user_uuid) == False:
            self.setErrorCode(API_ERR.NOT_GROUP_USER)
            logging.error("user: %s not in group:%s" % (_user_uuid, _group_uuid))
            return False

        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid + \
               ".user_uuid." + _user_uuid
        _data_uuid = _redis.get(_key)
        if _data_uuid == None:
            self.setErrorCode(API_ERR.NOT_GROUP_USER)
            logging.error("user: %s group:%s not bind." % (_user_uuid, _group_uuid))
            return False
        
        _row = OrgGroupUserData(uuid=_data_uuid)
        _row.async_delete(_redis)
        _row.delete_redis_keys(_redis)
        return True
    def _add(self, _group_uuid, _user_uuid):
        _redis = self.application.redis
        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid
        if _redis.sismember(_key, _user_uuid) == True:
            logging.info("user: %s already in group:%s" % (_user_uuid, _group_uuid))
            return

        # if the user has been in another group
        _key = OrgGroupUserData.__tablename__ + ".user_uuid." + _user_uuid
        _old_uuid = _redis.get(_key)
        if _old_uuid != None:
            _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _old_uuid + ".user_uuid." + _user_uuid
            _data_uuid = _redis.get(_key)
            if _data_uuid != None:
                _row = OrgGroupUserData(uuid=_data_uuid)
                _row.delete_redis_keys(_redis)
                _row.async_delete(_redis)

        _row = OrgGroupUserData(uuid=str(uuid.uuid1()), group_uuid=_group_uuid, user_uuid=_user_uuid)
        _row.async_add(_redis)
        _row.create_redis_keys(_redis)
        return
    def _add(self, _group_uuid, _user_uuid):
        _redis = self.application.redis
        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid
        if _redis.sismember(_key, _user_uuid) == True:
            logging.info("user: %s already in group:%s" %
                         (_user_uuid, _group_uuid))
            return

        _row = OrgGroupUserData(uuid=str(uuid.uuid1()),
                                group_uuid=_group_uuid,
                                user_uuid=_user_uuid)
        _row.async_add(_redis)
        _row.create_redis_keys(_redis)
        return
Beispiel #5
0
    def _remove(self, _group_uuid, _user_uuid):
        _redis = self.application.redis
        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid
        if _redis.sismember(_key, _user_uuid) == False:
            self.setErrorCode(API_ERR.NOT_GROUP_USER)
            logging.error("user: %s not in group:%s" %
                          (_user_uuid, _group_uuid))
            return False

        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid + \
               ".user_uuid." + _user_uuid
        _data_uuid = _redis.get(_key)
        if _data_uuid == None:
            self.setErrorCode(API_ERR.NOT_GROUP_USER)
            logging.error("user: %s group:%s not bind." %
                          (_user_uuid, _group_uuid))
            return False

        _row = OrgGroupUserData(uuid=_data_uuid)
        _row.async_delete(_redis)
        _row.delete_redis_keys(_redis)
        return True
def Csv2Mysql(csv_file):
    dbsession_class = getDatabaseInstance().dbsession_class
    db_session = dbsession_class()
    csv_data = csv.reader(file(csv_file))

    flag = 0
    for i in csv_data:
        flag += 1
        if flag != 1:
            row = []
            for item in i:
                row.append(encodeToUtf8(item, code_str))
            try:
                user_id = isUserExists(db_session, row[0])
                if not user_id:
                    deviceuser = DeviceUser()
                    deviceuser.user_name = row[0]
                    deviceuser.user_fullname = row[1]
                    deviceuser.user_email = row[2]
                    deviceuser.user_type = row[3]
                    deviceuser.user_status = row[4]
                    deviceuser.user_icon = "/static/yvertical/assets/img/user1.png"
                    deviceuser.user_gender = row[5]
                    deviceuser.user_dob = row[6]
                    deviceuser.user_doj = row[7]
                    deviceuser.user_rid = row[8]
                    deviceuser.user_iid = row[9]
                    is_byod = isByod(row[12])
                    deviceuser.user_is_byod = is_byod
                    deviceuser.user_is_enod = not is_byod
                    db_session.add(deviceuser)
                    db_session.commit()
                    user_id = deviceuser.id
            except:
                dbsession_class.remove()
                traceback.print_exc()
                break
                
            try:
                group_id = isGroupExists(db_session, row[11])
                if not group_id:
                    orggroup = OrgGroup()
                    orggroup.group_name = row[11]
                    orggroup.group_icon = "/static/yvertical/assets/img/group.jpg"
                    db_session.add(orggroup)
                    db_session.commit()
                    group_id = orggroup.id
            except:
                dbsession_class.remove()
                traceback.print_exc()

            try:
                user_data_id = isUserDataExists(db_session, user_id, group_id)
                if not user_data_id:
                    user_data = OrgGroupUserData()
                    user_data.group_id = group_id
                    user_data.user_id = user_id
                    user_data.is_leader = isLeader(row[10])
                    db_session.add(user_data)
                    db_session.commit()
            except:
                dbsession_class.remove()
                traceback.print_exc()

        else:
            if isinstance(i[0], unicode):
                code_str = None
            else:
                code_str = chardet.detect(i[0])["encoding"]
Beispiel #7
0
    def _add(self, _group_uuid, _user_uuid):
        _redis = self.application.redis
        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid
        if _redis.sismember(_key, _user_uuid) == True:
            logging.info("user: %s already in group:%s" %
                         (_user_uuid, _group_uuid))
            return

        # if the user has been in another group
        _key = OrgGroupUserData.__tablename__ + ".user_uuid." + _user_uuid
        _old_uuid = _redis.get(_key)
        if _old_uuid != None:
            _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _old_uuid + ".user_uuid." + _user_uuid
            _data_uuid = _redis.get(_key)
            if _data_uuid != None:
                _row = OrgGroupUserData(uuid=_data_uuid)
                _row.delete_redis_keys(_redis)
                _row.async_delete(_redis)

        _row = OrgGroupUserData(uuid=str(uuid.uuid1()),
                                group_uuid=_group_uuid,
                                user_uuid=_user_uuid)
        _row.async_add(_redis)
        _row.create_redis_keys(_redis)
        return