|
6 | 6 | class Visitor(NodeVisitor): |
7 | 7 | def visit_class_name(self, node, visited_children): |
8 | 8 | """get class name""" |
9 | | - class_name = node.children[1].children[0].text.strip() |
| 9 | + class_name = node.children[1].children[0].text.strip().replace(':', '') |
10 | 10 | return {"name": class_name} |
11 | 11 |
|
12 | 12 | def visit_class_def(self, node, visited_children): |
@@ -58,7 +58,6 @@ def extract_orm_attr(self, text: str): |
58 | 58 | text = text.split(",") |
59 | 59 |
|
60 | 60 | text = self.clean_up_cases_with_inner_pars(text) |
61 | | - print(text) |
62 | 61 | if i == "Field": |
63 | 62 | # for tortoise orm |
64 | 63 | split_by_field = base_text.split("Field")[0].split(".") |
@@ -122,38 +121,41 @@ def visit_attr_def(self, node, visited_children): |
122 | 121 | attr["attr"]["properties"] = children[-1][-1]["properties"] |
123 | 122 | if children[-1][-1]["type"] is not None: |
124 | 123 | attr["attr"]["type"] = children[-1][-1]["type"] |
125 | | - |
126 | 124 | return attr |
127 | 125 |
|
128 | | - def process_chld(self, child, final_child, meta): |
| 126 | + def process_chld(self, child, final_child): |
129 | 127 | if "attr" in child and child["attr"]["name"]: |
130 | 128 | if "tablename" in child["attr"]["name"]: |
131 | 129 | final_child["properties"]["table_name"] = child["attr"]["default"] |
132 | | - elif "table_args" in child["attr"]["name"] or meta: |
| 130 | + elif "table_args" in child["attr"]["name"]: |
133 | 131 | final_child["properties"][child["attr"]["name"]] = ( |
134 | 132 | child["attr"]["type"] or child["attr"]["default"] |
135 | 133 | ) |
136 | 134 | else: |
137 | | - if "class Meta" == child["attr"]["name"]: |
138 | | - return final_child, True |
139 | 135 | final_child["attrs"].append(child["attr"]) |
140 | 136 | else: |
141 | 137 | if isinstance(child, dict): |
142 | 138 | final_child.update(child) |
143 | 139 | elif isinstance(child, list): |
144 | 140 | for i in child: |
145 | | - final_child, meta = self.process_chld(i, final_child, meta) |
146 | | - return final_child, meta |
| 141 | + final_child= self.process_chld(i, final_child) |
| 142 | + return final_child |
147 | 143 |
|
148 | 144 | def visit_expr(self, node, visited_children): |
149 | 145 | """Makes a dict of the section (as key) and the key/value pairs.""" |
150 | 146 | children_values = [] |
| 147 | + n = -1 |
151 | 148 | for i in visited_children: |
152 | | - meta = False |
153 | 149 | final_child = {"name": None, "attrs": [], "parents": [], "properties": {}} |
154 | | - final_child, _ = self.process_chld(i, final_child, meta) |
155 | | - if final_child["name"]: |
| 150 | + final_child = self.process_chld(i, final_child) |
| 151 | + if final_child.get('name') and final_child['name'] == 'Meta' and children_values: |
| 152 | + for attr in final_child['attrs']: |
| 153 | + children_values[n]["properties"][attr["name"]] = ( |
| 154 | + attr["type"] or attr["default"] |
| 155 | + ) |
| 156 | + elif final_child.get("name"): |
156 | 157 | children_values.append(final_child) |
| 158 | + n += 1 |
157 | 159 | if "attr" in final_child: |
158 | 160 | del final_child["attr"] |
159 | 161 | return children_values |
|
0 commit comments