def post(self): session = is_logged_in(self) if not session: return req = self.request errors = {} dn = validate_string(req, errors, 'dname', 'display name', 100) email = validate_string(req, errors, 'email', 'email', 100) if len(errors): return self.redirect_to_self(errors) uid = session['my_id'] user = User.get_by_key_name(uid) if user.display_name!=dn or user.email!=email: str_update = "dn=%s email=%s ==> dn=%s email=%s" % (user.display_name, user.email, dn, email) user.display_name = dn user.email = email try: user.put() except Exception, e: logging.info("Unable to update user profile: " + str_update) return self.redirect_to_self({'err':'Unable to update your profile. Please try again later'}) # profile has been updated session['my_dname'] = dn session['my_email'] = email logging.info("Updated user profile: " + str_update) memcache.delete('u+c%s' % uid) # clear saved user_info self.redirect('/profile/update?info=Your%20profile%20has%20been%20updated.')
def post(self): session = is_logged_in(self) if not session: return self.redirect(REDIR_URL) req = self.request errors = {} name = validate_string(req, errors, 'name', 'search name', MAX_FEED_NAME_LEN) if not name: name = '' rss_url = req.get('rss_url') if rss_url: feed_key = parse_rss_url(rss_url) if not feed_key: return self.redirect_to_errors(GET_PARAMS, {'error_rss_url':'''This URL isn't in the expected form. Please <a href="/contact">send it to us</a> if you think this is a bug.'''}) if len(errors): return self.redirect_to_self(GET_PARAMS, errors) else: city = validate_string(req, errors, 'city', 'city/region', max_len=50) category = validate_string(req, errors, 'category', 'category', 3) area = '' # TODO: add area picker if not CATEGORIES.has_key(category): errors['category'] = 'Please choose a category.' query = validate_string(req, errors, 'query', 'search string', 100, required=False) if not query: query = '' title_only = req.get('title_only')=='checked' if title_only: stype = 'T' else: stype = 'A' min_cost = validate_int(req, errors, 'min_cost', 'Minimum Cost', 0, None, False) if not min_cost: min_cost = '' max_cost = validate_int(req, errors, 'max_cost', 'Maximum Cost', 0, None, False) if not max_cost: max_cost = '' num_bedrooms = validate_int(req, errors, 'num_bedrooms', 'Number of bedrooms', 1, 8, False) if not num_bedrooms: num_bedrooms = '' cats = req.get('cats')=='checked' dogs = req.get('dogs')=='checked' pics = req.get('pics')=='checked' if len(errors): return self.redirect_to_self(GET_PARAMS, errors) feed_key = Feed.make_key_name(city, category, area, min_cost, max_cost, num_bedrooms, cats, dogs, pics, [], stype, query) # make sure the feed is in the datastore try: feed = Feed.get_or_insert(key_name=feed_key) except Exception, e: logging.error('Unable to create new Feed (%s): %s' % (feed_key, e)) return self.redirect_to_self(GET_PARAMS, {'err':'The service is temporarily unavailable - please try again later.'})
def post(self): session = is_logged_in(self) if not session: return self.redirect(REDIR_URL) req = self.request errors = {} ad_url = validate_string(req, errors, 'ad_url', 'Craigslist Ad URL') if ad_url: if ad_url[:7] != 'http://': ad_url = 'http://' + ad_url m = RE_URL_CHECK.match(ad_url) if not m: errors['ad_url'] = 'This URL does not appear to be a valid craigslist.org webpage.' else: m = RE_ID.match(ad_url) if not m: errors['ad_url'] = 'Could not extract the ID from Ad URL' else: cid = int(m.group(1)) if len(errors): return self.redirect_to_self(GET_PARAMS, errors) # efficiency: get Ad and UserCmt at the same time to_put = [] ad_key = db.Key.from_path('Ad', cid) cmt_key = db.Key.from_path('UserCmt', '%s%s' % (session['my_id'], cid)) ad, cmt = db.get([ad_key, cmt_key]) # download the ad if we don't already have it in our db if not ad: ret = self.fetch_and_parse_page(ad_url) if not ret: errors['ad_url'] = 'Unable to download the webpage' return self.redirect_to_self(GET_PARAMS, errors) title, desc, dt = ret ad = Ad(key=ad_key, feeds=['manual'], title=title, desc=desc, update_dt=dt, url=ad_url) to_put = [ad] elif 'manual' not in ad.feeds: ad.feeds.insert(0, 'manual') to_put = [ad] # create UserCmt if not cmt: cmt = UserCmt(key=cmt_key, feeds=ad.feeds) to_put.append(cmt) elif 'manual' in cmt.feeds: return self.redirect('/tracker?info=You%20are%20already%20manually%20tracking%20that%20ad.') elif cmt.feeds != ad.feeds: cmt.feeds = ad.feeds to_put.append(cmt) # save the new entities if to_put: db.put(to_put) # redirect the user to the feed page self.redirect('/tracker?info=Added%20Ad%20%23' + str(cid) + '%20to%20your%20manually%20specified%20list.')
def post(self): session = is_logged_in(self) if not session: return self.redirect(REDIR_URL) req = self.request errors = {} new_name = validate_string(req, errors, 'new_name', 'new search name', MAX_FEED_NAME_LEN) if not new_name: new_name = '' if len(errors): return self.redirect_to_self(GET_PARAMS, errors) # update the search name user = User.get_by_key_name(session['my_id']) if not user: logging.error( 'Unable to retrieve user record for a logged in user: %s' % session['my_id']) return self.redirect( '/?err=The service is temporarily unavailable - please try again later.' ) feed_key = self.request.get('f') if feed_key not in user.feeds: return self.redirect( "/tracker&err=You%20can't%20rename%20a%20search%20you%20aren't%20tracking." ) for i in xrange(len(user.feeds)): if user.feeds[i] == feed_key: user.feed_names[i] = new_name break try: user.put() except: logging.error( 'Unable to update user record for logged in user: %s' % session['my_id']) return self.redirect( '/tracker?err=The service is temporarily unavailable - please try again later.' ) # invalidate the memcache entry for this users' feeds if it exists mckey = "user-feeds:%s" % session['my_id'] feed_infos = memcache.delete(mckey) # redirect the user to the feed page self.redirect('/view?t=newest&f=%s' % urllib.quote(feed_key))
def post(self): session = is_logged_in(self) if not session: return req = self.request errors = {} dn = validate_string(req, errors, 'dname', 'display name', 100) email = validate_string(req, errors, 'email', 'email', 100) if len(errors): return self.redirect_to_self(errors) uid = session['my_id'] user = User.get_by_key_name(uid) if user.display_name != dn or user.email != email: str_update = "dn=%s email=%s ==> dn=%s email=%s" % ( user.display_name, user.email, dn, email) user.display_name = dn user.email = email try: user.put() except Exception, e: logging.info("Unable to update user profile: " + str_update) return self.redirect_to_self({ 'err': 'Unable to update your profile. Please try again later' }) # profile has been updated session['my_dname'] = dn session['my_email'] = email logging.info("Updated user profile: " + str_update) memcache.delete('u+c%s' % uid) # clear saved user_info self.redirect( '/profile/update?info=Your%20profile%20has%20been%20updated.')
def post(self): session = is_logged_in(self) if not session: return self.redirect(REDIR_URL) req = self.request errors = {} new_name = validate_string(req, errors, 'new_name', 'new search name', MAX_FEED_NAME_LEN) if not new_name: new_name = '' if len(errors): return self.redirect_to_self(GET_PARAMS, errors) # update the search name user = User.get_by_key_name(session['my_id']) if not user: logging.error('Unable to retrieve user record for a logged in user: %s' % session['my_id']) return self.redirect('/?err=The service is temporarily unavailable - please try again later.') feed_key = self.request.get('f') if feed_key not in user.feeds: return self.redirect("/tracker&err=You%20can't%20rename%20a%20search%20you%20aren't%20tracking.") for i in xrange(len(user.feeds)): if user.feeds[i] == feed_key: user.feed_names[i] = new_name break try: user.put() except: logging.error('Unable to update user record for logged in user: %s' % session['my_id']) return self.redirect('/tracker?err=The service is temporarily unavailable - please try again later.') # invalidate the memcache entry for this users' feeds if it exists mckey = "user-feeds:%s" % session['my_id'] feed_infos = memcache.delete(mckey) # redirect the user to the feed page self.redirect('/view?t=newest&f=%s' % urllib.quote(feed_key))
def post(self): session = is_logged_in(self) if not session: return self.redirect(REDIR_URL) req = self.request errors = {} name = validate_string(req, errors, 'name', 'search name', MAX_FEED_NAME_LEN) if not name: name = '' rss_url = req.get('rss_url') if rss_url: feed_key = parse_rss_url(rss_url) if not feed_key: return self.redirect_to_errors( GET_PARAMS, { 'error_rss_url': '''This URL isn't in the expected form. Please <a href="/contact">send it to us</a> if you think this is a bug.''' }) if len(errors): return self.redirect_to_self(GET_PARAMS, errors) else: city = validate_string(req, errors, 'city', 'city/region', max_len=50) category = validate_string(req, errors, 'category', 'category', 3) area = '' # TODO: add area picker if not CATEGORIES.has_key(category): errors['category'] = 'Please choose a category.' query = validate_string(req, errors, 'query', 'search string', 100, required=False) if not query: query = '' title_only = req.get('title_only') == 'checked' if title_only: stype = 'T' else: stype = 'A' min_cost = validate_int(req, errors, 'min_cost', 'Minimum Cost', 0, None, False) if not min_cost: min_cost = '' max_cost = validate_int(req, errors, 'max_cost', 'Maximum Cost', 0, None, False) if not max_cost: max_cost = '' num_bedrooms = validate_int(req, errors, 'num_bedrooms', 'Number of bedrooms', 1, 8, False) if not num_bedrooms: num_bedrooms = '' cats = req.get('cats') == 'checked' dogs = req.get('dogs') == 'checked' pics = req.get('pics') == 'checked' if len(errors): return self.redirect_to_self(GET_PARAMS, errors) feed_key = Feed.make_key_name(city, category, area, min_cost, max_cost, num_bedrooms, cats, dogs, pics, [], stype, query) # make sure the feed is in the datastore try: feed = Feed.get_or_insert(key_name=feed_key) except Exception, e: logging.error('Unable to create new Feed (%s): %s' % (feed_key, e)) return self.redirect_to_self( GET_PARAMS, { 'err': 'The service is temporarily unavailable - please try again later.' })
def post(self): session = is_logged_in(self) if not session: return self.redirect(REDIR_URL) req = self.request errors = {} ad_url = validate_string(req, errors, 'ad_url', 'Craigslist Ad URL') if ad_url: if ad_url[:7] != 'http://': ad_url = 'http://' + ad_url m = RE_URL_CHECK.match(ad_url) if not m: errors[ 'ad_url'] = 'This URL does not appear to be a valid craigslist.org webpage.' else: m = RE_ID.match(ad_url) if not m: errors['ad_url'] = 'Could not extract the ID from Ad URL' else: cid = int(m.group(1)) if len(errors): return self.redirect_to_self(GET_PARAMS, errors) # efficiency: get Ad and UserCmt at the same time to_put = [] ad_key = db.Key.from_path('Ad', cid) cmt_key = db.Key.from_path('UserCmt', '%s%s' % (session['my_id'], cid)) ad, cmt = db.get([ad_key, cmt_key]) # download the ad if we don't already have it in our db if not ad: ret = self.fetch_and_parse_page(ad_url) if not ret: errors['ad_url'] = 'Unable to download the webpage' return self.redirect_to_self(GET_PARAMS, errors) title, desc, dt = ret ad = Ad(key=ad_key, feeds=['manual'], title=title, desc=desc, update_dt=dt, url=ad_url) to_put = [ad] elif 'manual' not in ad.feeds: ad.feeds.insert(0, 'manual') to_put = [ad] # create UserCmt if not cmt: cmt = UserCmt(key=cmt_key, feeds=ad.feeds) to_put.append(cmt) elif 'manual' in cmt.feeds: return self.redirect( '/tracker?info=You%20are%20already%20manually%20tracking%20that%20ad.' ) elif cmt.feeds != ad.feeds: cmt.feeds = ad.feeds to_put.append(cmt) # save the new entities if to_put: db.put(to_put) # redirect the user to the feed page self.redirect('/tracker?info=Added%20Ad%20%23' + str(cid) + '%20to%20your%20manually%20specified%20list.')