|
6 | 6 | from django.core.paginator import Paginator
|
7 | 7 | from django.http import Http404
|
8 | 8 | import django_tables2 as tables
|
| 9 | +from django_tables2.tables import DeclarativeColumnsMetaclass |
9 | 10 | from haystack.query import SearchQuerySet
|
10 | 11 |
|
11 | 12 |
|
@@ -58,6 +59,38 @@ class CityTable(GeoAreaTable, AddedMixin):
|
58 | 59 | assert 'added' in CityTable.base_columns
|
59 | 60 |
|
60 | 61 |
|
| 62 | +@core.test |
| 63 | +def metaclass_inheritance(): |
| 64 | + class Tweaker(type): |
| 65 | + """Adds an attribute "tweaked" to all classes""" |
| 66 | + def __new__(cls, name, bases, attrs): |
| 67 | + attrs['tweaked'] = True |
| 68 | + return super(Tweaker, cls).__new__(cls, name, bases, attrs) |
| 69 | + |
| 70 | + class Meta(Tweaker, DeclarativeColumnsMetaclass): |
| 71 | + pass |
| 72 | + |
| 73 | + class TweakedTable(tables.Table): |
| 74 | + __metaclass__ = Meta |
| 75 | + name = tables.Column() |
| 76 | + |
| 77 | + table = TweakedTable([]) |
| 78 | + assert 'name' in table.columns |
| 79 | + assert table.tweaked |
| 80 | + |
| 81 | + # now flip the order |
| 82 | + class FlippedMeta(DeclarativeColumnsMetaclass, Tweaker): |
| 83 | + pass |
| 84 | + |
| 85 | + class FlippedTweakedTable(tables.Table): |
| 86 | + __metaclass__ = FlippedMeta |
| 87 | + name = tables.Column() |
| 88 | + |
| 89 | + table = FlippedTweakedTable([]) |
| 90 | + assert 'name' in table.columns |
| 91 | + assert table.tweaked |
| 92 | + |
| 93 | + |
61 | 94 | @core.test
|
62 | 95 | def attrs():
|
63 | 96 | class TestTable(tables.Table):
|
|
0 commit comments