def generate_dynamic_table_by_objects(objects): try: if (len(objects) == 0): return None dt = dynamic_table.DynamicTable() #generate header for ob in objects: # data =ob.data # data = json.loads(data) # fields =data["fields"] schema_id = ob.schema_id #schema_id =data["schema_id"] sch = get_to_schema(schema_id) data = sch.data data = json.loads(data) fields = data["fields"] for field in fields: if (check_field(field, "is_visible")): dt.init_header_element(text=field["title"], align="center", value=field["name"]) break for ob in objects: items = {} data = ob.data data = json.loads(data) fields = data["fields"] d_obj = dynamic_object.DynamicObject() setattr(d_obj, "g_id", ob.id) for field in fields: field_type = field["field_type"] if (field_type == 9): items = f_i_converter.get_to_schema_link_items( ob.schema_id, field["name"]) if (items != None and len(items) > 0): field["items"] = encoder.encode(items) o_v = field["output_value"] for i in items: if (str(i.id) == str(o_v)): field["output_value"] = i.name break if (check_field(field, "is_visible")): setattr(d_obj, field["name"], field["output_value"]) dt.init_item(d_obj) return encoder.encode(dt) except Exception as e: return None
def get(self, id): result = e_model.EntityDetails(id) if result == None: abort(404, message="Object {} doesn't exist".format(id)) return encoder.encode(result)
def get_to_data_field_items(data): try: j = json.loads(data) fields = j["fields"] for field in fields: field_type = field["field_type"] if (field_type == 9 or field_type == 5): items = get_to_schema_catalog_items(field["var"]["schema_id"]) if (items != None and len(items) > 0): field["items"] = encoder.encode(items) j["fields"] = fields data = encoder.encode(j) return data except Exception as e: return data
def __init__(self, schema_id, client_id, user_id, parent_id, fields): self.client_id = client_id self.user_id = user_id self.schema_id = schema_id self.creation_date = datetime.datetime.now() self.update_date = datetime.datetime.now() self.parent_id = parent_id obj = object_model.Object(parent_id=parent_id, fields=fields) self.data = encoder.encode(obj)
def export_object(obj): export_path =setting.TEMP_FOLDER filename = export_path+obj.name+".txt" try: j = encoder.encode(obj) f = open(filename, 'w', encoding='utf-8') f.write(j) f.close() except Exception as e: print("Error in exporting: " + str(e))
def __init__(self, name, title, group_title, description, schema_type_id, client_id, user_id, is_show): self.name = name self.title = title self.group_title = group_title self.description = description self.schema_type_id = schema_type_id self.client_id = client_id self.user_id = user_id self.creation_date = datetime.datetime.now() self.is_show = is_show obj = schema_model.Schema(name, title, group_title, schema_type_id) self.creation_date = datetime.datetime.now() self.update_date = datetime.datetime.now() self.data = encoder.encode(obj)
def put(self, id): try: json_data = request.get_json(force=True) object = session.query(Objects).filter(Objects.id == id).first() object.schema_id = json_data["schema_id"] object.client_id = json_data["client_id"] object.user_id = json_data["user_id"] object.parent_id = json_data["parent_id"] fields = json_data["fields"] object.update_date = datetime.datetime.now() obj = object_model.Object(parent_id=object.parent_id, fields=fields) object.data = encoder.encode(obj) session.add(object) session.commit() return object, 201 except: session.rollback() abort(400, message="Error while update object")
def convert_schema_object(json_data): name = json_data['name'] title = json_data["title"] group_title = json_data["group_title"] schema_type_id = json_data["schema_type_id"] data = json_data["data"] fields = json.loads(data)["fields"] ob = ob_model.Schema(name, title, group_title, schema_type_id, True) ob.fields = [] for field in fields: field_type = field["field_type"] f_var = init_field(field, field_type) is_index = check_arr_value(field, "is_index") is_value = check_arr_value(field, "is_value") is_visible = check_arr_value(field, "is_visible") r_field = field_model.Field(len(ob.fields), field["name"], field["title"], field_type, f_var, is_index, is_value, is_visible) ob.init_field(r_field) return encoder.encode(ob) pass
import modules.testing_modules.test_module as testing import models.app_models.dynamic_object_models.dynamic_object_model as dynamic_model import modules.json_modules.json_encoder as encoder if __name__ == '__main__': try: print("Working") model = dynamic_model.DynamicObject() model.id = '1' model.name = 'test' s ="" model.s= '2' model.values =[] obj =dynamic_model.DynamicObject() setattr(obj, 'some_attribute', 42); s = encoder.encode(model) testing.run_test() except Exception as e: print("Error");