def post(self): sender = self.request.get("from") id = self.request.get("id") message = self.request.get("message") comment = self.request.get("comment") item_key = db.Key(id) item = db.get(item_key) send_to = item.parent().user.email() email_message = message if (item.parent().user == users.get_current_user()): new_comment = Comment(parent=item ,message=message[0:400], poster='seller') new_comment.put() item.comments += 1 item.put() self.response.out.write("Success") self.response.set_status(201) return if not users.get_current_user(): if not mail.is_email_valid(sender): invalid_reason = mail.invalid_email_reason(sender, sender) self.response.out.write("<ERROR EXCEPTION>") return #TODO: Translate message #throw exception in client with message email_message += ''' *** IMPORTANT *** Please do not reply back to this message. Instead, you may write an email to %s ''' % sender sender = '*****@*****.**' else: sender = users.get_current_user().email() if comment: if (users.get_current_user()): new_comment = Comment(parent=item ,message=message[0:400], poster=users.get_current_user().nickname()) else: new_comment = Comment(parent=item ,message=message[0:400], poster='anonymous') new_comment.put() item.comments += 1 item.put() mail.send_mail(sender, send_to, 'Tatamee Buyer Notification [%s]' % item.title, email_message) logging.info('Email sent to: %s, by: %s' % (send_to, sender)) self.response.out.write("Success") self.response.set_status(201)
def get(self): if (self.request.get("action") == "map"): #TODO: Add results from categories with high edges min_lat = float(self.request.get('min_lat')) min_lng = float(self.request.get('min_lng')) max_lat = float(self.request.get('max_lat')) max_lng = float(self.request.get('max_lng')) search_terms = [word.strip().lower() for word in self.request.get('search_term').split()] result = [] tags = {} areas = geo.getInnerSquares(db.GeoPt(min_lat, min_lng), db.GeoPt(max_lat, max_lng)) while len(areas) > 0: query = db.Query(ItemLight) query.filter("area =", areas.pop()) for term in search_terms: query.filter("tags =", term) items = query.fetch(200) for item in items: result.append(item) self.response.out.write(cgi.escape('{Items: ' + MyEncoder.encode(MyEncoder(), result) + "}")) elif (self.request.get("action") == "user"): user_id = self.request.get("user_id") offset = int(self.request.get("offset")) user = User.get_by_key_name('key:' + user_id) items = [] if user: items = ItemLight.all().ancestor(user).fetch(1000, offset=offset) self.response.out.write(cgi.escape('{Items: ' + MyEncoder.encode(MyEncoder(), items) + "}")) return elif (self.request.get("action") == "me"): items = [] user = users.get_current_user() if user: user = User.get_by_key_name('key:' + user.user_id()) query = db.Query(ItemLight) query.ancestor(user) items = query.fetch(1000) self.response.out.write(cgi.escape('{Items: ' + MyEncoder.encode(MyEncoder(), items) + "}")) elif (self.request.get("action") == "item"): key = self.request.get("key") item = Item.get(key) self.response.out.write(MyEncoder.encode(MyEncoder(), item)) elif (self.request.get("action") == "comments"): offset = int(self.request.get("offset")) key = self.request.get("id") item = Item.get(key) comments = Comment.all().ancestor(item).order('-__key__').fetch(5, offset=offset) self.response.out.write(cgi.escape('{Messages: ' + MyEncoder.encode(MyEncoder(), comments) + '}')) elif (self.request.get("action") == "good_ratings"): offset = int(self.request.get("offset")) key = self.request.get("id") item = Item.get(key) ratings = GoodRating.all().ancestor(item.parent()).order('-__key__').fetch(5, offset=offset) logging.info(MyEncoder.encode(MyEncoder(), ratings)) self.response.out.write(cgi.escape('{Messages: ' + MyEncoder.encode(MyEncoder(), ratings) + '}')) elif (self.request.get("action") == "bad_ratings"): offset = int(self.request.get("offset")) key = self.request.get("id") item = Item.get(key) ratings = BadRating.all().ancestor(item.parent()).order('-__key__').fetch(5, offset=offset) self.response.out.write(cgi.escape('{Messages: ' + MyEncoder.encode(MyEncoder(), ratings) + '}'))