Example #1
0
 def _get_adverts(self, params):
     '''
     Возвращает объявления по критериям.
     @return: list
     '''
     processor = AdvertProcessor()
     params['publication_date'] = {'$gt': datetime.utcnow() - timedelta(days=self.ADVERT_MAX_AGE)}
     return processor.get_by_info(params)
Example #2
0
def index():
    '''
    Главная страница.
    '''
    processor = AdvertProcessor()
    aggregated = processor.get_aggregated()
    graph_url = url_for('graph', type=request.args.get('type') or 'all', district=request.args.get('district') or 'all',
                        floor_number=request.args.get('floor_number') or 0, room_count=request.args.get('room_count') or 0)
    return render_template('index.html', debug=settings.DEBUG, aggregated=aggregated, graph_url=graph_url)
Example #3
0
def _validate_graph_params(params):
    '''
    Проверяет параметры графика.
    '''
    processor = AdvertProcessor()
    aggregated = processor.get_aggregated()
    if not _validate_graph_param(aggregated, params, 'type', 'all'):
        return False
    if not _validate_graph_param(aggregated, params, 'district', 'all'):
        return False
    if not _validate_graph_param(aggregated, params, 'floor_number', 0):
        return False
    if not _validate_graph_param(aggregated, params, 'room_count', 0):
        return False
    return True
Example #4
0
def save_advert(advert):
    """
    Сохраняет объявление в БД.
    Возвращает, новое ли объявление.
    @param advert: Advert
    @return: bool
    """
    processor = AdvertProcessor()
    stored = processor.get_by_external_id(advert.external_id)
    if stored is not None:
        logger.debug("advert with external id %s found", advert.external_id)
        advert.id = stored.id
    processor.save(advert)
    logger.debug("advert with external id %s saved", advert.external_id)
    return stored is None