Changeset 4182

Show
Ignore:
Timestamp:
02/29/08 22:02:13 (9 months ago)
Author:
chrisz
Message:

Proper decorator syntax.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/qstemplates/quickstart/+package+/model.py_tmpl

    r3666 r4182  
    200200    expiry = Field(DateTime) 
    201201 
    202     @classmethod 
    203202    def lookup_visit(cls, visit_key): 
    204203        return Visit.get(visit_key) 
     204    lookup_visit = classmethod(lookup_visit) 
    205205 
    206206 
  • branches/1.0/turbogears/tests/test_paginate.py

    r4132 r4182  
    9494    assert_ok = staticmethod(assert_ok) 
    9595 
    96  
     96[jsonify.when('isinstance(obj, Spy)')] 
    9797def jsonify_spy(obj): 
    9898    result = str(obj) 
    9999    return result 
    100 jsonify_spy = jsonify.when('isinstance(obj, Spy)')(jsonify_spy) 
    101100 
    102101 
     
    105104 
    106105    class MyRoot(RootController): 
     106 
     107        [expose()] 
     108        [paginate("data")] 
    107109        def spy(self): 
    108110            data = range(100) 
    109111            spy = Spy() 
    110112            return dict(data=data, spy=spy) 
    111         spy = paginate("data")(spy) 
    112         spy = expose()(spy) 
    113  
     113 
     114        [expose()] 
     115        [paginate("data")] 
    114116        def spy_correct_expectation(self): 
    115117            data = range(100) 
    116118            spy = Spy(page_count=10) 
    117119            return dict(data=data, spy=spy) 
    118         spy_correct_expectation = paginate("data")(spy_correct_expectation) 
    119         spy_correct_expectation = expose()(spy_correct_expectation) 
    120  
     120 
     121        [expose()] 
     122        [paginate("data")] 
    121123        def spy_wrong_expectation(self): 
    122124            data = range(100) 
    123125            spy = Spy(page_count=9) 
    124126            return dict(data=data, spy=spy) 
    125         spy_wrong_expectation = paginate("data")(spy_wrong_expectation) 
    126         spy_wrong_expectation = expose()(spy_wrong_expectation) 
    127  
     127 
     128        [expose()] 
     129        [paginate("data")] 
    128130        def spy_invalid_expectation(self): 
    129131            data = range(100) 
    130132            spy = Spy(foobar=10) 
    131133            return dict(data=data, spy=spy) 
    132         spy_invalid_expectation = paginate("data")(spy_invalid_expectation) 
    133         spy_invalid_expectation = expose()(spy_invalid_expectation) 
    134134 
    135135 
     
    141141        body = cherrypy.response.body[0] 
    142142        Spy.assert_ok(body, 'current_page', 1) 
    143  
    144143        try: 
    145144            Spy.assert_ok(body, 'current_page', 2) 
     
    169168 
    170169 
    171  
    172  
    173170class TestPagination(unittest.TestCase): 
    174171    """Base class for all Paginate TestCases""" 
     172 
    175173    def request(self, url): 
    176174        create_request(url) 
     
    181179 
    182180 
    183  
    184  
    185181class TestBasicPagination(TestPagination): 
    186182 
    187183    class MyRoot(RootController): 
     184 
     185        [expose()] 
     186        [paginate("data", limit=4)] 
    188187        def basic(self): 
    189188            spy = Spy(var_name='data', pages=[1,2,3], limit=4, page_count=3, 
     
    191190            data = range(10) 
    192191            return dict(data=data, spy=spy) 
    193         basic = paginate("data", limit=4)(basic) 
    194         basic = expose()(basic) 
    195  
     192 
     193        [expose()] 
     194        [paginate("data", limit=4, allow_limit_override=True)] 
    196195        def custom_limit(self): 
    197196            spy = Spy(var_name='data', order=None, ordering={}, row_count=10) 
    198197            data = range(10) 
    199198            return dict(data=data, spy=spy) 
    200         custom_limit = paginate("data", limit=4, 
    201             allow_limit_override=True)(custom_limit) 
    202         custom_limit = expose()(custom_limit) 
    203  
     199 
     200        [expose()] 
     201        [paginate("data")] 
    204202        def default_max_pages(self): 
    205203            spy = Spy(var_name='data', limit=10, page_count=10, 
     
    207205            data = range(100) 
    208206            return dict(data=data, spy=spy) 
    209         default_max_pages = paginate("data")(default_max_pages) 
    210         default_max_pages = expose()(default_max_pages) 
    211  
     207 
     208        [expose()] 
     209        [paginate("data", max_pages=4)] 
    212210        def four_max_pages(self): 
    213211            spy = Spy(var_name='data', limit=10, page_count=10, 
     
    215213            data = range(100) 
    216214            return dict(data=data, spy=spy) 
    217         four_max_pages = paginate("data", max_pages=4)(four_max_pages) 
    218         four_max_pages = expose()(four_max_pages) 
    219  
     215 
     216        [expose()] 
     217        [paginate("data", max_pages=3)] 
    220218        def three_max_pages(self): 
    221219            spy = Spy(var_name='data', limit=10, page_count=10, 
     
    223221            data = range(100) 
    224222            return dict(data=data, spy=spy) 
    225         three_max_pages = paginate("data", max_pages=3)(three_max_pages) 
    226         three_max_pages = expose()(three_max_pages) 
    227  
     223 
     224        [expose()] 
     225        [paginate("data", limit=4, dynamic_limit='foobar')] 
    228226        def invalid_dynamic(self): 
    229227            data = range(10) 
    230228            return dict(data=data) 
    231         invalid_dynamic = paginate("data", limit=4, 
    232             dynamic_limit='foobar')(invalid_dynamic) 
    233         invalid_dynamic = expose()(invalid_dynamic) 
    234  
     229 
     230        [expose()] 
     231        [paginate("data", limit=4, dynamic_limit='foobar', allow_limit_override=True)] 
    235232        def dynamic(self): 
    236233            spy = Spy(var_name='data', pages=[1,2], limit=7, page_count=2, 
     
    238235            data = range(10) 
    239236            return dict(data=data, spy=spy, foobar=7) 
    240         dynamic = paginate("data", limit=4, dynamic_limit='foobar', 
    241             allow_limit_override=True)(dynamic) 
    242         dynamic = expose()(dynamic) 
    243  
     237 
     238        [expose()] 
     239        [paginate("bar")] 
     240        [paginate("foo", limit=4)] 
    244241        def multiple(self): 
    245242            spy_foo = Spy(name='foo', var_name='foo', pages=[1,2,3,4,5], 
     
    250247            foo = range(20) 
    251248            bar = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') # 26 letters 
    252  
    253249            return dict(foo=foo, bar=bar, spy_foo=spy_foo, spy_bar=spy_bar) 
    254         multiple = paginate("foo", limit=4)(multiple) 
    255         multiple = paginate("bar")(multiple) 
    256         multiple = expose()(multiple) 
    257  
     250 
     251        [expose()] 
     252        [paginate("data", limit=4, allow_limit_override=True)] 
    258253        def empty(self): 
    259254            spy = Spy(var_name='data', pages=[], page_count=0, 
     
    262257            data = [] 
    263258            return dict(data=data, spy=spy) 
    264         empty = paginate("data", limit=4, allow_limit_override=True)(empty) 
    265         empty = expose()(empty) 
    266     # end of MyRoot ------------------------------------------------------------ 
    267259 
    268260 
     
    577569 
    578570    class MyRoot(RootController): 
     571 
    579572        def __common(self, method=None): 
    580573            if method == "Q": 
     
    633626        default_compound_ordering4 = expose("turbogears.tests.paginate")(default_compound_ordering4) 
    634627 
     628        [expose("turbogears.tests.paginate")] 
     629        [paginate("data", default_order="id")] 
    635630        def related(self): 
    636631            # only SA Query 
     
    640635                      order=None, row_count=16) 
    641636            return dict(data=data, spy=spy) 
    642         related = paginate("data", default_order="id")(related) 
    643         related = expose("turbogears.tests.paginate")(related) 
    644  
     637 
     638        [expose("turbogears.tests.paginate")] 
     639        [paginate("data", default_order="id", limit=0)] 
    645640        def zero_limit(self, method=None): 
    646641            if method == "Q": 
     
    657652            return dict(data=data, spy=spy) 
    658653 
    659         zero_limit = paginate("data", default_order="id", limit=0)(zero_limit) 
    660         zero_limit = expose("turbogears.tests.paginate")(zero_limit) 
    661  
     654        [expose("turbogears.tests.paginate")] 
     655        [paginate("data", default_order="id")] 
    662656        def empty_with_groupby(self): 
    663657            data = session.query(Address).filter(Address.c.id<0).group_by(Address.c.user_id) 
     
    667661            return dict(data=data, spy=spy) 
    668662 
    669         empty_with_groupby = paginate("data", default_order="id")(empty_with_groupby) 
    670         empty_with_groupby = expose("turbogears.tests.paginate")(empty_with_groupby) 
    671  
    672     # end of MyRoot ------------------------------------------------------------ 
    673663 
    674664    def setUp(self): 
  • branches/1.1/turbogears/qstemplates/quickstart/+package+/model.py_tmpl

    r3667 r4182  
    9393    expiry = DateTimeCol() 
    9494 
     95        @classmethod 
    9596    def lookup_visit(cls, visit_key): 
    9697        try: 
     
    9899        except SQLObjectNotFound: 
    99100            return None 
    100     lookup_visit = classmethod(lookup_visit) 
    101101 
    102102 
     
    325325    A visit to your site 
    326326    """ 
     327        @classmethod 
    327328    def lookup_visit(cls, visit_key): 
    328329        return cls.query.get(visit_key) 
    329     lookup_visit = classmethod(lookup_visit) 
    330330 
    331331 
     
    356356    permissions = property(permissions) 
    357357 
     358        @classmethod 
    358359    def by_email_address(cls, email): 
    359360        """ 
     
    363364        return cls.query.filter_by(email_address=email).first() 
    364365 
    365     by_email_address = classmethod(by_email_address) 
    366  
     366        @classmethod 
    367367    def by_user_name(cls, username): 
    368368        """ 
     
    371371        """ 
    372372        return cls.query.filter_by(user_name=username).first() 
    373  
    374     by_user_name = classmethod(by_user_name) 
    375373 
    376374    def _set_password(self, password): 
  • branches/1.1/turbogears/tests/test_paginate.py

    r4132 r4182  
    8383            " , ".join(["%s=%r" % (k,v) for k,v in paginate.__dict__.items()]) 
    8484 
     85    @staticmethod 
    8586    def assert_ok(body, key, value, raw=False): 
    8687        assert "ok: [paginate" in body 
     
    9293            print body 
    9394        assert expr in body, "expected %s" % expr 
    94     assert_ok = staticmethod(assert_ok) 
    95  
    96  
     95 
     96 
     97@jsonify.when('isinstance(obj, Spy)') 
    9798def jsonify_spy(obj): 
    9899    result = str(obj) 
    99100    return result 
    100 jsonify_spy = jsonify.when('isinstance(obj, Spy)')(jsonify_spy) 
    101101 
    102102 
     
    105105 
    106106    class MyRoot(RootController): 
     107 
     108        @expose() 
     109        @paginate("data") 
    107110        def spy(self): 
    108111            data = range(100) 
    109112            spy = Spy() 
    110113            return dict(data=data, spy=spy) 
    111         spy = paginate("data")(spy) 
    112         spy = expose()(spy
    113  
     114 
     115        @expose(
     116        @paginate("data") 
    114117        def spy_correct_expectation(self): 
    115118            data = range(100) 
    116119            spy = Spy(page_count=10) 
    117120            return dict(data=data, spy=spy) 
    118         spy_correct_expectation = paginate("data")(spy_correct_expectation) 
    119         spy_correct_expectation = expose()(spy_correct_expectation
    120  
     121 
     122        @expose(
     123        @paginate("data") 
    121124        def spy_wrong_expectation(self): 
    122125            data = range(100) 
    123126            spy = Spy(page_count=9) 
    124127            return dict(data=data, spy=spy) 
    125         spy_wrong_expectation = paginate("data")(spy_wrong_expectation) 
    126         spy_wrong_expectation = expose()(spy_wrong_expectation
    127  
     128 
     129        @expose(
     130        @paginate("data") 
    128131        def spy_invalid_expectation(self): 
    129132            data = range(100) 
    130133            spy = Spy(foobar=10) 
    131134            return dict(data=data, spy=spy) 
    132         spy_invalid_expectation = paginate("data")(spy_invalid_expectation) 
    133         spy_invalid_expectation = expose()(spy_invalid_expectation) 
    134135 
    135136 
     
    141142        body = cherrypy.response.body[0] 
    142143        Spy.assert_ok(body, 'current_page', 1) 
    143  
    144144        try: 
    145145            Spy.assert_ok(body, 'current_page', 2) 
     
    169169 
    170170 
    171  
    172  
    173171class TestPagination(unittest.TestCase): 
    174172    """Base class for all Paginate TestCases""" 
     173 
    175174    def request(self, url): 
    176175        create_request(url) 
     
    181180 
    182181 
    183  
    184  
    185182class TestBasicPagination(TestPagination): 
    186183 
    187184    class MyRoot(RootController): 
     185 
     186        @expose() 
     187        @paginate("data", limit=4) 
    188188        def basic(self): 
    189189            spy = Spy(var_name='data', pages=[1,2,3], limit=4, page_count=3, 
     
    191191            data = range(10) 
    192192            return dict(data=data, spy=spy) 
    193         basic = paginate("data", limit=4)(basic) 
    194         basic = expose()(basic
    195  
     193 
     194        @expose(
     195        @paginate("data", limit=4, allow_limit_override=True) 
    196196        def custom_limit(self): 
    197197            spy = Spy(var_name='data', order=None, ordering={}, row_count=10) 
    198198            data = range(10) 
    199199            return dict(data=data, spy=spy) 
    200         custom_limit = paginate("data", limit=4, 
    201             allow_limit_override=True)(custom_limit) 
    202         custom_limit = expose()(custom_limit) 
    203  
     200 
     201        @expose() 
     202        @paginate("data") 
    204203        def default_max_pages(self): 
    205204            spy = Spy(var_name='data', limit=10, page_count=10, 
     
    207206            data = range(100) 
    208207            return dict(data=data, spy=spy) 
    209         default_max_pages = paginate("data")(default_max_pages) 
    210         default_max_pages = expose()(default_max_pages
    211  
     208 
     209        @expose(
     210        @paginate("data", max_pages=4) 
    212211        def four_max_pages(self): 
    213212            spy = Spy(var_name='data', limit=10, page_count=10, 
     
    215214            data = range(100) 
    216215            return dict(data=data, spy=spy) 
    217         four_max_pages = paginate("data", max_pages=4)(four_max_pages) 
    218         four_max_pages = expose()(four_max_pages
    219  
     216 
     217        @expose(
     218        @paginate("data", max_pages=3) 
    220219        def three_max_pages(self): 
    221220            spy = Spy(var_name='data', limit=10, page_count=10, 
     
    223222            data = range(100) 
    224223            return dict(data=data, spy=spy) 
    225         three_max_pages = paginate("data", max_pages=3)(three_max_pages) 
    226         three_max_pages = expose()(three_max_pages
    227  
     224 
     225        @expose(
     226        @paginate("data", limit=4, dynamic_limit='foobar') 
    228227        def invalid_dynamic(self): 
    229228            data = range(10) 
    230229            return dict(data=data) 
    231         invalid_dynamic = paginate("data", limit=4, 
    232             dynamic_limit='foobar')(invalid_dynamic) 
    233         invalid_dynamic = expose()(invalid_dynamic) 
    234  
     230 
     231        @expose() 
     232        @paginate("data", limit=4, dynamic_limit='foobar', allow_limit_override=True) 
    235233        def dynamic(self): 
    236234            spy = Spy(var_name='data', pages=[1,2], limit=7, page_count=2, 
     
    238236            data = range(10) 
    239237            return dict(data=data, spy=spy, foobar=7) 
    240         dynamic = paginate("data", limit=4, dynamic_limit='foobar', 
    241             allow_limit_override=True)(dynamic
    242         dynamic = expose()(dynamic
    243  
     238 
     239        @expose(
     240        @paginate("bar"
     241        @paginate("foo", limit=4) 
    244242        def multiple(self): 
    245243            spy_foo = Spy(name='foo', var_name='foo', pages=[1,2,3,4,5], 
     
    252250 
    253251            return dict(foo=foo, bar=bar, spy_foo=spy_foo, spy_bar=spy_bar) 
    254         multiple = paginate("foo", limit=4)(multiple) 
    255         multiple = paginate("bar")(multiple
    256         multiple = expose()(multiple) 
     252 
     253        @expose(
     254        @paginate("data", limit=4, allow_limit_override=True) 
    257255 
    258256        def empty(self): 
     
    262260            data = [] 
    263261            return dict(data=data, spy=spy) 
    264         empty = paginate("data", limit=4, allow_limit_override=True)(empty) 
    265         empty = expose()(empty) 
    266     # end of MyRoot ------------------------------------------------------------ 
    267262 
    268263 
     
    630625        default_compound_ordering4 = expose("turbogears.tests.paginate")(default_compound_ordering4) 
    631626 
     627        @expose("turbogears.tests.paginate") 
     628        @paginate("data", default_order="id") 
    632629        def related(self): 
    633630            # only SA Query 
     
    637634                      order=None, row_count=16) 
    638635            return dict(data=data, spy=spy) 
    639         related = paginate("data", default_order="id")(related) 
    640         related = expose("turbogears.tests.paginate")(related
    641  
     636 
     637        @expose("turbogears.tests.paginate"
     638        @paginate("data", default_order="id", limit=0) 
    642639        def zero_limit(self, method=None): 
    643640            if method == "Q": 
     
    654651            return dict(data=data, spy=spy) 
    655652 
    656         zero_limit = paginate("data", default_order="id", limit=0)(zero_limit) 
    657         zero_limit = expose("turbogears.tests.paginate")(zero_limit) 
    658  
     653        @expose("turbogears.tests.paginate") 
     654        @paginate("data", default_order="id") 
    659655        def empty_with_groupby(self): 
    660656            data = session.query(Address).filter(Address.c.id<0).group_by(Address.c.user_id) 
     
    664660            return dict(data=data, spy=spy) 
    665661 
    666         empty_with_groupby = paginate("data", default_order="id")(empty_with_groupby) 
    667         empty_with_groupby = expose("turbogears.tests.paginate")(empty_with_groupby) 
    668  
    669     # end of MyRoot ------------------------------------------------------------ 
    670662 
    671663    def setUp(self): 
  • branches/1.1/turbogears/visit/savisit.py

    r3619 r4182  
    8484class TG_Visit(object): 
    8585 
     86    @classmethod 
    8687    def lookup_visit(cls, visit_key): 
    8788        return Visit.get(visit_key) 
    88     lookup_visit = classmethod(lookup_visit) 
  • branches/1.1/turbogears/visit/sovisit.py

    r3367 r4182  
    8888    expiry= DateTimeCol() 
    8989 
     90    @classmethod 
    9091    def lookup_visit( cls, visit_key ): 
    9192        try: 
     
    9394        except SQLObjectNotFound: 
    9495            return None 
    95     lookup_visit= classmethod(lookup_visit) 
  • branches/1.1/turbogears/widgets/big_widgets.py

    r4118 r4182  
    412412    name = "AJAX Grid" 
    413413 
     414    @staticmethod 
    414415    def facgen(n): 
    415416        total = 1 
     
    418419            total *= x 
    419420            yield x, total 
    420     facgen = staticmethod(facgen) 
    421  
    422421 
    423422    full_class_name = "turbogears.widgets.AjaxGrid" 
  • branches/1.1/turbogears/widgets/datagrid.py

    r1850 r4182  
    9595        """Shortcut to get_column.""" 
    9696        return self.get_column(name) 
     97    @staticmethod 
    9798    def get_field_getter(columns): 
    9899        """ Returns a function to access the fields of table by row, col """ 
     
    103104            return idx[col].get_field(row) 
    104105        return _get_field 
    105     get_field_getter = staticmethod(get_field_getter) 
    106106    def update_params(self, d): 
    107107        super(DataGrid, self).update_params(d)