Пример #1
0
def view(request):
    data = json.loads(request.POST.get('data', '{}'))
    action = data.get('action')
    handler = ACTION_HANDLER_MAP.get(action, None)
    if handler is None:
        return JsonHttpResponse({'error': 'No such action'}, status=400)
    return JsonHttpResponse(handler(data, request))
Пример #2
0
def _api_send_reminder(request):
    if not get_param(request, 'vacancy_id'):
        return JsonHttpResponse({'error': 'missing argument'})
    v = Vacancy.by_id(get_param(request, 'vacancy_id'))
    if not v:
        raise Http404
    if not v.pool.may_manage(request.user):
        raise PermissionDenied
    send_reminder(v, update=False)
    return JsonHttpResponse({'success': True})
Пример #3
0
def _api_close_event(request):
    if not 'id' in request.REQUEST:
        return JsonHttpResponse({'error': 'missing argument'})
    e = subscr_Es.event_by_id(request.REQUEST['id'])
    if not e:
        raise Http404
    if not e.has_write_access(request.user):
        raise PermissionDenied
    e.is_open = False
    e.save()
    return JsonHttpResponse({'success': True})
Пример #4
0
def _api_send_reminder(request):
    if not 'vacancy_id' in request.REQUEST:
        return JsonHttpResponse({'error': 'missing argument'})
    v = Vacancy.by_id(request.REQUEST['vacancy_id'])
    if not v:
        raise Http404
    print v._data
    print v.pool_id
    print v.pool
    if not request.user.cached_groups_names & set(
        ['secretariaat', v.pool.administrator]):
        raise PermissionDenied
    send_reminder(v, update=False)
    return JsonHttpResponse({'success': True})
Пример #5
0
def accounts_api(request):
    if request.user.is_authenticated():
        ret = {'valid': True, 'name': request.user.get_username()}
    else:
        ret = {'valid': False}

    return JsonHttpResponse(ret)
Пример #6
0
def _api_get_email_addresses(request):
    if 'id' not in request.POST:
        return JsonHttpResponse({'error': 'missing arguments'})
    event = subscr_Es.event_by_id(request.POST['id'])
    if not event:
        raise Http404
    if (not event.has_public_subscriptions
            and not event.has_read_access(request.user)):
        raise PermissionDenied
    # XXX We can optimize this query
    return JsonHttpResponse({
        'success':
        True,
        'addresses':
        [s.user.canonical_full_email for s in event.listSubscribed]
    })
Пример #7
0
def _api_change_debit(request):
    if not 'debit' in request.REQUEST or not 'id' in request.REQUEST:
        return JsonHttpResponse({'error': 'missing arguments'})
    subscr = subscr_Es.subscription_by_id(request.REQUEST['id'])
    if not subscr:
        raise Http404
    try:
        d = decimal.Decimal(request.REQUEST['debit'])
    except decimal.InvalidOperation:
        return JsonHttpResponse({'error': 'not a decimal'})
    event = subscr.event
    if not event.has_debit_access(request.user):
        raise PermissionDenied
    subscr.debit = d
    subscr.save()
    return JsonHttpResponse({'success': True})
Пример #8
0
def api(request):
    action = request.POST.get('action')
    if action == 'get-email-addresses':
        return _api_get_email_addresses(request)
    elif action == 'event-set-opened':
        return _api_event_set_opened(request)
    else:
        return JsonHttpResponse({'error': 'unknown action'})
Пример #9
0
def _api_event_set_opened(request):
    if ('id' not in request.POST
            or not isinstance(request.POST['id'], six.string_types)):
        return JsonHttpResponse({'error': 'invalid or missing argument "id"'})
    e = subscr_Es.event_by_id(request.POST['id'])
    if not e:
        raise Http404
    if not e.has_write_access(request.user):
        raise PermissionDenied

    opened = {'true': True, 'false': False}.get(request.POST.get('opened'))
    if opened is True:
        e.open(request.user)
    elif opened is False:
        e.close(request.user)
    else:
        return JsonHttpResponse(
            {'error': 'invalid or missing argument "opened"'})

    return JsonHttpResponse({'success': True})
Пример #10
0
def api(request):
    action = request.REQUEST.get('action')
    if action == 'change-debit':
        return _api_change_debit(request)
    elif action == 'get-email-addresses':
        return _api_get_email_addresses(request)
    elif action == 'close-event':
        return _api_close_event(request)
    elif action == 'confirm-subscription':
        return _api_confirm_subscription(request)
    else:
        return JsonHttpResponse({'error': 'unknown action'})
Пример #11
0
def _api_confirm_subscription(request):
    if not 'id' in request.REQUEST:
        return JsonHttpResponse({'error': 'missing argument'})
    # Find the event and subscription
    event = subscr_Es.event_by_id(request.REQUEST['id'])
    if event is None:
        return JsonHttpResponse({'error': 'event not found'})
    subscription = event.get_subscription_of(request.user)
    if subscription is None:
        return JsonHttpResponse({'error': 'subscription not found'})
    if not event.is_open:
        return JsonHttpResponse({'error': 'event is closed'})
    # Confirm, if not confirmed already
    if subscription.confirmed:
        return JsonHttpResponse({'error': 'already confirmed'})
    subscription.confirmed = True
    subscription.dateConfirmed = datetime.datetime.now()
    subscription.save()
    return JsonHttpResponse({'success': True})
Пример #12
0
def planning_api(request):
    action = request.POST.get('action')
    if action == 'send-reminder':
        return _api_send_reminder(request)
    else:
        return JsonHttpResponse({'error': 'unknown action'})
Пример #13
0
def view(request):
    data = json.loads(request.REQUEST.get('data', {}))
    action = data.get('action')
    handler = ACTION_HANDLER_MAP.get(action, ACTION_HANDLER_MAP[None])
    return JsonHttpResponse(handler(data, request))