Example #1
0
def groups(request):
    c = {}
    resp = helix_cli.request(FilterGroupForm.get_services_req(request), request)
    c.update(process_helix_response(resp, "services", "services_error"))
    srvs = resp.get("services", [])
    srvs_idx = {}
    for s in srvs:
        srvs_idx[s["id"]] = s
    c["services_idx"] = srvs_idx

    if len(request.GET) == 0 or (len(request.GET) == 1 and "pager_offset" in request.GET):
        # setting default is_active value to True
        form = FilterGroupForm({"is_active": "all"}, request=request)
    else:
        form = FilterGroupForm(request.GET, request=request)

    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request(), request)
        form.update_total(resp)
        c.update(process_helix_response(resp, "groups", "groups_error"))
        c["pager"] = form.pager

    c["form"] = form

    return render_to_response("group/list.html", c, context_instance=RequestContext(request))
Example #2
0
def users(request):
    c = {}
    resp = helix_cli.request(FilterUserForm.get_active_groups_req(request), request)
    c.update(process_helix_response(resp, "groups", "groups_error"))
    groups_idx = build_index(resp, "groups")
    c["groups_idx"] = groups_idx

    resp = helix_cli.request(FilterUserForm.get_services_req(request), request)
    c.update(process_helix_response(resp, "services", "services_error"))
    c["services_idx"] = build_index(resp, "services")

    if len(request.GET) == 0 or (len(request.GET) == 1 and "pager_offset" in request.GET):
        # setting default is_active value to True
        form = FilterUserForm({"is_active": "all"}, request=request)
    else:
        form = FilterUserForm(request.GET, request=request)

    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request(), request)
        form.update_total(resp)
        users_list = resp.get("users", [])
        _calculate_summary_user_rights(users_list, groups_idx)
        c.update(process_helix_response(resp, "users", "users_error"))
        c["pager"] = form.pager
    c["form"] = form
    return render_to_response("user/list.html", c, context_instance=RequestContext(request))
Example #3
0
def modify_used_currencies(request):
    c = {}
    resp = helix_cli.request(BillingForm.get_currencies_req(request))
    c.update(process_helix_response(resp, 'currencies', 'currencies_error'))
    currencies = resp.get('currencies', [])

    if request.method == 'POST':
        form = ModifyUsedCurrenciesForm(request.POST, currencies=currencies, request=request)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request())
            form.handle_errors(resp)
            if resp['status'] == 'ok':
                if request.POST.get('stay_here', '0') != '1':
                    return HttpResponseRedirect('/billing/get_used_currencies/')
    else:
        resp = helix_cli.request(BillingForm.get_used_currencies_req(request))
        c.update(process_helix_response(resp, 'currencies', 'used_currencies_error'))
        used_currs = resp.get('currencies', [])
        used_currs_codes = [curr['code'] for curr in used_currs]
        d = {'new_currencies_codes': used_currs_codes}
        form = ModifyUsedCurrenciesForm(d, currencies=currencies, request=request)
        if form.is_valid():
            form.handle_errors(resp)
    c['form'] = form
    return render_to_response('currency/modify_used_currencies.html', c,
        context_instance=RequestContext(request))
Example #4
0
def user_info(request, id):  # @ReservedAssignment
    id = int(id)  # @ReservedAssignment
    c = {}
    resp = helix_cli.request(HelixwebRequestForm.get_users_req(request, [id]), request)
    c.update(process_helix_response(resp, "users", "users_error"))
    c["user"] = _extract_user(resp)
    return render_to_response("user/user_info.html", c, context_instance=RequestContext(request))
Example #5
0
def _add_money(request, form_cls, template, redirect_url, user_id, balance_id):
    c = {}
    c['action'] = form_cls.action
    c['user_id'] = user_id
    resp = helix_cli.request(form_cls.get_balance_req(request, balance_id))
    c.update(process_helix_response(resp, 'balances', 'balances_error'))
    if resp['total'] != 1:
        balance = {}
    else:
        balance = resp['balances'][0]
    c['balance'] = balance
    currency_code = balance.get('currency_code')
    if request.method == 'POST':
        form = form_cls(request.POST, request=request,
            balance_id=balance_id, currency_code=currency_code)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request())
            form.handle_errors(resp)
            if resp['status'] == 'ok':
                if request.POST.get('stay_here', '0') != '1':
                    return HttpResponseRedirect(redirect_url)
    else:
        form = form_cls(balance_id=balance_id, currency_code=currency_code,
            request=request)
    c['form'] = form
    return render_to_response(template, c,
        context_instance=RequestContext(request))
