Skip to content

Feature list item#24

Open
philall wants to merge 10 commits into
jpadilla:masterfrom
philall:feature_list_item
Open

Feature list item#24
philall wants to merge 10 commits into
jpadilla:masterfrom
philall:feature_list_item

Conversation

@philall
Copy link
Copy Markdown
Contributor

@philall philall commented Aug 2, 2017

The Problem

We using this library to render XML in django rest framework.
Of course the consumer are ERP system. For this reason the behavior is not useful with list-item.

Sample

{
        "creation_date": "2017-07-01 14:00:00",
        "orderId": 1,
        "positions": [
            {
                "posNo": 1,
                "amount": 3,
                "messages": [
                    {
                        "type": "O",
                        "code": "xyz"
                    },
                    {
                        "type": "L",
                        "code": "zyx"
                    }
                ]
            },
            {
                "posNo": 2,
                "amount": 1,
                "messages": [
                    {
                        "type": "O",
                        "code": "xyz"
                    },
                    {
                        "type": "L",
                        "code": "zyx"
                    }
                ]
            }
        ]
    }

std. Renderer

<?xml version="1.0" encoding="utf-8"?>
<root>
  <creation_date>2017-07-01 14:00:00</creation_date>
  <orderId>1</orderId>
  <positions>
    <list-item>
      <posNo>1</posNo>
      <amount>3</amount>
      <messages>
        <list-item>
          <type>O</type>
          <code>xyz</code>
        </list-item>
        <list-item>
          <type>L</type>
          <code>zyx</code>
        </list-item>
      </messages>
    </list-item>
    <list-item>
      <posNo>2</posNo>
      <amount>1</amount>
      <messages>
        <list-item>
          <type>O</type>
          <code>xyz</code>
        </list-item>
        <list-item>
          <type>L</type>
          <code>zyx</code>
        </list-item>
      </messages>
      </list-item>
  </positions>
</root>

Solution

override <list-item> tag with parent name (parent_name[0:-1]) without the last sign.

  • positions -> position
  • messages -> message
class OrderXMLRenderer(XMLRenderer):
    root_tag_name = 'order'
    override_item_tag_name = True    
<?xml version="1.0" encoding="utf-8"?>
<order>
  <creation_date>2017-07-01 14:00:00</creation_date>
  <orderId>1</orderId>
  <positions>
    <position>
      <posNo>1</posNo>
      <amount>3</amount>
      <messages>
        <message>
          <type>O</type>
          <code>xyz</code>
        </message>
        <message>
          <type>L</type>
          <code>zyx</code>
        </message>
      </messages>
    </position>
    <position>
      <posNo>2</posNo>
      <amount>1</amount>
      <messages>
        <message>
          <type>O</type>
          <code>xyz</code>
        </message>
        <message>
          <type>L</type>
          <code>zyx</code>
        </message>
      </messages>
      </position>
  </positions>
</order>

@philall philall changed the title WIP: Feature list item Feature list item Aug 4, 2017
@philall
Copy link
Copy Markdown
Contributor Author

philall commented Aug 14, 2017

@jpadilla What is missing or does not fit?

@loftsmartmatt
Copy link
Copy Markdown

I'd also like to use this

@philall
Copy link
Copy Markdown
Contributor Author

philall commented Sep 19, 2017

@jpadilla don't you want to use that?

@aijogja
Copy link
Copy Markdown

aijogja commented Oct 22, 2019

vote to merge this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants