From 8095ac8b40b226d2e2179462fc4b6a4a162452c0 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Fri, 1 Feb 2013 20:30:17 +0100 Subject: [PATCH] Fetch post_data when needed --- diaspy/models.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/diaspy/models.py b/diaspy/models.py index 4700d21..3302c76 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -21,11 +21,14 @@ class Post: before calling any of the post functions. """ - self._client = client + self.post_id = post_id + + + def fetch_data(self): r = self._client.session.get(self._client.pod + '/posts/' + - post_id + + self.post_id + '.json') if r.status_code == 200: self.data = r.json() @@ -43,7 +46,7 @@ class Post: r = self._client.session.post(self._client.pod + '/posts/' + - str(self.data['id']) + + self.post_id + '/likes', data=data, headers={'accept': 'application/json'}) @@ -60,10 +63,12 @@ class Post: data = {'authenticity_token': self._client.get_token()} + post_data = self.fetch_data() + r = self._client.session.delete(self._client.pod + '/posts/' + - str(self.data['id']) + + self.post_id + '/likes/' + - str(self.data['interactions'] + str(post_data['interactions'] ['likes'][0]['id']), data=data) @@ -76,7 +81,9 @@ class Post: """ - data = {'root_guid': self.data['guid'], + post_data = self.fetch_data() + + data = {'root_guid': post_data['guid'], 'authenticity_token': self._client.get_token()} r = self._client.session.post(self._client.pod + @@ -105,7 +112,7 @@ class Post: r = self._client.session.post(self._client.pod + '/posts/' + - str(self.data['id']) + + self.post_id + '/comments', data=data, headers={'accept': 'application/json'}) @@ -129,7 +136,7 @@ class Post: data = {'authenticity_token': self._client.get_token()} r = self._client.session.delete(self._client.pod + '/posts/' + - str(self.data['id']) + + self.post_id + '/comments/' + comment_id, data=data, -- 2.25.1