Sorting on list and detail pages, plus type and ref type fixes to classes

This commit is contained in:
Anthony Johnson 2015-04-14 18:05:15 -07:00
parent 5a5ae1cf15
commit e7be3b1804
6 changed files with 82 additions and 22 deletions

View File

@ -33,6 +33,12 @@ class AutoAPIBase(object):
context['object'] = self context['object'] = self
return context return context
def __lt__(self, other):
'''Object sorting comparison'''
if isinstance(other, AutoAPIBase):
return self.id < other.id
return super(AutoAPIBase, self).__lt__(other)
class UnknownType(AutoAPIBase): class UnknownType(AutoAPIBase):

View File

@ -135,6 +135,8 @@ class DotNetDomain(AutoAPIDomain):
# TODO not here! # TODO not here!
for child in obj.children: for child in obj.children:
obj.item_map[child.type].append(child) obj.item_map[child.type].append(child)
for key in obj.item_map.keys():
obj.item_map[key].sort()
rst = obj.render() rst = obj.render()
# Detail # Detail
@ -226,60 +228,68 @@ class DotNetBase(AutoAPIBase):
if pieces: if pieces:
return '.'.join(pieces) return '.'.join(pieces)
@property
def ref_type(self):
return self.type
@property
def ref_directive(self):
return self.type
class DotNetNamespace(DotNetBase): class DotNetNamespace(DotNetBase):
type = 'namespace' type = 'namespace'
ref_type = 'ns' ref_directive = 'ns'
class DotNetMethod(DotNetBase): class DotNetMethod(DotNetBase):
type = 'method' type = 'method'
ref_type = 'meth' ref_directive = 'meth'
class DotNetProperty(DotNetBase): class DotNetProperty(DotNetBase):
type = 'property' type = 'property'
ref_type = 'prop' ref_directive = 'prop'
class DotNetEnum(DotNetBase): class DotNetEnum(DotNetBase):
type = 'enum' type = 'enum'
ref_type = 'enum' ref_type = 'enumeration'
ref_directive = 'enum'
class DotNetStruct(DotNetBase): class DotNetStruct(DotNetBase):
type = 'struct' type = 'struct'
ref_type = 'struct' ref_type = 'structure'
ref_directive = 'struct'
class DotNetConstructor(DotNetBase): class DotNetConstructor(DotNetBase):
type = 'constructor' type = 'constructor'
ref_type = 'ctor' ref_directive = 'ctor'
class DotNetInterface(DotNetBase): class DotNetInterface(DotNetBase):
type = 'interface' type = 'interface'
ref_type = 'iface' ref_directive = 'iface'
class DotNetDelegate(DotNetBase): class DotNetDelegate(DotNetBase):
type = 'delegate' type = 'delegate'
ref_type = 'del' ref_directive = 'del'
class DotNetClass(DotNetBase): class DotNetClass(DotNetBase):
type = 'class' type = 'class'
ref_type = 'cls' ref_directive = 'cls'
class DotNetField(DotNetBase): class DotNetField(DotNetBase):
type = 'field' type = 'field'
ref_type = 'field'
class DotNetEvent(DotNetBase): class DotNetEvent(DotNetBase):
type = 'event' type = 'event'
ref_type = 'event'
class DotNetVirtualNamespace(AutoAPIBase): class DotNetVirtualNamespace(AutoAPIBase):

View File

@ -3,7 +3,7 @@
{{ object.short_name }} {{ object.type.title()}} {{ object.short_name }} {{ object.type.title()}}
{{ "=" * (object.short_name|length + object.type|length + 1) }} {{ "=" * (object.short_name|length + object.type|length + 1) }}
.. dn:{{ object.type }}:: {{ object.name }} .. dn:{{ object.ref_type }}:: {{ object.name }}
{% endblock %} {% endblock %}

View File

@ -1,4 +1,4 @@
.. dn:{{ object.type }}:: {{ object.name }} .. dn:{{ object.ref_type }}:: {{ object.name }}
{% if summary %} {% if summary %}

