def newTemplate(): name = request.form["template_name"] desc = request.form["template_description"] key = request.form["login_key"] thumb = request.form["thumbnail"] user = utils.get_user_name(key) # check if that template exists filter = {"n": name, "u": user} current_app.logger.info(filter) template = ControlTemplate.get_object(filter, {"_id": 1}) if template is None: res = ControlTemplate.insert(name, desc, user, thumb) else: res = str(template.get("_id", "")) return jsonify({"result": res})
def insert(self, user, name, slug, desc, template_id, image, read_access, write_access): if is_valid_id(template_id): template = ControlTemplate.get_object( {'_id': ObjectId(template_id)}) items = template['i'] fields = [] for item in items: fields.append(item['s']) now = datetime.utcnow() acl = dict() acl['read'] = read_access acl['write'] = write_access num = int(NUM_CHARS) url_id = "".join(sample(digits + ascii_letters, num)) doc = {"n": name, "s": slug, "d": desc, "u": user, "c": now, "t": template, "img": image, 'a': acl, 'f': fields, 'at': slug, 'st': {'v': 0}, 'si': url_id} newId = objects.insert(doc) return str(newId)