def add_controls(self, template, controls, user): items = [] # current_app.logger.info("add_controls " + str(controls)) controls = json.loads(controls) for control in controls: item = {} cid = control.get('cid', '') if is_valid_id(cid): item['c'] = ObjectId(cid) item['n'] = control['name'] item['h'] = control['help'] item['tx'] = control['type'] item['o'] = int(control['order']) item['s'] = slugify(control['name']) item['m'] = True if control['multi'] == 'true' else False if 'items' in control: item['i'] = control.get('items') items.append(item) # else: # current_app.logger.info('Control ID' + cid) # current_app.logger.info(items) now = datetime.utcnow() doc = { "n": template, "u": user, "c": now, "s": slugify(template), 'q': 'draft', 'i': items} newId = objects.insert(doc) return str(newId)
def insert(self, name, desc, user, thumbnail, status="draft"): now = datetime.utcnow() doc = { "n": name, "d": desc, "u": user, "c": now, "s": slugify(name), 't': thumbnail, 'q': status} newId = objects.insert(doc) return str(newId)