Example #6
0
def used_currencies(request):
    c = {}
    form = FilterUsedCurrenciesForm(request=request)
    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request())
        c.update(process_helix_response(resp, 'currencies', 'currencies_error'))
    return render_to_response('currency/used_list.html', c,
        context_instance=RequestContext(request))
Example #7
0
def balances_self(request):
    c = {}
    c['action'] = 'get_balances_self'
    resp = helix_cli.request(BalanceForm.get_balances_self_req(request))
    c.update(process_helix_response(resp, 'balances', 'balances_error'))
    balances = resp.get('balances', [])
    return render_to_response('balance/balances_self.html', c,
        context_instance=RequestContext(request))
Example #8
0
def user_balances(request, user_id):
    c = {}
    c['action'] = 'get_balances'
    c['user_id'] = user_id
    resp = helix_cli.request(BalanceForm.get_user_balances_req(request, user_id))
    c.update(process_helix_response(resp, 'balances', 'balances_error'))
    balances = resp.get('balances', [])
    return render_to_response('user/balances.html', c,
        context_instance=RequestContext(request))
Example #9
0
def get_tariffs(request):
    c = {}
    form = FilterTariffsForm(request.GET, request=request)
    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request())
        c.update(process_helix_response(resp, 'tariffs', 'tariffs_error'))
    c['form'] = form
    return render_to_response('tariff/list.html', c,
        context_instance=RequestContext(request))
Example #10
0
def _get_user_info(request, c, id):  # @ReservedAssignment
    resp = helix_cli.request(ModifyUserForm.get_users_req(id, request), request)
    c.update(process_helix_response(resp, "users", "users_error"))
    user = {}
    if "users" in resp:
        if len(resp["users"]) != 1:
            c["users_error"] = "HELIXAUTH_USER_ACCESS_DENIED"
        else:
            user = resp["users"][0]
    return user
Example #11
0
def balances(request):
    c = {}
    resp = helix_cli.request(FilterBalanceForm.get_used_currencies_req(request))
    c.update(process_helix_response(resp, 'currencies', 'currencies_error'))
    currencies = resp.get('currencies', [])
    if len(request.GET) == 0 or (len(request.GET) == 1 and 'pager_offset' in request.GET):
        # setting default is_active value to True
        form = FilterBalanceForm({'is_active': 'all'}, currencies=currencies, request=request)
    else:
        form = FilterBalanceForm(request.GET, currencies=currencies, request=request)

    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request())
        form.update_total(resp)
        c.update(process_helix_response(resp, 'balances', 'balances_error'))
        balances = resp.get('balances', [])
        c['pager'] = form.pager
    c['form'] = form
    return render_to_response('balance/list.html', c,
        context_instance=RequestContext(request))
Example #12
0
def get_tariffication_objects(request):
    c = {}
    form = FilterTarifficationObjectsForm(request.GET, request=request)

    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request())
        form.update_total(resp)
        c.update(process_helix_response(resp, 'tariffication_objects',
            'tariffication_objects_error'))
        c['pager'] = form.pager
    c['form'] = form
    return render_to_response('tariffication_object/list.html', c,
        context_instance=RequestContext(request))
Example #13
0
def notifications(request):
    c = {}
    if len(request.GET) == 0 or (len(request.GET) == 1 and "pager_offset" in request.GET):
        # setting default is_active value to True
        form = FilterNotificationForm({"type": None}, request=request)
    else:
        form = FilterNotificationForm(request.GET, request=request)

    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request(), request)
        form.update_total(resp)
        c.update(process_helix_response(resp, "notifications", "notifications_error"))
        c["pager"] = form.pager

    c["form"] = form

    return render_to_response("notification/list.html", c, context_instance=RequestContext(request))
