Show More
@@ -54,6 +54,7 b' log = logging.getLogger(__name__)' | |||||
54 | # BASE CLASSES |
|
54 | # BASE CLASSES | |
55 | #============================================================================== |
|
55 | #============================================================================== | |
56 |
|
56 | |||
|
57 | ||||
57 | class ModelSerializer(json.JSONEncoder): |
|
58 | class ModelSerializer(json.JSONEncoder): | |
58 | """ |
|
59 | """ | |
59 | Simple Serializer for JSON, |
|
60 | Simple Serializer for JSON, | |
@@ -84,6 +85,7 b' class ModelSerializer(json.JSONEncoder):' | |||||
84 | else: |
|
85 | else: | |
85 | return json.JSONEncoder.default(self, obj) |
|
86 | return json.JSONEncoder.default(self, obj) | |
86 |
|
87 | |||
|
88 | ||||
87 | class BaseModel(object): |
|
89 | class BaseModel(object): | |
88 | """Base Model for all classess |
|
90 | """Base Model for all classess | |
89 |
|
91 | |||
@@ -101,6 +103,10 b' class BaseModel(object):' | |||||
101 | d = {} |
|
103 | d = {} | |
102 | for k in self._get_keys(): |
|
104 | for k in self._get_keys(): | |
103 | d[k] = getattr(self, k) |
|
105 | d[k] = getattr(self, k) | |
|
106 | ||||
|
107 | # also use __json__() if present to get additional fields | |||
|
108 | for k, val in getattr(self, '__json__', lambda: {})().iteritems(): | |||
|
109 | d[k] = val | |||
104 | return d |
|
110 | return d | |
105 |
|
111 | |||
106 | def get_appstruct(self): |
|
112 | def get_appstruct(self): | |
@@ -315,6 +321,9 b' class User(Base, BaseModel):' | |||||
315 | except: |
|
321 | except: | |
316 | return self.__class__.__name__ |
|
322 | return self.__class__.__name__ | |
317 |
|
323 | |||
|
324 | def __json__(self): | |||
|
325 | return {'email': self.email} | |||
|
326 | ||||
318 | @classmethod |
|
327 | @classmethod | |
319 | def get_by_username(cls, username, case_insensitive=False): |
|
328 | def get_by_username(cls, username, case_insensitive=False): | |
320 | if case_insensitive: |
|
329 | if case_insensitive: |
General Comments 0
You need to be logged in to leave comments.
Login now