Skip to content

Commit 4373297

Browse files
authored
Merge pull request #36 from LithiumH/develop
feat(user): added support for marking two posts as duplicates
2 parents f65c042 + 0911cc6 commit 4373297

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

piazza_api/network.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,28 @@ 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+
:type msg: string
186+
:param msg: the optional message (or reason for marking as duplicate)
187+
:returns: True if it is successful. False otherwise
188+
"""
189+
content_id_from = self.get_post(duplicated_cid)["id"]
190+
content_id_to = self.get_post(master_cid)["id"]
191+
params = {
192+
"cid_dupe": content_id_from,
193+
"cid_to": content_id_to,
194+
"msg": msg
195+
}
196+
return self._rpc.content_mark_duplicate(params)
197+
176198
#########
177199
# Users #
178200
#########

piazza_api/rpc.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ def content_create(self, params):
109109
method="content.create",
110110
data=params
111111
)
112-
return self._handle_error(r, "Could not create object {}.".format(
113-
repr(params)))
112+
return self._handle_error(
113+
r,
114+
"Could not create object {}.".format(repr(params))
115+
)
114116

115117
def content_instructor_answer(self, params):
116118
"""Answer a post as an instructor.
@@ -127,6 +129,18 @@ def content_instructor_answer(self, params):
127129
return self._handle_error(r, "Could not create object {}.".format(
128130
repr(params)))
129131

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

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

0 commit comments

Comments
 (0)