View File

@ -3,7 +3,7 @@
{{ object.short_name }} {{ object.type.title() }} {{ object.short_name }} {{ object.type.title() }}
{{ "=" * (object.short_name|length + object.type|length + 1) }} {{ "=" * (object.short_name|length + object.type|length + 1) }}
.. dn:{{ object.type }}:: {{ object.name }} .. dn:{{ object.ref_type }}:: {{ object.name }}
{% endblock %} {% endblock %}
@ -24,17 +24,17 @@
{% block table %} {% block table %}
{% if children %} {% if object.children %}
.. list-table:: Classes .. list-table:: Members
:widths: 20, 80 :widths: 20, 80
:header-rows: 1 :header-rows: 1
* - Class * - Class
- Description - Description
{%- for item in children %} {%- for item in object.children|sort %}
{% macro render() %}{{ item.summary }}{% endmacro %} {% macro render() %}{{ item.summary }}{% endmacro %}
* - :dn:{{ item.ref_type }}:`{{ item.id }}` * - :dn:{{ item.ref_directive }}:`{{ item.id }}`
- {{ render()|indent(7) }} - {{ render()|indent(7) }}
{% endfor %} {% endfor %}

View File

@ -12,15 +12,59 @@ class NamespaceTests(unittest.TestCase):
'''Test types of some of the objects''' '''Test types of some of the objects'''
obj = dotnet.DotNetNamespace({'id': 'Foo.Bar'}) obj = dotnet.DotNetNamespace({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'namespace') self.assertEqual(obj.type, 'namespace')
self.assertEqual(obj.ref_type, 'ns') self.assertEqual(obj.ref_type, 'namespace')
self.assertEqual(obj.ref_directive, 'ns')
obj = dotnet.DotNetMethod({'id': 'Foo.Bar'}) obj = dotnet.DotNetMethod({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'method') self.assertEqual(obj.type, 'method')
self.assertEqual(obj.ref_type, 'meth') self.assertEqual(obj.ref_type, 'method')
self.assertEqual(obj.ref_directive, 'meth')
obj = dotnet.DotNetProperty({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'property')
self.assertEqual(obj.ref_type, 'property')
self.assertEqual(obj.ref_directive, 'prop')
obj = dotnet.DotNetEnum({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'enum')
self.assertEqual(obj.ref_type, 'enumeration')
self.assertEqual(obj.ref_directive, 'enum')
obj = dotnet.DotNetStruct({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'struct')
self.assertEqual(obj.ref_type, 'structure')
self.assertEqual(obj.ref_directive, 'struct')
obj = dotnet.DotNetConstructor({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'constructor')
self.assertEqual(obj.ref_type, 'constructor')
self.assertEqual(obj.ref_directive, 'ctor')
obj = dotnet.DotNetInterface({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'interface')
self.assertEqual(obj.ref_type, 'interface')
self.assertEqual(obj.ref_directive, 'iface')
obj = dotnet.DotNetDelegate({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'delegate')
self.assertEqual(obj.ref_type, 'delegate')
self.assertEqual(obj.ref_directive, 'del')
obj = dotnet.DotNetClass({'id': 'Foo.Bar'}) obj = dotnet.DotNetClass({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'class') self.assertEqual(obj.type, 'class')
self.assertEqual(obj.ref_type, 'cls') self.assertEqual(obj.ref_type, 'class')
self.assertEqual(obj.ref_directive, 'cls')
obj = dotnet.DotNetField({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'field')
self.assertEqual(obj.ref_type, 'field')
self.assertEqual(obj.ref_directive, 'field')
obj = dotnet.DotNetEvent({'id': 'Foo.Bar'})
self.assertEqual(obj.type, 'event')
self.assertEqual(obj.ref_type, 'event')
self.assertEqual(obj.ref_directive, 'event')
def test_names(self): def test_names(self):
'''Test names of objects''' '''Test names of objects'''