Exemple #1
0
 def shifts(self, start=None, end=None, limit=25, filter=False, query=None):
     from server.models.shift import Shift
     db = core.connect("shiftspace/shared")
     if not filter:
         if not start:
             start = [self.id]
         if not end:
             end = [self.id, {}]
         results = Shift.by_user_and_created(db, limit=limit)
         return Shift.joinData(core.objects(results[start:end]))
     else:
         lucene = core.lucene()
         queryString = "createdBy:%s" % self.id
         theFilter = core.dictToQuery(query)
         if theFilter:
             queryString = queryString + " AND " + theFilter
         try:
             print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
             print queryString
             rows = lucene.search(db,
                                  "shifts",
                                  q=queryString,
                                  include_docs=True,
                                  sort="\modified")
         except Exception, err:
             print err
             return []
         shifts = [row["doc"] for row in rows]
         return Shift.joinData(shifts, self.id)
Exemple #2
0
 def shifts(self, start=None, end=None, limit=25, filter=False, query=None):
     from server.models.shift import Shift
     db = core.connect("shiftspace/shared")
     if not filter:
         if not start:
             start = [self.id]
         if not end:
             end = [self.id, {}]
         results = Shift.by_user_and_created(db, limit=limit)
         return Shift.joinData(core.objects(results[start:end]))
     else:
         lucene = core.lucene()
         queryString = "createdBy:%s" % self.id
         theFilter = core.dictToQuery(query)
         if theFilter:
             queryString = queryString + " AND " + theFilter
         try:
             print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
             print queryString
             rows = lucene.search(db, "shifts", q=queryString, include_docs=True, sort="\modified")
         except Exception, err:
             print err
             return []
         shifts = [row["doc"] for row in rows]
         return Shift.joinData(shifts, self.id)
Exemple #3
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 []
Exemple #4
0
def shifts(byHref, userId=None, byFollowing=False, byGroups=False, start=0, perPage=25):
    """
    Returns a list of shifts based on whether
        1. href
        3. By public streams specified user is following. 
        4. By groups streams specified user is following.
    Parameters:
        byHref - a url
        byDomain - a url string
        byFollowing - a user id
        byGroups - a user id
    Returns:
        A list of shifts that match the specifications.
    """
    db = core.connect()
    # NOTE: to prevent errors on a newly created DB - David 9/11/09
    if core.single(schema.statsCount, "shift") == None:
        return []
    lucene = core.lucene()
    # TODO: validate byHref - David
    queryString = "(href:\"%s\" AND draft:false AND private:false)" % byHref
    if userId:
        queryString = queryString + " OR createdBy:%s" % userId
        streams = ""
        if byFollowing:
            following = user.followStreams(userId)
            streams = streams + " ".join(following)
        if byGroups:
            groups = user.groupStreams(userId)
            streams = streams + " ".join(groups)
        # TODO: make sure streams cannot be manipulated from client - David
        queryString = queryString + ((" OR (draft:false%s)" % ((len(streams) > 0 and (" AND streams:%s" % streams)) or "")))
    rows = lucene.search("shifts", q=queryString, sort="\modified", skip=start, limit=perPage)

    shifts = [db[row["id"]] for row in rows]
    return shifts
Exemple #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 []