Skip to content

Commit 786af7f

Browse files
sbanoeondjs0109
andauthored
fix(entities): fixed blocking of entity type field (#220)
* fix(entities): fixed blocking of entity type field after pressing load button when no data model passed * chore(entities): fix type only when type is defined in datamodels --------- Co-authored-by: JunsongDu <[email protected]>
1 parent 38546fe commit 786af7f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app/Entirety/entities/views.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def post(self, request, *args, **kwargs):
193193
context = super(Create, self).get_context_data(**kwargs)
194194
if self.request.POST.get("data_model") == "..":
195195
entity_json = {}
196+
basic_info = EntityForm(self.project)
196197
else:
197198
try:
198199
entity_json = parse_entity(self.request.POST.get("data_model"))
@@ -201,12 +202,16 @@ def post(self, request, *args, **kwargs):
201202
messages.error(
202203
self.request, f"Error parsing data model: missing key {e}"
203204
)
204-
entity_json = {}
205-
basic_info = EntityForm(
206-
self.project,
207-
initial={"id": entity_json.get("id"), "type": entity_json.get("type")},
208-
)
209-
basic_info.fields["type"].widget.attrs["readonly"] = True
205+
entity_json = dict()
206+
basic_info = EntityForm(
207+
self.project,
208+
initial={
209+
"id": entity_json.get("id"),
210+
"type": entity_json.get("type"),
211+
},
212+
)
213+
if basic_info.initial.get("type"):
214+
basic_info.fields["type"].widget.attrs["readonly"] = True
210215
initial = []
211216
for attr_key, attr_value in entity_json.items():
212217
if attr_key not in MANDATORY_ENTITY_FIELDS:

0 commit comments

Comments
 (0)