Beispiel #1
0
    def post(self):

        tool_user, db_user = ADayThere.tool_user()
        if not tool_user:
            self.response.status = 401
            return

        data = json.loads(self.request.body)

        day = Day.query_user_title(db_user.user_id, data["title"]).get()

        KeywordsDayList.delete_keywords(day)

        day.full_locality = data["full_locality"]
        day.title = data["title"]
        day.description = data["description"]

        if isinstance(data["keywords"], basestring):
            if "," in data["keywords"]:
                day.keywords = data["keywords"].split(",")
            else:
                day.keywords = data["keywords"].split(" ")
        else:
            day.keywords = data["keywords"]

        for keyword in day.keywords:
            Keywords.add_if_missing(keyword)

        day.places = []
        for place in data["places"]:
            p = Place()
            p.name = place["name"]
            p.comment = place["comment"]
            p.location = Location()
            p.location.latitude = str(place["location"]["latitude"])
            p.location.longitude = str(place["location"]["longitude"])
            p.location.vicinity = place["vicinity"]
            day.places.append(p)

        day.photos = []
        for photo in data["photos"]:
            day_photo = DayPhoto()
            day_photo.title = photo["title"]
            day_photo.description = photo["description"]

            day.photos.append(day_photo)

            photo_query = Photos.query_photo(db_user.user_id, photo["title"])
            pq = photo_query.get()
            cnt = pq.used_by.count(day.title)
            if cnt == 0:
                pq.used_by.append(day.title)

        day.put()

        KeywordsDayList.add_keywords(day)

        Words.update_words(day.title, day.description, day.key, day.full_locality)

        self.response.status = 200
Beispiel #2
0
    def get (self):

        keywords = Keywords.query ().fetch ()

        rv = []
        for keyword in keywords:
            rv.append (keyword.keyword)

        self.response.write (json.dumps (rv))