def _newItem(self, request): token = self._ensureAccessScope(request, 'post-item') authInfo = utils.AuthInfo() authInfo.username = token.user authInfo.organization = token.org convType = 'status' convId, conv, keywords = yield Item.new(request, authInfo, convType, richText=True) if keywords: raise errors.InvalidRequest(_('Matching keywords found(%s). Set reportOK=1.') % ', '.join(keywords)) else: self._success(request, 201, {'id': convId})
def _new(self, request, data=None): (appchange, script, args, myId) = yield self._getBasicArgs(request) me = args['me'] landing = not self._ajax authInfo = request.getSession(IAuthInfo) convType = data['type'] convId, conv, keywords = yield Item.new(request, authInfo, convType) if keywords: block = t.getBlock('item.mako', 'requireReviewDlg', keywords=keywords) request.write('$$.convs.reviewRequired(%s);' % json.dumps(block)) return target = conv['meta'].get('target', None) toFetchEntities = set() if target: toFetchEntities.update(target.split(',')) convType = utils.getRequestArg(request, "type") plugin = plugins[convType] entityIds = yield plugin.fetchData(args, convId) toFetchEntities.update(entityIds) entities = base.EntitySet(toFetchEntities) yield entities.fetchData() entities.update(args['me']) relation = Relation(myId, []) yield relation.initGroupsList() data = {"items": {convId: conv}, "relations": relation, "entities": entities, "script": True} args.update(data) onload = "(function(obj){$$.convs.load(obj);$('#sharebar-attach-uploaded').empty();})(this);" t.renderScriptBlock(request, "item.mako", "item_layout", False, "#user-feed", "prepend", args=[convId, 'conv-item-created'], handlers={"onload": onload}, **args) defaultType = plugins.keys()[0] plugins[defaultType].renderShareBlock(request, True) if plugin and hasattr(plugin, 'renderFeedSideBlock'): entityId = myId referer = request.getHeader('referer') matchObj = feedPathObj.search(referer) if matchObj: matchedStr = matchObj.group('entityId') if matchedStr != "": entityId = matchedStr else: if target: entityId = target.split(',')[0] args["groupId"] = target.split(',')[0] request.write("$('#feed-side-block-container').empty();") yield plugin.renderFeedSideBlock(request, landing, entityId, args)