Skip to content

Commit 253d162

Browse files
author
Haojun Li
committed
feat(user): added support for marking two posts as duplicates
1 parent f65c042 commit 253d162

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

piazza_api/network.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,27 @@ def create_instructor_answer(self, post, content, revision, anonymous=False):
173173
}
174174
return self._rpc.content_instructor_answer(params)
175175

176+
def mark_as_duplicate(self, duplicated_cid, master_cid, msg=''):
177+
"""Mark the post at DUPLICATED_CID as a duplicate of MASTER_CID
178+
179+
:type duplicated_cid: int
180+
:param duplicated_cid: The numeric id of the duplicated post
181+
:type master_cid: int
182+
:param master_cid: The numeric id of an older post. This will be the
183+
post that gets kept and DUPLICATED_CID post will be concatinated
184+
as a follow up to MASTER_CID post.
185+
:returns True if it is successful. False otherwise
186+
"""
187+
try:
188+
content_id_from = self.get_post(duplicated_cid)['id']
189+
content_id_to = self.get_post(master_cid)['id']
190+
except:
191+
return False
192+
params = {'cid_dupe': content_id_from,
193+
'cid_to': content_id_to,
194+
'msg': msg}
195+
return self._rpc.content_mark_duplicate(params) == 'OK'
196+
176197
#########
177198
# Users #
178199
#########

piazza_api/rpc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ def content_instructor_answer(self, params):
127127
return self._handle_error(r, "Could not create object {}.".format(
128128
repr(params)))
129129

130+
def content_mark_duplicate(self, params):
131+
"""Mark a post as duplicate to another.
132+
133+
:type params: dict
134+
:param params: the parameters to be passed in
135+
:returns python object containting returned data
136+
"""
137+
r = self.request(
138+
method="content.duplicate",
139+
data=params
140+
)
141+
return self._handle_error(r, "Could not create object {}.".format(
142+
repr(params)))
130143

131144
def add_students(self, student_emails, nid=None):
132145
"""Enroll students in a network `nid`.

0 commit comments

Comments
 (0)