Пример #1
0
def _make_mba_order(gen_id, user_id, order_type, order_manager_id, copy_info=u'', comments=u''):
    user_id = str(user_id)
    order_types = ('delivery', 'copy')
    if order_type not in order_types:
        raise ValueError(u'Wrong order type ' + str(order_type))

    doc = None
    try:
        doc = Record.objects.using('records').get(gen_id=gen_id)
    except Record.DoesNotExist:
        pass
    if not doc:
        try:
            doc = Ebook.objects.using('records').get(gen_id=gen_id)
        except Ebook.DoesNotExist:
            raise MBAOrderException(u'Record not founded')

    order_manager = OrderManager(settings.ORDERS['db_catalog'], settings.ORDERS['rdx_path'])

    library = None
    try:
        library = Library.objects.get(id=order_manager_id)
    except Library.DoesNotExist:
        raise MBAOrderException(u'Library not founded')

    def get_first_recivier_code(library):
        ancestors = library.get_ancestors()
        for ancestor in ancestors:
            if ancestor.ill_service and ancestor.ill_service.strip():
                return ancestor.code
        return None

    # если у библиотеки указан ill адрес доставки, то пересылаем заказ ей
    if library.ill_service and library.ill_service.strip():
        manager_id = ''
        reciver_id = library.code

    # иначе ищем родителя, у которого есть адрес доставки
    else:
        manager_id = library.code
        reciver_id = get_first_recivier_code(library)

        if not reciver_id:
            raise MBAOrderException(u'Library cant manage orders')

    sender_id = user_id
    copy_info = copy_info

    order_manager.order_document(
        order_type=order_type,
        sender_id=sender_id,
        reciver_id=reciver_id,
        manager_id=manager_id,
        xml_record=doc.content,
        comments=comments,
        copy_info=copy_info
    )
Пример #2
0
def delete_order(request, order_id=''):
    order_manager = OrderManager(settings.ORDERS['db_catalog'], settings.ORDERS['rdx_path'])
    transactions = order_manager.get_order(order_id=order_id.encode('utf-8'), user_id=unicode(request.user.id))
    if len(transactions):
        if check_for_can_delete(transactions[0]):
            pass
    order_manager.delete_order(order_id=order_id.encode('utf-8'), user_id=unicode(request.user.id))

    return redirect(urlresolvers.reverse('orders:frontend:mba_orders'))
Пример #3
0
def mba_orders(request):
    user_id = request.user.id

    def format_time(datestr='', timestr=''):
        if datestr:
            datestr = time.strptime(datestr, "%Y%m%d")
            datestr = time.strftime("%d.%m.%Y", datestr)
        if timestr:
            timestr = time.strptime(timestr, "%H%M%S")
            timestr = time.strftime("%H:%M:%S", timestr)
        return datestr + ' ' + timestr

    order_manager = OrderManager(settings.ORDERS['db_catalog'], settings.ORDERS['rdx_path'])
    transactions = order_manager.get_orders(user_id)
    orgs = {}
    # for org_id in transactions_by_org:
    orders = []
    for transaction in transactions:
        # print ET.tostring(transaction.illapdus[0].delivery_status.supplemental_item_description, encoding="UTF-8")
        try:
            doc = etree.XML(etree.tostring(transaction.illapdus[0].delivery_status.supplemental_item_description,
                                           encoding="UTF-8"))
            result_tree = xslt_bib_draw_transformer(doc)
            res = str(result_tree)
        except Exception, e:
            raise e
        res = res.replace('– –', '—')
        res = res.replace('\n', '</br>')
        order = {}

        if transaction.status in order_statuses_titles:
            order['status'] = order_statuses_titles[transaction.status]
        else:
            order['status'] = transaction.status
        order['type'] = ''
        order['copy_info'] = ''
        order['apdus'] = []

        for apdu in transaction.illapdus:
            apdu_map = {}

            apdu_map['type'] = apdu.delivery_status.type
            if apdu.delivery_status.type in apdy_type_titles:
                apdu_map['type_title'] = apdy_type_titles[apdu.delivery_status.type]
            else:
                apdu_map['type_title'] = apdu.delivery_status.type

            apdu_map['datetime'] = format_time(apdu.delivery_status.service_date_time['dtots']['date'],
                                               apdu.delivery_status.service_date_time['dtots']['time'])

            if isinstance(apdu.delivery_status, ILLRequest):
                order['order_id'] = apdu.delivery_status.transaction_id['tq']
                order['org_info'] = org_by_id(apdu.delivery_status.responder_id['pois']['is'])
                if apdu.delivery_status.third_party_info_type['tpit']['stl']['stlt']['si']:
                    order['org_info'] = org_by_id(
                        apdu.delivery_status.third_party_info_type['tpit']['stl']['stlt']['si'])
                apdu_map['requester_note'] = apdu.delivery_status.requester_note
                order['record'] = res
                order['user_comments'] = apdu.delivery_status.requester_note
                apdu_map['record'] = res
                if apdu.delivery_status.ill_service_type == '1':
                    apdu_map['service_type'] = u'доставка'
                    order['type'] = 'doc'

                elif apdu.delivery_status.ill_service_type == '2':
                    apdu_map['service_type'] = u'копия'
                    order['type'] = 'copy'
                    order['copy_info'] = apdu.delivery_status.item_id['pagination']

                order['type_title'] = apdu_map['service_type']
                order['can_delete'] = check_for_can_delete(transaction)

            else:
                # print apdu.delivery_status.type
                apdu_map['responder_note'] = apdu.delivery_status.responder_note
                if apdu.delivery_status.type == 'ILLAnswer':
                    apdu_map['reason_will_supply'] = apdu.delivery_status.results_explanation['wsr']['rws']
                    apdu_map['reason_will_supply_title'] = ''
                    if apdu_map['reason_will_supply'] in apdu_reason_will_supply:
                        apdu_map['reason_will_supply_title'] = apdu_reason_will_supply[apdu_map['reason_will_supply']]

                    apdu_map['unfilled_results'] = apdu.delivery_status.results_explanation['ur']['ru']
                    apdu_map['unfilled_results_title'] = ''
                    if apdu_map['unfilled_results'] in apdu_unfilled_results:
                        apdu_map['unfilled_results_title'] = apdu_unfilled_results[apdu_map['unfilled_results']]

            # apdu_map['record'] = res
            order['apdus'].append(apdu_map)

        orders.append(order)