示例#1
0
文件: views.py 项目: isergey/libcms
def holdings(request):
    record_id = request.GET.get('recordId', '')
    if not record_id:
        return api_responses.errors_response('recordId params does not exist')

    try:
        response = ruslan_client.get_records(id_list=[record_id], database=HOLDINGS_BASE, opac=True)
    except Exception as e:
        return api_responses.errors_response(e.message)

    return api_responses.response(response)
示例#2
0
文件: views.py 项目: isergey/libcms
def make_reservation(request):
    ruslan_user = get_ruslan_user(request)
    if not ruslan_user:
        return api_responses.errors_response(u'Вы не являетесь читателем')

    if request.method == 'POST':
        make_reservation_form = forms.MakeReservationForm(request.POST)
        if make_reservation_form.is_valid():
            ncip_message = {
                "RequestItem": {
                    "UserId": {
                        "AgencyId": {
                            "value": ORG_CODES[make_reservation_form.cleaned_data['org']]
                        },
                        "UserIdentifierValue": ruslan_user.username
                    },
                    "BibliographicId": {
                        "BibliographicRecordId": {
                            "BibliographicRecordIdentifier": make_reservation_form.cleaned_data['record_id'],
                            "AgencyId": {
                                "value": ORG_CODES[make_reservation_form.cleaned_data['org']]
                            }
                        }
                    },
                    "RequestType": {
                        "value": u"Hold",
                        "Scheme": u"http://www.niso.org/ncip/v1_0/imp1/schemes/requesttype/requesttype.scm"
                    },
                    "RequestScopeType": {
                        "value": u"Bibliographic Item",
                        "Scheme": u"http://www.niso.org/ncip/v1_0/imp1/schemes/requestscopetype/requestscopetype.scm"
                    },
                    "PickupLocation": {
                        "value": u'%s/%s' % (make_reservation_form.cleaned_data['org'], make_reservation_form.cleaned_data['branch'])
                    }
                }
            }

            response = ruslan_client.send_ncip_message(ncip_message)
            response_dict = response.json()
            problem = response_dict.get('RequestItemResponse', {}).get('Problem', {})
            if problem:
                message = u'Ошибка при бронировании'
                problem_detail = response_dict.get('RequestItemResponse', {}).get('Problem', {}).get('ProblemDetail', '');
                if problem_detail.startswith('220'):
                    message = u'Превышен лимит заказов. Посмотреть текущие заказы можно в разделе "Мои заказы"'
                    return api_responses.error_response(api_errors.Error(code='220', message=message))
                return api_responses.error_response(api_errors.Error(code='0', message=message))
            return api_responses.response({
                'status': 'ok',
            })
        else:
            return api_responses.error_response(api_errors.FormError.from_form(name='make_reservation_form', django_form=make_reservation_form))
示例#3
0
def holdings(request):
    record_id = request.GET.get('recordId', '')
    if not record_id:
        return api_responses.errors_response('recordId params does not exist')

    try:
        response = ruslan_client.get_records(id_list=[record_id],
                                             database=HOLDINGS_BASE,
                                             opac=True)
    except Exception as e:
        return api_responses.errors_response(e.message)

    return api_responses.response(response)
示例#4
0
def get_config(request):
    is_reader = False
    if get_ruslan_user(request):
        is_reader = True

    response = {
        'can_order_branches': CAN_ORDER_BRANCHES,
        'is_reader': is_reader,
        'urls': {
            'holdings': reverse('ruslan_cabinet:api:holdings'),
            'make_reservation': reverse('ruslan_cabinet:api:make_reservation')
        }
    }
    return api_responses.response(response)
示例#5
0
文件: views.py 项目: isergey/libcms
def get_config(request):
    is_reader = False
    if get_ruslan_user(request):
        is_reader = True

    response = {
        'can_order_branches': CAN_ORDER_BRANCHES,
        'is_reader': is_reader,
        'urls': {
            'holdings': reverse('ruslan_cabinet:api:holdings'),
            'make_reservation': reverse('ruslan_cabinet:api:make_reservation')
        }
    }
    return api_responses.response(response)
示例#6
0
def make_reservation(request):
    ruslan_user = get_ruslan_user(request)
    if not ruslan_user:
        return api_responses.errors_response(u'Вы не являетесь читателем')

    if request.method == 'POST':
        make_reservation_form = forms.MakeReservationForm(request.POST)
        if make_reservation_form.is_valid():
            ncip_message = {
                "RequestItem": {
                    "UserId": {
                        "AgencyId": {
                            "value":
                            ORG_CODES[
                                make_reservation_form.cleaned_data['org']]
                        },
                        "UserIdentifierValue": ruslan_user.username
                    },
                    "BibliographicId": {
                        "BibliographicRecordId": {
                            "BibliographicRecordIdentifier":
                            make_reservation_form.cleaned_data['record_id'],
                            "AgencyId": {
                                "value":
                                ORG_CODES[
                                    make_reservation_form.cleaned_data['org']]
                            }
                        }
                    },
                    "RequestType": {
                        "value":
                        u"Hold",
                        "Scheme":
                        u"http://www.niso.org/ncip/v1_0/imp1/schemes/requesttype/requesttype.scm"
                    },
                    "RequestScopeType": {
                        "value":
                        u"Bibliographic Item",
                        "Scheme":
                        u"http://www.niso.org/ncip/v1_0/imp1/schemes/requestscopetype/requestscopetype.scm"
                    },
                    "PickupLocation": {
                        "value":
                        u'%s/%s' %
                        (make_reservation_form.cleaned_data['org'],
                         make_reservation_form.cleaned_data['branch'])
                    }
                }
            }

            response = ruslan_client.send_ncip_message(ncip_message)
            response_dict = response.json()
            problem = response_dict.get('RequestItemResponse',
                                        {}).get('Problem', {})
            if problem:
                message = u'Ошибка при бронировании'
                problem_detail = response_dict.get('RequestItemResponse',
                                                   {}).get('Problem', {}).get(
                                                       'ProblemDetail', '')
                if problem_detail.startswith('220'):
                    message = u'Превышен лимит заказов. Посмотреть текущие заказы можно в разделе "Мои заказы"'
                    return api_responses.error_response(
                        api_errors.Error(code='220', message=message))
                return api_responses.error_response(
                    api_errors.Error(code='0', message=message))
            return api_responses.response({
                'status': 'ok',
            })
        else:
            return api_responses.error_response(
                api_errors.FormError.from_form(
                    name='make_reservation_form',
                    django_form=make_reservation_form))
示例#7
0
def index(request):
    return api_responses.response({'status': 'ok'})
示例#8
0
文件: views.py 项目: isergey/libcms
def index(request):
    return api_responses.response({
        'status': 'ok'
    })