def create_old_email(): default = get_setting('EMAIL_FIELD_DEFAULT') if default: return default # 检查概率设置 pr = get_setting('EMAIL_FIELD_PR') char_field_list = get_setting('EMAIL_FIELD_LIST') if pr and is_hit_pr(pr): return get_lucky_one(char_field_list)
def create_old_datetime(): default = get_setting('DATETIME_FIELD_DEFAULT') if default: return default # 检查概率设置 pr = get_setting('DATETIME_FIELD_PR') datetime_field_list = get_setting('DATE_FIELD_LIST') if pr and is_hit_pr(pr): return get_lucky_one(datetime_field_list)
def create_old_int(): default = get_setting('INTEGER_FIELD_DEFAULT') if default: return default # 检查概率设置 pr = get_setting('INTEGER_FIELD_PR') integer_field_list = get_setting('INTEGER_FIELD_LIST') if pr and is_hit_pr(pr): return get_lucky_one(integer_field_list)
def create_old_float(): default = get_setting('FLOAT_FIELD_DEFAULT') if default: return default # 检查概率设置 pr = get_setting('FLOAT_FIELD_PR') float_field_list = get_setting('FLOAT_FIELD_LIST') if pr and is_hit_pr(pr): return get_lucky_one(float_field_list)
def create_old_password(): # 小分支,用户名类生成 # 检查是否有默认值 default = get_setting('PASSWORD_DEFAULT') if default: return default # 检查概率设置 pr = get_setting('PASSWORD_PR') password_list = get_setting('PASSWORD_LIST') if pr and is_hit_pr(pr): return get_lucky_one(password_list)
def create_old_name(): # 小分支,用户名类生成 # 检查是否有默认值 default = get_setting('NAME_DEFAULT') if default: return default # 检查概率设置 pr = get_setting('NAME_PR') name_list = get_setting('NAME_LIST') if pr and is_hit_pr(pr): return get_lucky_one(name_list)
def create_old_char(max_length): default = get_setting('CHAR_FIELD_DEFAULT') if default: return default # 检查概率设置 pr = get_setting('CHAR_FIELD_PR') char_field_list = get_setting('CHAR_FIELD_LIST') if pr and is_hit_pr(pr): ret = get_lucky_one(char_field_list) if max_length >= len(ret): return ret
def create_foreign_key(related_model, column): # column : consultant_id # 查找出所有已存在的model的id,随机选择一个id l = related_model.objects.all().values_list('id') required_num = get_setting('FOREIGN_OBJ_REQUIRED_NUMBER ') ingore_required_list = get_setting('CAN_IGNORE_REQUIRED_MODEL') id_list = list(l) if len(id_list) < 0: raise ForeignModelNullException(related_model, column) if len(id_list) < required_num: if related_model._meta.label not in ingore_required_list: raise ForeignModelNullException(related_model, column) foreign_id = random.choice(id_list)[0] return foreign_id
def create_new_file(): file_field_list = get_setting('FILE_FIELD_LIST') return get_lucky_one(file_field_list)
def create_new_text(): text_length_range = get_setting('TEXT_FIELD_RANGE') text_length = random.randint(*text_length_range) last_index = len(source_setting.TEXT_FIELD_WORD) - text_length index = random.randint(0, last_index) return source_setting.TEXT_FIELD_WORD[index:index + text_length + 1]