-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
241 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from faker import Faker | ||
from torcms.handlers.user_handler import MUser | ||
from torcms.handlers.permission_handler import MPermission | ||
|
||
|
||
class Create_Data(object): | ||
def __init__(self): | ||
# 选择中文 | ||
fake = Faker('zh_CN') | ||
# 生成数据改变循环体来控制数据量rang(?) | ||
self.data_total = [ | ||
[fake.name(), fake.job(), fake.company(), fake.phone_number(), fake.company_email(), fake.address(), | ||
fake.date_time(tzinfo=None)] for x in range(100)] | ||
print(self.data_total) | ||
|
||
def deal_postgresql(self): | ||
# 写入mysql | ||
|
||
# SQL 插入语句 | ||
for val in self.data_total: | ||
post_data = { | ||
'user_name': val[0], | ||
'user_email': val[4], | ||
'user_pass': val[0], | ||
} | ||
|
||
MUser.create_user(post_data) | ||
|
||
|
||
if __name__ == '__main__': | ||
data = Create_Data() | ||
|
||
data.deal_postgresql() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- coding: utf-8 | ||
''' | ||
Genereting catetory. | ||
''' | ||
import os | ||
|
||
import yaml | ||
from openpyxl.reader.excel import load_workbook | ||
|
||
from torcms.model.category_model import MCategory | ||
|
||
from torcms.model.permission_model import MPermission | ||
from torcms.model.role_model import MRole | ||
|
||
XLSX_FILE = './database/role_perm.xlsx' | ||
|
||
|
||
def gen_xlsx_category(): | ||
''' | ||
Genereting role,permission from xlsx file. | ||
''' | ||
|
||
|
||
all_cate_arr = [] | ||
|
||
for sheet_ranges in load_workbook(filename=XLSX_FILE): | ||
kind_sig = str(sheet_ranges['A1'].value).strip() | ||
|
||
|
||
for row_num in range(3, 10000): | ||
|
||
# 父类 | ||
a_cell_val = sheet_ranges['A{0}'.format(row_num)].value | ||
b_cell_val = sheet_ranges['B{0}'.format(row_num)].value | ||
c_cell_val = sheet_ranges['C{0}'.format(row_num)].value | ||
d_cell_val = sheet_ranges['D{0}'.format(row_num)].value | ||
|
||
if a_cell_val and a_cell_val != '': | ||
cell_arr = a_cell_val.strip() | ||
uid = kind_sig + cell_arr.split(":")[0] | ||
name = cell_arr.split(":")[1] | ||
pid = '0000' | ||
auid=uid | ||
elif b_cell_val and b_cell_val != '': | ||
cell_arr = b_cell_val | ||
uid = kind_sig + cell_arr.split(":")[0] | ||
pid = auid | ||
name = name = cell_arr.split(":")[1] | ||
buid=uid | ||
elif c_cell_val and c_cell_val != '': | ||
cell_arr = c_cell_val | ||
uid = kind_sig + cell_arr.split(":")[0] | ||
pid = buid | ||
name = name = cell_arr.split(":")[1] | ||
cuid=uid | ||
elif d_cell_val and d_cell_val != '': | ||
cell_arr = d_cell_val | ||
uid = kind_sig + cell_arr.split(":")[0] | ||
pid = cuid | ||
name = name = cell_arr.split(":")[1] | ||
|
||
else: | ||
continue | ||
|
||
post_data = { | ||
'name': name, | ||
'uid': uid, | ||
'pid': pid | ||
} | ||
|
||
all_cate_arr.append(post_data) | ||
MRole.add_or_update(uid, post_data) | ||
|
||
return all_cate_arr | ||
|
||
|
||
|
||
|
||
|
||
def run_gen_category(*args): | ||
''' | ||
to run | ||
''' | ||
gen_xlsx_category() | ||
|
||
if __name__ == '__main__': | ||
gen_xlsx_category() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# -*- coding: utf-8 | ||
''' | ||
Genereting catetory. | ||
''' | ||
import os | ||
|
||
import yaml | ||
from openpyxl.reader.excel import load_workbook | ||
|
||
from torcms.model.category_model import MCategory | ||
|
||
from torcms.model.permission_model import MPermission | ||
from torcms.model.role_model import MRole | ||
|
||
XLSX_FILE = './database/role_perm.xlsx' | ||
|
||
|
||
def gen_xlsx_category(): | ||
''' | ||
Genereting catetory from xlsx file. | ||
''' | ||
|
||
# 在分类中排序 | ||
order_index = 1 | ||
|
||
all_cate_arr = [] | ||
|
||
for sheet_ranges in load_workbook(filename=XLSX_FILE): | ||
kind_sig = sheet_ranges.get_sheet_names() | ||
print(kind_sig) | ||
|
||
# for row_num in range(3, 10000): | ||
# | ||
# # 父类 | ||
# a_cell_val = sheet_ranges['A{0}'.format(row_num)].value | ||
# b_cell_val = sheet_ranges['B{0}'.format(row_num)].value | ||
# c_cell_val = sheet_ranges['C{0}'.format(row_num)].value | ||
# | ||
# if a_cell_val or b_cell_val or c_cell_val: | ||
# pass | ||
# else: | ||
# break | ||
# | ||
# if a_cell_val and a_cell_val != '': | ||
# cell_arr = a_cell_val.strip() | ||
# p_uid = cell_arr[1:] # 所有以 t 开头 | ||
# t_slug = sheet_ranges['C{0}'.format(row_num)].value.strip() | ||
# t_title = sheet_ranges['D{0}'.format(row_num)].value.strip() | ||
# u_uid = p_uid + (4 - len(p_uid)) * '0' | ||
# pp_uid = '0000' | ||
# elif b_cell_val and b_cell_val != '': | ||
# cell_arr = b_cell_val | ||
# c_iud = cell_arr[1:] | ||
# t_slug = sheet_ranges['C{0}'.format(row_num)].value.strip() | ||
# t_title = sheet_ranges['D{0}'.format(row_num)].value.strip() | ||
# if len(c_iud) == 4: | ||
# u_uid = c_iud | ||
# else: | ||
# u_uid = '{0}{1}'.format(p_uid, c_iud) | ||
# pp_uid = p_uid + (4 - len(p_uid)) * '0' | ||
# else: | ||
# continue | ||
# | ||
# post_data = { | ||
# 'name': t_title, | ||
# 'slug': t_slug, | ||
# 'order': order_index, | ||
# 'uid': u_uid, | ||
# 'pid': pp_uid, | ||
# 'kind': kind_sig, | ||
# } | ||
# all_cate_arr.append(post_data) | ||
# MCategory.add_or_update(u_uid, post_data) | ||
# order_index += 1 | ||
# return all_cate_arr | ||
|
||
|
||
|
||
|
||
|
||
def run_gen_role_permission(*args): | ||
''' | ||
to run | ||
''' | ||
gen_xlsx_category() | ||
|
||
if __name__ == '__main__': | ||
run_gen_role_permission() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters