Пример #1
0
def _create_subscriptions_json(request, mailbox_slug):
    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)

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

    try:
        params = json.loads(request.body)
    except:
        return HttpResponse(status=400)

    if not isinstance(params, dict):
        return HttpResponse(status=400)

    try:
        sub_type = params.get('type')
        del params['type']
        
        sub = Subscription.create_type(sub_type)
        sub.user_update(params)
        sub.store(mb)
        return HttpResponse(json.dumps({'slug': sub.id}),
                            content_type='application/json',
                            status=201)
    except: 
        return HttpResponse(status=400)
Пример #2
0
def manage_subscriptions(request, mailbox_slug):
    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 handle_unauth(request)

    info = MailboxInfo.get(mb)

    subs = []
    for sub in Subscription.view(mb, Subscription.by_type,
                                 include_docs=True):
        subs.append(sub)

    ctx = {}
    ctx['mailbox'] = mb
    ctx['mailbox_slug'] = mailbox_slug
    ctx['mailbox_title'] = info.title or mailbox_slug
    ctx['subscriptions'] = sorted(subs, key=attrgetter('title'))

    if request.headers.get('X-Requested-With') == 'XMLHttpRequest': 
        return render_to_response('radar/subscriptions_table.html', 
                                  TemplateContext(request, ctx))
    else: 
        return render_to_response('radar/subscriptions.html', 
                                  TemplateContext(request, ctx))
Пример #3
0
def _subscription_exists(request, mailbox_slug, sub_slug):
    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)
    sub = Subscription.load(mb, sub_slug)
    if sub is None or sub.type != SUBSCRIPTION_TYPE: 
        return HttpResponse(status=404)
    return HttpResponse()
Пример #4
0
def _get_subscription_json(request, mailbox_slug, sub_slug):
    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)

    sub = Subscription.load(mb, sub_slug)
    if sub is None or sub.type != SUBSCRIPTION_TYPE: 
        return HttpResponse(status=404)

    return HttpResponse(json.dumps(_sub_json(sub)), 
                        content_type="application/json")
Пример #5
0
def _get_subscriptions_json(request, mailbox_slug):

    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)

    subs = []
    for sub in Subscription.view(mb, Subscription.by_type,
                                 include_docs=True):
        subs.append(_sub_json(sub))

    return HttpResponse(json.dumps(subs),
                        content_type="application/json")
Пример #6
0
def _delete_subscription(request, mailbox_slug, sub_slug):
    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)

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

    sub = Subscription.load(mb, sub_slug)
    if sub is None or sub.type != SUBSCRIPTION_TYPE: 
        return HttpResponse(status=404)

    try:
        del mb[sub.id]
    except ResourceNotFound: 
        return HttpResponse(status=404)

    return HttpResponse()
Пример #7
0
def _update_subscription(request, mailbox_slug, sub_slug):
    ctx = request.context
    mb = ctx.get_mailbox(mailbox_slug)
    if mb is None:
        return HttpResponse(status=404)

    sub = Subscription.load(mb, sub_slug)
    if sub is None or sub.type != SUBSCRIPTION_TYPE: 
        return HttpResponse(status=404)

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


    params = _get_params_by_ct(request)
    try:
        sub.user_update(params)
        sub.store(mb)
        return HttpResponse()
    except:
        return HttpResponse(status=400)