def newComment(): e = Event('web.newComment') comment = Comment() c_id = None key = request.form['k'] user = utils.getKey(key) logging.error('Processing %s' % user) if user is not None: target_id = None parent = None pObject = None if 'b' in request.form: target_id = request.form['b'] parent = 'b' pObject = Blibb() logging.error('Processing %s' % target_id) elif 'i' in request.form: target_id = request.form['i'] parent = 'i' pObject = Blitem() logging.error('Processing %s' % target_id) else: abort(404) text = request.form['c'] c_id = comment.insert(target_id, user, text, parent) pObject.incCommentsCounter(target_id) e.save() else: d = dict() d['error'] = "user not found" c_id = d return json.dumps(c_id,default=json_util.default)
def set_picture_data(): e = Event('getImage.set_picture_data') jsonData = request.form['p'] r = Picture.updateJson(jsonData) e.save() if r != 'null': return r else: abort(404)
def getTemplate(template_id=None): e = Event('web.getTemplate') t = Template() res = t.getById(template_id) e.save() if res != 'null': return res else: abort(404)
def get_picture_data(picture_id=None): e = Event('getImage.get_picture_data') r = None if is_valid_id(picture_id): r = Picture.dump_image(picture_id) e.save() if r is not None: return jsonify(r) else: abort(404)
def newTemplate(): e = Event('web.newTemplate') name = request.form['bname'] desc = request.form['bdesc'] key = request.form['bkey'] status = request.form['bstatus'] thumb = request.form['thumbnail'] user = utils.getKey(key) t = Template() res = str(t.insert(name, desc, user, thumb, status)) e.save() return res
def newPicture(): e = Event('getImage.newPicture') pict = Picture() blibb = request.form['b'] key = request.form['k'] user = get_user_name(key) items = dict() r = pict.create(user, items, blibb) e.save() if r != 'null': return r else: abort(404)
def publishTemplate(): e = Event('web.publishTemplate') t_id = request.form['tid'] view = request.form['view'] key = request.form['k'] user = utils.getKey(key) t = Template() if t.isOwner(t_id, user): t.load(t_id) t.createDefaultView() res = getMessage(t_id, True) else: res = getErrorMessage('User is not the owner of the Template') e.save() return res
def newBookmark(song_id=None): e = Event('web.content.newBookmark') bk = Bookmark() t = request.form['title'] b = request.form['b'] bn = request.form['bn'] k = request.form['k'] user = get_user_name(k) url = request.form['url'] tags = [] if 'tags' in request.form: tags = request.form['tags'] bk_id = bk.insert(b, user, url, t, bn, tags) e.save() return jsonify({'result': str(bk_id)})
def getImage(pict_id=None, size=160): e = Event('web.content.getImage') r = None if is_valid_id(pict_id): try: img = Picture.dump_image(pict_id) g = file(Picture.get_image_by_size(img, size)) return Response(g, direct_passthrough=True) except IOError: abort(404) e.save() if r != 'null': return json.dumps(r) else: abort(404)
def new_control(): e = Event('web.new_control') key = request.form['login_key'] name = request.form['control_name'] ui = request.form['control_ui'] type = request.form['control_type'] read = request.form['control_read'] write = request.form['control_write'] button = request.form['control_button'] user = utils.get_user_name(key) cid = Control.insert(name, user, ui, type, read, write, button) res = {'id': cid} e.save() return jsonify(res)
def addControl(): e = Event('web.addControl') c_id = request.form['cid'] t_id = request.form['tid'] order = request.form['order'] title = request.form['title'] help = request.form['help'] view = request.form['view'] slug = request.form['slug'] typex = request.form['typex'] key = request.form['k'] user = utils.getKey(key) t = Template() if t.isOwner(t_id, user): res = t.addControl(c_id, t_id, title, help, order, view, slug, typex) else: res = getErrorMessage('User is not the owner of the Template') e.save() return res
def loader_excel(): event = Event('web.content.loader_excel') key = request.form['login_key'] bid = request.form['blibb_id'] user = get_user_name(key) res = dict() file = request.files['file'] if file and allowed_file(file.filename): try: filename = secure_filename(file.filename) excel_file = os.path.join( get_config_value('UPLOAD_FOLDER'), filename ) file.save(excel_file) if is_valid_id(bid): fields = Blibb.get_fields(bid) excel_data = loader.excel_to_dict(excel_file, fields) current_app.logger.debug(excel_data) if len(excel_data): a = Blitem.bulk_insert(bid, user, excel_data) current_app.logger.debug(a) res['result'] = 'ok' else: res['error'] = 'No data found in file' else: if bid == '-1': res['error'] = 'create new blibb from file' res['error'] = 'Object Id is not valid' # except Exception, e: # current_app.logger.error(e) # res['error'] = 'Error processing spreadsheet' finally: if os.path.isfile(filename): os.unlink(filename) else: res['error'] = 'File was not uploaded' event.save() return jsonify(res)
def getComments(parent_id=None): e = Event('web.getComments') comment = Comment() cs = comment.getCommentsById(parent_id,True) e.save() return cs
def get_controls(): e = Event('web.get_controls') res = Control.get_all_controls() e.save() return jsonify({'controls': res})
def getCtrlUi(c_id=None): e = Event('web.getCtrlUi') c = BControl() res = c.getUiDefTemplate(c_id) e.save() return res
def getAllControls(): e = Event('web.getAllControls') c = BControl() res = c.getAllControls() e.save() return res
def getCtrls(): e = Event('web.getCtrls') c = BControl() res = c.getIdNameList() e.save() return res
def getTemplates(status=None, params=None): e = Event('web.newTemplate') template = Template() res = template.getActiveTemplates(status, params) e.save() return res