Example #1
0
 def info(self):
     from server.models.follow import Follow
     from server.models.shift import Shift
     # TODO: use the bulk API - David 12/10/09
     result = {}
     db = core.connect()
     shared = core.connect("shiftspace/shared")
     result["followerCount"] = core.value(Follow.followers_count(db, key=self.id)) or 0
     result["followingCount"] = core.value(Follow.following_count(db, key=self.id)) or 0
     result["publishedShiftCount"] = core.value(Shift.count_by_user_and_published(shared, key=self.id)) or 0
     return result
Example #2
0
 def info(self):
     from server.models.follow import Follow
     from server.models.shift import Shift
     # TODO: use the bulk API - David 12/10/09
     result = {}
     db = core.connect()
     shared = core.connect("shiftspace/shared")
     result["followerCount"] = core.value(
         Follow.followers_count(db, key=self.id)) or 0
     result["followingCount"] = core.value(
         Follow.following_count(db, key=self.id)) or 0
     result["publishedShiftCount"] = core.value(
         Shift.count_by_user_and_published(shared, key=self.id)) or 0
     return result
Example #3
0
 def followers(self, start=None, end=None, limit=25):
     from server.models.follow import Follow
     if not start:
         start = [self.id]
     if not end:
         end = [self.id, {}]
     results = Follow.followers_by_created(core.connect(), limit=limit)
     userIds = core.values(results[start:end])
     return core.fetch(keys=userIds)
Example #4
0
 def followers(self, start=None, end=None, limit=25):
     from server.models.follow import Follow
     if not start:
         start = [self.id]
     if not end:
         end = [self.id, {}]
     results = Follow.followers_by_created(core.connect(), limit=limit)
     userIds = core.values(results[start:end])
     return core.fetch(keys=userIds)
Example #5
0
    def shifts(cls, user, byHref=None, byDomain=None, byFollowing=False, byGroups=False, bySpace=None, start=0, limit=25, filter=False, query=None, all=False):
        from server.models.ssuser import SSUser
        db = core.connect("shiftspace/shared")
        lucene = core.lucene()
        queryString = ""
        # TODO: validate all fields - David
        
        if byHref or byDomain:
            if byHref:
                queryString = "hrefExact:\"%s_HREF_EXACT\"" % byHref
            elif byDomain:
                queryString = "domain:\"%s\""% byDomain
            if bySpace:
                queryString = queryString + " spaceName:" + bySpace
            queryString = queryString + " AND ((draft:false AND private:false)"
            if user:
                queryString = queryString + " OR createdBy:%s" % user.id
                dbs = user.readable()
                dbs.append(SSUser.db(user.id))
                dbsStr = " ".join(dbs)
                queryString = queryString + ((" OR (draft:false%s)" % ((len(dbs) > 0 and (" AND dbs:(%s)" % dbsStr)) or "")))
            queryString = queryString + ")"
        elif byFollowing:
            from server.models.follow import Follow
            # FIXME: impossible to make this scale in a simple way for many followers w/o p2p - David 12/2/09
            # when p2p we can tag the shift as a follow shift when we get it
            results = Follow.following_by_created(core.connect())
            following = " ".join(core.values(results[[user.id]:[user.id, {}]]))
            queryString = "(draft:false AND private:false AND createdBy:(%s)) OR dbs:(%s)" % (following, SSUser.db(user.id))
        elif byGroups:
            from server.models.group import Group
            queryString = "dbs:(%s)" % " ".join(user.readable())
        if filter:
            queryString = queryString + " AND " + core.dictToQuery(query)

        print queryString
        try:
            if all:
                rows = lucene.search(db, "shifts", q=queryString, include_docs=True, sort="\modified")
            else:
                rows = lucene.search(db, "shifts", q=queryString, include_docs=True, sort="\modified", skip=start, limit=limit)
        except Exception, err:
            print err
            return []
Example #6
0
 def unfollow(self, other):
     from server.models.follow import Follow
     follow = Follow.read(self, other)
     follow.delete()
     return self
Example #7
0
 def follow(self, other):
     from server.models.follow import Follow
     Follow.create(self, other)
     return self
Example #8
0
 def unfollow(self, other):
     from server.models.follow import Follow
     follow = Follow.read(self, other)
     follow.delete()
     return self
Example #9
0
 def follow(self, other):
     from server.models.follow import Follow
     Follow.create(self, other)
     return self
Example #10
0
    def shifts(cls,
               user,
               byHref=None,
               byDomain=None,
               byFollowing=False,
               byGroups=False,
               bySpace=None,
               start=0,
               limit=25,
               filter=False,
               query=None,
               all=False):
        from server.models.ssuser import SSUser
        db = core.connect("shiftspace/shared")
        lucene = core.lucene()
        queryString = ""
        # TODO: validate all fields - David

        if byHref or byDomain:
            if byHref:
                queryString = "hrefExact:\"%s_HREF_EXACT\"" % byHref
            elif byDomain:
                queryString = "domain:\"%s\"" % byDomain
            if bySpace:
                queryString = queryString + " spaceName:" + bySpace
            queryString = queryString + " AND ((draft:false AND private:false)"
            if user:
                queryString = queryString + " OR createdBy:%s" % user.id
                dbs = user.readable()
                dbs.append(SSUser.db(user.id))
                dbsStr = " ".join(dbs)
                queryString = queryString + ((" OR (draft:false%s)" % (
                    (len(dbs) > 0 and (" AND dbs:(%s)" % dbsStr)) or "")))
            queryString = queryString + ")"
        elif byFollowing:
            from server.models.follow import Follow
            # FIXME: impossible to make this scale in a simple way for many followers w/o p2p - David 12/2/09
            # when p2p we can tag the shift as a follow shift when we get it
            results = Follow.following_by_created(core.connect())
            following = " ".join(core.values(results[[user.id]:[user.id, {}]]))
            queryString = "(draft:false AND private:false AND createdBy:(%s)) OR dbs:(%s)" % (
                following, SSUser.db(user.id))
        elif byGroups:
            from server.models.group import Group
            queryString = "dbs:(%s)" % " ".join(user.readable())
        if filter:
            queryString = queryString + " AND " + core.dictToQuery(query)

        print queryString
        try:
            if all:
                rows = lucene.search(db,
                                     "shifts",
                                     q=queryString,
                                     include_docs=True,
                                     sort="\modified")
            else:
                rows = lucene.search(db,
                                     "shifts",
                                     q=queryString,
                                     include_docs=True,
                                     sort="\modified",
                                     skip=start,
                                     limit=limit)
        except Exception, err:
            print err
            return []