Example #14
0
def add_user(request):
    c = {}
    resp = helix_cli.request(AddUserForm.get_active_groups_req(request), request)
    c.update(process_helix_response(resp, "groups", "groups_error"))
    groups = resp.get("groups", [])
    if request.method == "POST":
        form = AddUserForm(request.POST, groups=groups, request=request)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request(), request)
            form.handle_errors(resp)
            if resp["status"] == "ok":
                if request.POST.get("stay_here", "0") != "1":
                    return HttpResponseRedirect("/auth/get_users/")
    else:
        form = AddUserForm(groups=groups, request=request)
    c["form"] = form
    return render_to_response("user/add.html", c, context_instance=RequestContext(request))
Example #15
0
def services(request):
    c = {}
    if len(request.GET) == 0 or (len(request.GET) == 1 and "pager_offset" in request.GET):
        # setting default is_active value to True
        form = FilterServiceForm({"is_active": "all"}, request=request)
    else:
        form = FilterServiceForm(request.GET, request=request)

    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request(), request)
        form.update_total(resp)
        c.update(process_helix_response(resp, "services", "services_error"))
        c["pager"] = form.pager

    c["filter_service_form"] = form

    return render_to_response("service/list.html", c, context_instance=RequestContext(request))
Example #16
0
def add_group(request):
    c = {}
    resp = helix_cli.request(AddGroupForm.get_services_req(request), request)
    services = resp.get("services", [])
    c.update(process_helix_response(resp, "services", "services_error"))

    if request.method == "POST":
        form = AddGroupForm(request.POST, services=services, request=request)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request(), request)
            form.handle_errors(resp)
            if resp["status"] == "ok":
                if request.POST.get("stay_here", "0") != "1":
                    return HttpResponseRedirect("/auth/get_groups/")
    else:
        form = AddGroupForm(services=services, request=request)

    c["add_group_form"] = form
    return render_to_response("group/add.html", c, context_instance=RequestContext(request))
Example #17
0
def user_action_logs(request, user_id):
    c = {}
    c['action'] = FilterUserActionLogsForm.action
    c['user_id'] = user_id
    _prepare_action_logs_context(c)
    if request.method == 'GET':
        form = FilterUserActionLogsForm(request.GET, request=request, id=user_id)
    else:
        form = FilterUserActionLogsForm({}, request=request, id=user_id)
    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request())
        form.update_total(resp)
        if 'action_logs' in resp:
            resp['action_logs'] = map(_prepare_action_log, resp['action_logs'])
        c.update(process_helix_response(resp, 'action_logs', 'action_logs_error'))
        c['pager'] = form.pager
    c['form'] = form
    return render_to_response('user/billing_user_action_logs.html', c,
        context_instance=RequestContext(request))
Example #18
0
def user_action_logs(request, id):  # @ReservedAssignment
    c = {}
    c["action"] = FilterUserActionLogsForm.action
    _prepare_action_logs_context(c)
    user = _get_user_info(request, c, id)
    c["user"] = user
    if request.method == "GET":
        form = FilterUserActionLogsForm(request.GET, request=request, id=id)
    else:
        form = FilterUserActionLogsForm({}, request=request, id=id)
    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request(), request)
        form.update_total(resp)
        if "action_logs" in resp:
            resp["action_logs"] = map(_prepare_action_log, resp["action_logs"])
        c.update(process_helix_response(resp, "action_logs", "action_logs_error"))
        c["pager"] = form.pager
    c["form"] = form
    return render_to_response("user/user_action_logs.html", c, context_instance=RequestContext(request))
Example #19
0
def modify_group(request, id):  # @ReservedAssignment
    c = {}
    resp = helix_cli.request(ModifyGroupForm.get_services_req(request), request)
    c.update(process_helix_response(resp, "services", "services_error"))
    services = resp.get("services", [])

    if request.method == "POST":
        form = ModifyGroupForm(request.POST, services=services, request=request)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request(), request)
            form.handle_errors(resp)
            if resp["status"] == "ok":
                if request.POST.get("stay_here", "0") != "1":
                    return HttpResponseRedirect("/auth/get_groups/")
    else:
        resp = helix_cli.request(ModifyGroupForm.get_by_id_req(id, request), request)
        form = ModifyGroupForm.from_get_groups_helix_resp(resp, request, services)
        if form.is_valid():
            form.handle_errors(resp)
    c["form"] = form
    return render_to_response("group/modify.html", c, context_instance=RequestContext(request))
