def render_GET(self, request): segmentCount = len(request.postpath) d = None if segmentCount == 0: d = self._renderNotifications(request) elif segmentCount == 1 and request.postpath[0] == "new" and self._ajax: d = utils.getLatestCounts(request) d.addCallback(lambda x: request.write('$$.menu.counts(%s);' % x)) return self._epilogue(request, d)
def _getBasicArgs(self, request): auth = yield defer.maybeDeferred(request.getSession, IAuthInfo) myId = auth.username orgId = auth.organization isOrgAdmin = auth.isAdmin script = False if '_ns' in request.args or\ request.getCookie('_ns') else True appchange = True if '_fp' in request.args and self._ajax or\ not self._ajax and script else False entities = EntitySet([myId, orgId]) yield entities.fetchData() args = {"me": entities[myId], "isOrgAdmin": isOrgAdmin, "ajax": self._ajax, "script": script, "org": entities[orgId], "myId": myId, "orgId": orgId} if appchange: latest = yield utils.getLatestCounts(request, False) args["latest"] = latest defer.returnValue((appchange, script, args, myId))
def _listGroups(self, request): appchange, script, args, myId = yield self._getBasicArgs(request) landing = not self._ajax me = args['me'] viewType = utils.getRequestArg(request, 'type') or 'myGroups' start = utils.getRequestArg(request, 'start') or '' start = utils.decodeKey(start) viewTypes = ['myGroups', 'allGroups', 'adminGroups', 'pendingRequests', 'invitations'] viewType = 'myGroups' if viewType not in viewTypes else viewType args["menuId"] = "groups" args['viewType'] = viewType cols = yield db.get_slice(myId, "entities", super_column='adminOfGroups') managedGroupIds = [col.column.name for col in cols] ##TODO: can we use getLatestCounts instead of fetching pendingConnections? cols = yield db.multiget_slice(managedGroupIds, "pendingConnections", count=1) cols = utils.multiColumnsToDict(cols) showPendingRequestsTab = sum([len(cols[groupId]) for groupId in cols]) > 0 args["showPendingRequestsTab"] = showPendingRequestsTab if viewType == 'pendingRequests' and not showPendingRequestsTab: viewType = 'myGroups' args["viewType"] = viewType cols = yield db.get_slice(myId, "pendingConnections", start="GI:", count=1) args["showInvitationsTab"] = bool(len([col for col in cols if col.column.name.startswith('GI:')])) if viewType == 'invitations' and not args["showInvitationsTab"]: viewType = 'myGroups' args['viewType'] = viewType counts = yield utils.getLatestCounts(request, False) groupRequestCount = args["groupRequestCount"] = counts["groups"] if script and landing: t.render(request, "groups.mako", **args) if script and appchange: t.renderScriptBlock(request, "groups.mako", "layout", landing, "#mainbar", "set", **args) if viewType not in ['pendingRequests', 'invitations']: if viewType == 'myGroups': data = yield Group.getGroups(me, me, start) elif viewType == 'allGroups': data = yield Group.getGroups(me, args['org'], start) else: data = yield Group.getManagedGroups(me, start) args.update(data) elif viewType == 'pendingRequests': data = yield Group.getGroupRequests(me, start) args.update(data) args['tab'] = 'pending' elif viewType == 'invitations': data = yield Group.getAllInvitations(me, start) args.update(data) if script: t.renderScriptBlock(request, "groups.mako", "titlebar", landing, "#titlebar", "set", **args) t.renderScriptBlock(request, "groups.mako", "viewOptions", landing, "#groups-view", "set", args=[viewType], showPendingRequestsTab=showPendingRequestsTab, showInvitationsTab=args['showInvitationsTab'], groupRequestCount=groupRequestCount) if viewType == "pendingRequests": t.renderScriptBlock(request, "groups.mako", "allPendingRequests", landing, "#groups-wrapper", "set", **args) else: t.renderScriptBlock(request, "groups.mako", "listGroups", landing, "#groups-wrapper", "set", **args) t.renderScriptBlock(request, "groups.mako", "paging", landing, "#groups-paging", "set", **args) if not script: t.render(request, "groups.mako", **args)