Issue #227 new

handler's fields cannot override other's, I just hacked it , cannot ensure it

sprhawk
created an issue

I'm a newbie, I just hack it to have my code work.

Problem: the CouponsHandler's fields cannot override CouponDetailHandler's.

my code's here

class CouponsHandler(BaseHandler):
    allowed_methods = ("GET")
    model = UserCoupon
    fields = (
        ('user', ('username', )),
        ('coupon', ('description','start_time', 'end_time', ('coupon_type', ('name', )), 'usage')),
        )

class CouponDetailHandler(BaseHandler):
    allowed_methods = ("GET")
    model = Coupon
    fields =  ('description',
               'start_time',
               'end_time',
               ('coupon_type', ('name', )),
               'usage',
               'restricted_time_description',
               'restricted_location_description',
               'restricted_other_description',
               'declaration'
               )
    def read(self, request, coupon_id):
        if coupon_id:
            return self.model.objects.filter(id=coupon_id).all()
        return None

I just hack it:

diff -r 7c90898072ce piston/emitters.py
--- a/piston/emitters.py        Fri Mar 30 18:12:21 2012 -0400
+++ b/piston/emitters.py        Thu Dec 27 23:23:55 2012 +0800
@@ -175,10 +175,10 @@
                 # use the list_fields from the base handler and accept that
                 # the nested models won't appear properly
                 # Refs #157
-                if handler:
+                if handler and not fields:
                     fields = getattr(handler, 'fields')    

-                if not fields or hasattr(handler, 'fields'):
+                if not fields and hasattr(handler, 'fields'):
                     """
                     Fields was not specified, try to find teh correct
                     version in the typemapper we were sent.

I didn't understand: if there is a fields, why files = getattr(handler, 'fields')

then the next if expression overrides it again.

Comments (0)

  1. Log in to comment