def test_excludes_inactive(self):
        from datetime import datetime
        from datetime import timedelta
        from opencore.utils import coarse_datetime_repr
        now = datetime.now()
        today = now.today()
        six_months_ago = today - timedelta(days=180)
        self._set_TODAY(today)
        self._register()
        context = testing.DummyModel()
        profiles = context['profiles'] = testing.DummyModel()
        profiles[None] = testing.DummyModel()
        catalog = context.catalog = oitesting.DummyCatalog(
                                      {1: '/foo', 2: '/bar'})
        foo = testing.DummyModel(content_modified=now - timedelta(1))
        bar = testing.DummyModel(content_modified=now - timedelta(32))
        testing.registerModels({'/foo': foo,
                                '/bar': bar,
                               })
        request = testing.DummyRequest()

        info = self._callFUT(context, request)

        self.assertEqual(len(catalog.queries), 1)
        query = catalog.queries[0]
        self.assertEqual(query['content_modified'],
                         (coarse_datetime_repr(six_months_ago), None))

        communities = info['communities']
        self.assertEqual(len(communities), 2)
        self.assertEqual(communities[0].context, foo)
        self.assertEqual(communities[1].context, bar)
        self.failUnless(info['actions'])
        _checkCookie(request, 'active')
Exemple #2
0
 def test_w_date(self):
     import datetime
     from opencore.utils import coarse_datetime_repr
     context = testing.DummyModel()
     today = datetime.date.today()
     self._decorate(context, today)
     result = self._callFUT(context, None)
     self.assertEqual(result, coarse_datetime_repr(today))
Exemple #3
0
def show_active_communities_view(context, request):
    _set_cookie_via_request(request, 'active')

    six_months_ago = _today() - datetime.timedelta(days=180)
    content_modified = (coarse_datetime_repr(six_months_ago), None)

    return show_communities_view_helper(context,
                                         request, prefix='Active ',
                                         content_modified=content_modified,
                                        )
Exemple #4
0
def make_query(context, request, search_interfaces=[]):
    """Given a search request, return a catalog query and a list of terms.
    """
    params = request.params
    query = {}
    terms = []
    body = params.get('body')
    if body:
        query['texts'] = body
        query['sort_index'] = 'texts'
        terms.append(body)

    creator = params.get('creator')
    if creator:
        userids = list(_iter_userids(context, request, creator))
        query['creator'] = {
            'query': userids,
            'operator': 'or',
            }
        terms.append(creator)

    types = params.getall('types')
    if types:
        type_dict = {}
        for t in get_content_types():
            type_dict[interface_id(t)] = t
        ifaces = [type_dict[name] for name in types]
        query['interfaces'] = {
            'query': ifaces,
            'operator': 'or',
            }
        terms.extend(iface.getTaggedValue('name') for iface in ifaces)
    else:
        query['interfaces'] = {
            'query': search_interfaces,
            'operator': 'or'
            }

    tags = params.getall('tags')
    if tags:
        query['tags'] = {
            'query': tags,
            'operator': 'or',
            }
        terms.extend(tags)

    topics = params.getall('topics')
    if topics:
        query['topics'] = {
            'query': topics,
            'operator': 'or',
            }
        terms.extend(topics)

    year = params.get('year')
    if year:
        year = int(year)
        begin = coarse_datetime_repr(datetime.datetime(year, 1, 1))
        end = coarse_datetime_repr(datetime.datetime(year, 12, 31, 12, 59, 59))
        query['creation_date'] = (begin, end)
        terms.append(year)

    return query, terms
Exemple #5
0
def _get_date_or_datetime(object, attr, default):
    d = getattr(object, attr, None)
    if (isinstance(d, datetime.datetime) or
        isinstance(d, datetime.date)):
        return coarse_datetime_repr(d)
    return default