Exemplo n.º 1
0
def atom_feed_latest(request, mailbox_slug):
    """
    renders the mailbox as an atom feed
    """
    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)

    if not ctx.user.has_perm(PERM_READ, mb):
        return HttpResponse(status=401)

    etag = get_mailbox_etag(mb)
    cached = check_etag(request, etag)
    if cached is not None: 
        return cached

    # number of entries
    try:
        limit = min(int(request.GET.get('limit', DEFAULT_ATOM_ENTRIES)), 
                    MAX_ATOM_ENTRIES)
    except:
        return HttpResponse(status=400)

    params = {'limit': limit, 
              'include_docs': True,
              'reduce': False,
              'descending': True}

    # starting point in time
    if 'startkey' in request.GET:
        params['startkey'] = request.GET['startkey']

    latest_messages = Message.view(mb, Message.by_timestamp, **params) 
    return _render_atom_feed(request, mb, latest_messages)
Exemplo n.º 2
0
def mailbox_exists(request, mailbox_slug):
    """
    tests existence of a mailbox. 
    returns 200 if the mailbox exists, 404 if not.
    """
    ctx = request.context 
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)
    
    etag = get_mailbox_etag(mb)
    cached = check_etag(request, etag)
    if cached is not None:
        return cached
    
    res = HttpResponse(content_type="text/html")
    res.headers['etag'] = etag
    return res