示例#1
0
    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.'})
示例#2
0
def parse_rss_url(url):
    """Parses a RSS URL from Craigslist and returns the Feed key which describes it."""
    m = RE_RSS_URL.match(url)
    if not m:
        return None
    groups = m.groups()
    city, cat, area, qparams = groups[0], groups[2], groups[4], groups[5]
    cat2, min_ask, max_ask, nb, c, d, hp, n, st, q = parse_rss_url_params(qparams)
    if cat2:
        cat = cat2
    return Feed.make_key_name(city, cat, area, min_ask, max_ask, nb, c, d, hp, n, st, q)
示例#3
0
def parse_rss_url(url):
    """Parses a RSS URL from Craigslist and returns the Feed key which describes it."""
    m = RE_RSS_URL.match(url)
    if not m:
        return None
    groups = m.groups()
    city, cat, area, qparams = groups[0], groups[2], groups[4], groups[5]
    cat2, min_ask, max_ask, nb, c, d, hp, n, st, q = parse_rss_url_params(
        qparams)
    if cat2:
        cat = cat2
    return Feed.make_key_name(city, cat, area, min_ask, max_ask, nb, c, d, hp,
                              n, st, q)
示例#4
0
    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.'
                })