diff --git a/stackexchange/core.py b/stackexchange/core.py index 26c2f0b..26c113d 100644 --- a/stackexchange/core.py +++ b/stackexchange/core.py @@ -24,7 +24,7 @@ def __init__(self, json, site, skip_ext = False): transfer = self.transfer if hasattr(self, 'transfer') else () fields = ([A + (None,) for A in alias if len(A) == 2] + [(k, k, None) for k in transfer if isinstance(k, str)] + - [A for A in alias if len(A) == 3] + + [A for A in alias if len(A) == 3] + [(k[0],) + k for k in transfer if not isinstance(k, str)]) for dest, key, transform in fields: @@ -45,10 +45,10 @@ def __init__(self, json, site, skip_ext = False): if hasattr(self, '_extend') and not skip_ext: self._extend(self.json_ob, site) - def fetch(self): + def fetch(self, **kwargs): """Fetches all the data that the model can describe, not just the attributes which were specified in the original response.""" if hasattr(self, 'fetch_callback'): - res = self.fetch_callback(self) + res = self.fetch_callback(self, **kwargs) if isinstance(res, dict): self.__init__(res, self.site) @@ -184,7 +184,7 @@ def __init__(self, code = UNKNOWN, name = None, message = None): self.code = code self.name = name self.message = message - + def __str__(self): if self.code == self.UNKNOWN: return 'unrecognised error' @@ -356,7 +356,7 @@ def paginated_to_resultset(site, json, typ, collection, params): # no longer variable in v2.x, having been replaced by a generic field # 'items'. To perhaps be removed completely at some later point. items = [] - + # create strongly-typed objects from the JSON items for json_item in json['items']: json_item['_params_'] = params[-1] # convenient access to the kw hash diff --git a/stackexchange/models.py b/stackexchange/models.py index f7c510a..f6ac3a7 100644 --- a/stackexchange/models.py +++ b/stackexchange/models.py @@ -167,15 +167,15 @@ def owner(self): if self._owner is None: self._owner = self.site.user(self.owner_id) return self._owner - + @property def question(self): if self._question is None: self._question = self.site.question(self.question_id) return self._question - def fetch_callback(self, _, site): - return site.answer(self.id) + def fetch_callback(self, _, site, **kwargs): + return site.answer(self.id, **kwargs) def __unicode__(self): return u'Answer %d' % self.id @@ -200,7 +200,7 @@ class Question(JSONModel): 'body_markdown', 'is_answered', 'link', 'answer_count', 'can_close', 'can_flag', 'close_vote_count', 'closed_reason', 'comment_count', 'community_owned_date', 'delete_vote_count', 'down_vote_count', - 'downvoted', 'favorite_count', 'favorited', 'is_answered', + 'downvoted', 'favorite_count', 'favorited', 'is_answered', 'accepted_answer_id', 'question_id', 'bounty_amount', 'upvoted', 'reopen_vote_count', 'share_link', 'up_vote_count', ('creation_date', UNIXTimestamp), @@ -217,7 +217,7 @@ class Question(JSONModel): ('comments', LazySequenceField(Comment, 'questions/{id}/comments', filter = '!-*7AsUyrEan0')), ('answers', ListOf(ModelRef(Answer)))) alias = (('id', 'question_id'), - ('accepted_answer', 'accepted_answer_id', IDPartial(Answer, lambda a: a.site.answer(a.id)))) + ('accepted_answer', 'accepted_answer_id', IDPartial(Answer, lambda a, **kwargs: a.site.answer(a.id, **kwargs)))) def _extend(self, json, site): if hasattr(json, 'owner') and 'user_id' in json.owner: @@ -232,8 +232,8 @@ def _extend(self, json, site): self.url = 'http://' + self.site.root_domain + '/questions/' + str(self.id) - def fetch_callback(self, _): - return self.site.question(self.id) + def fetch_callback(self, _, **kwargs): + return self.site.question(self.id, **kwargs) def linked(self): return self.site.questions(linked_to = self.id)