Пример #1
0
 def apply(self):
     """filtering by Block.
     """
     block = self.location_object
     search_buf = make_search_buffer(block.location.centroid, self.block_radius)
     self.qs = self.qs.filter(location__bboverlaps=search_buf)
     return self.qs
Пример #2
0
 def apply(self):
     """filtering by Block.
     """
     block = self.location_object
     search_buf = make_search_buffer(block.location.centroid,
                                     self.block_radius)
     self.qs = self.qs.filter(location__bboverlaps=search_buf)
     return self.qs
Пример #3
0
def email_for_subscription(alert, start_date, frequency):
    """
    Returns a (place_name, text, html) tuple for the given EmailAlert
    object and date.
    """
    start_datetime = datetime.datetime(start_date.year, start_date.month, start_date.day)
    yesterday = datetime.date.today() - datetime.timedelta(days=1)
    end_datetime = datetime.datetime.combine(yesterday, datetime.time(23, 59, 59, 9999)) # the end of yesterday

    from ebpub.utils.view_utils import get_schema_manager_for_user
    manager = get_schema_manager_for_user(alert.user)
    allowed_schemas = manager.allowed_schema_ids()
    qs = NewsItem.objects.select_related().filter(schema__id__in=allowed_schemas)
    if alert.include_new_schemas:
        # We saved an opt-out list.
        if alert.schemas:
            qs = qs.exclude(schema__id__in=alert.schemas.split(','))
    else:
        # We saved an opt-in list.
        if alert.schemas:
            qs = qs.filter(schema__id__in=alert.schemas.split(','))

    if alert.block_center:
        place = alert._get_block()
        place_name, place_url = place.pretty_name, place.url()
        search_buffer = make_search_buffer(place.geom.centroid, alert.radius)
        qs = qs.filter(location__bboverlaps=search_buffer)

    elif alert.location:
        place_name, place_url = alert.location.name, alert.location.url()
        place = alert.location
        qs = qs.filter(newsitemlocation__location__id=alert.location.id)

    # Order by schema__id to group schemas together.
    news_qs = qs.filter(schema__is_event=False,
                        pub_date__range=(start_datetime, end_datetime),
                        ).order_by('-schema__importance', 'schema__id', '-item_date', '-id')
    events_qs = qs.filter(schema__is_event=True,
                         pub_date__range=(start_datetime, end_datetime),
                         ).order_by('-schema__importance', 'schema__id', 'item_date', 'id')

    news_list = list(news_qs)
    events_list = list(events_qs)
    if not (news_list or events_list):
        raise NoNews
    schemas_used = set([ni.schema for ni in news_list + events_list])
    populate_attributes_if_needed(news_list, list(schemas_used))
    populate_attributes_if_needed(events_list, list(schemas_used))
    newsitem_groups = ({'title': 'Recent', 'newsitems': news_list},
                       {'title': 'Upcoming', 'newsitems': events_list})
    text, html = email_text_for_place(alert, place, place_name, place_url, newsitem_groups, start_date, frequency)
    return place_name, text, html
Пример #4
0
 def newsitems_for_obj(self, obj, qs, block_radius):
     search_buffer = make_search_buffer(obj.location.centroid, block_radius)
     return qs.filter(location__bboverlaps=search_buffer)
Пример #5
0
 def newsitems_for_obj(self, obj, qs, block_radius):
     search_buffer = make_search_buffer(obj.location.centroid, block_radius)
     return qs.filter(location__bboverlaps=search_buffer)