示例#1
0
def wrapper_html(**kwargs):
    request    = kwargs['request']
    service    = kwargs['service'] if 'service' in kwargs else None
    worker     = kwargs['worker']

    if is_authenticated(request):
        required = GenericRequired(request=request, service=service)
             
        if required.success():
            response = worker(required)
            if 'success' in response and response['success']:
                context  = response['template_context']
                template = response['template']
            else:
                context = {}
                context['contract'] = required.get_auth_contract()
                context['fio']      = required.get_auth_contract().fio               
                context['title']   = response['title']
                context['message'] = response['message']
                template           = settings.ERROR_TEMPLATE
        else:
            context = {}
            context['contract'] = required.get_auth_contract()
            context['fio']      = required.get_auth_contract().fio
            context['title']    = required.title
            context['message']  = required.message
            template            = settings.ERROR_TEMPLATE

        #отображаем страницу
        return render(request, template, context)

    else:
        #редирект на страницу авторизации
        return redirect('/login/?next=%s' % request.path)
示例#2
0
def wrapper_json(**kwargs):
    request    = kwargs['request']
    req_params = kwargs['req_params']
    _context   = kwargs['context']
    service    = kwargs['service'] if 'service' in kwargs else None
    worker     = kwargs['worker']

    if is_authenticated(request):
        if _context in ('balance', 'payment'):
            required = BalanceRequired(request=request, req_params=req_params, service=service)

        if _context == 'cdr':
            required = CDRRequired(request=request, req_params=req_params, service='phone')

        if _context == 'generic':
            required = GenericRequired(request=request, req_params=req_params, service=service)

        if _context == 'change_internet_password':
            required = ChangeInternetPasswordRequired(request=request, req_params=req_params, service='internet')

        if _context == 'change_internet_tariff':
            required = ChangeInternetTariffRequired(request=request, req_params=req_params, service='internet')
           
        if required.success():
            response = worker(required)
        else:
            #внутри required произошла ошибка
            response = {'success': False, 'title': required.title, 'message': required.message}

    else:
        #не авторизованный JSON запрос
        response = {'success': False, 'title': u'Вы не авторизованы!', 'message': u'Пожалуйста, авторизуйтесь повторно.' }

    return HttpResponseJSON(response)