Beispiel #1
0
    def get(self):
        """Returns one or more radars.
        
        Parameters:
        
        count (optional): The number of results to return. Default is 100.
        page (optional): The page of results. Default is 1.
        id (optional): The radar identifier.
        number (optional): The radar number.
        user (optional): The email address of the radar submitter.
        
        Errors:
        
        400 Bad Request
        """
        result = {}
        count = self.request.get("count", None)
        if (count):
            count = int(count)
        else:
            count = 100
        page = self.request.get("page", None)
        if (page):
            page = int(page)
        else:
            page = 1
        parameters = []
        radarId = self.request.get("id")
        if (radarId):
            parameters.append(radarId)
            radar = db.Radar().fetchById(int(radarId))
            if (radar):
                result = radar.toDictionary()
        if (not result):
            radarNumber = self.request.get("number")
            if radarNumber:
                parameters.append(radarNumber)
                radar = db.Radar().fetchByNumber(radarNumber)
                if (radar):
                    result = radar.toDictionary()
        if (not result):
            userName = self.request.get("user")
            if (userName):
                parameters.append(userName)
                user = google.appengine.api.users.User(userName)
                if (user):
                    radars = db.Radar().fetchByUser(user, page, count)
                    if (radars):
                        result = [radar.toDictionary() for radar in radars]
        if (not result and not parameters):
            radars = db.Radar().fetchAll(page, count)
            if (radars):
                result = [radar.toDictionary() for radar in radars]

        # Return the result
        self.respondWithDictionaryAsJSON({"result": result})
Beispiel #2
0
    def get(self):
        result = {}
        radars = None

        count = self.request.get("count")
        if (count):
            count = int(count)
        else:
            count = 100

        page = self.request.get("page")
        if (page):
            page = int(page)
        else:
            page = 1

        scope = self.request.get("scope")
        if (not scope):
            scope = "all"

        searchQuery = self.request.get("q")
        keywords = searchQuery.split(" ")
        keyword = keywords[0]

        try:
            if (scope == "number"):
                radars = db.Radar().fetchByNumbers(keywords, page, count)
            elif (scope == "user"):
                users = []
                for userName in keywords:
                    user = google.appengine.api.users.User(userName)
                    if user:
                        users.append(user)
                radars = db.Radar().fetchByUsers(users, page, count)
            else:
                radars = models.Radar.all().search(keyword).order(
                    "-number").fetch(count, (page - 1) * count)
        except Exception:
            radars = None

        if (radars and len(radars) > 0):
            result = [radar.toDictionary() for radar in radars]

        # Return the result
        self.respondWithDictionaryAsJSON({"result": result})
Beispiel #3
0
 def get(self):
     """Returns the number of radars.
     
     Parameters:
     
     Errors:
     
     400 Bad Request
     """
     result = db.Radar().fetchCount()
     # Return the result
     self.respondWithDictionaryAsJSON({"result": result})