Example #20
0
def _add_balance(request, template, redirect_url, user_id=None):
    c = {}
    c['user_id'] = user_id
    c['action'] = AddBalanceForm.action
    resp = helix_cli.request(AddBalanceForm.get_used_currencies_req(request))
    c.update(process_helix_response(resp, 'currencies', 'currencies_error'))
    currencies = resp.get('currencies', [])
    if request.method == 'POST':
        form = AddBalanceForm(request.POST, currencies=currencies, request=request,
            user_id=user_id)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request())
            form.handle_errors(resp)
            if resp['status'] == 'ok':
                if request.POST.get('stay_here', '0') != '1':
                    return HttpResponseRedirect(redirect_url)
    else:
        form = AddBalanceForm(currencies=currencies, request=request, user_id=user_id)
    c['form'] = form
    return render_to_response(template, c,
        context_instance=RequestContext(request))
Example #21
0
def _modify_balance(request, template, redirect_url, balance_id, user_id=None):
    c = {}
    c['action'] = ModifyBalanceForm.action
    c['user_id'] = user_id
    if request.method == 'POST':
        form = ModifyBalanceForm(request.POST, request=request)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request())
            form.handle_errors(resp)
            if resp['status'] == 'ok':
                if request.POST.get('stay_here', '0') != '1':
                    return HttpResponseRedirect(redirect_url)
    else:
        resp = helix_cli.request(ModifyBalanceForm.get_balance_req(request, balance_id))
        c.update(process_helix_response(resp, 'balances', 'balances_error'))
        balance_info = {}
        if resp['status'] == 'ok' and len(resp['balances']) > 0:
            balance_info = resp['balances'][0]
        form = ModifyBalanceForm.from_balance_info(balance_info, request)
    c['form'] = form
    return render_to_response(template, c,
        context_instance=RequestContext(request))
Example #22
0
def modify_user(request, id):  # @ReservedAssignment
    c = {}
    c["action"] = ModifyUserForm.action
    resp = helix_cli.request(ModifyUserForm.get_active_groups_req(request), request)
    c.update(process_helix_response(resp, "groups", "groups_error"))
    groups = resp.get("groups", [])
    user = _get_user_info(request, c, id)
    c["user"] = user
    if request.method == "POST":
        form = ModifyUserForm(request.POST, groups=groups, request=request)
        if form.is_valid():
            resp = helix_cli.request(form.as_helix_request(), request)
            form.handle_errors(resp)
            if resp["status"] == "ok":
                new_login = request.POST.get("new_login")
                if new_login:
                    c["user"]["login"] = new_login
                if request.POST.get("stay_here", "0") != "1":
                    return HttpResponseRedirect("/auth/user_info/%s" % user["id"])
    else:
        form = ModifyUserForm.from_user_info(user, groups, request)
    c["form"] = form
    return render_to_response("user/modify_user.html", c, context_instance=RequestContext(request))
Example #23
0
def _transactions(request, form_cls, template, user_id, balance_id):
    c = {}
    c['action'] = form_cls.action
    c['user_id'] = user_id
    c['balance_id'] = balance_id

    if len(request.GET) == 0 or (len(request.GET) == 1 and 'pager_offset' in request.GET):
        form = form_cls({'user_id': user_id, 'balance_id': balance_id},
            request=request)
    else:
        form = form_cls(request.GET, request=request)

    if form.is_valid():
        resp = helix_cli.request(form.as_helix_request())
        form.update_total(resp)
        c.update(process_helix_response(resp, 'transactions', 'transactions_error'))
        transactions = resp.get('transactions', [])
        for transaction in transactions:
            _prepare_date(transaction, 'creation_date')
        c['transactions'] = transactions
        c['pager'] = form.pager
    c['form'] = form
    return render_to_response(template, c,
        context_instance=RequestContext(request))