-
Notifications
You must be signed in to change notification settings - Fork 24
Postmovement #80
base: master
Are you sure you want to change the base?
Postmovement #80
Changes from 1 commit
03bae0d
a95fa1a
c7fc246
2739bef
eefd50e
f3721e5
afe23b1
582d9fd
ac9ed72
fa13a33
b7e7355
91d0c4e
bedd944
cf10a31
2edef55
33a3850
2124bd7
9bdf974
ce3d6ff
5e5f092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…o comment.parent_id now safed.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -459,7 +459,10 @@ def keep_item(self, item): | |
| except AttributeError: | ||
| return True | ||
| else: | ||
| return False | ||
| if item.parent_id: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a really awkward way to write the function. You don't need the else block. Just save the result of the first access of |
||
| return False | ||
| else: | ||
| return True | ||
|
|
||
| class ContextualCommentBuilder(CommentBuilderMixin, UnbannedCommentBuilder): | ||
| def __init__(self, query, sr_ids, **kw): | ||
|
|
@@ -574,7 +577,7 @@ def get_items(self, num, nested = True, starting_depth = 0): | |
| top = self.comment | ||
| dont_collapse.append(top._id) | ||
| #add parents for context | ||
| while self.context > 0 and hasattr(top, 'parent_id'): | ||
| while self.context > 0 and hasattr(top, 'parent_id') and top.parent_id: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to see tests for |
||
| self.context -= 1 | ||
| new_top = comment_dict[top.parent_id] | ||
| comment_tree[new_top._id] = [top] | ||
|
|
@@ -657,7 +660,7 @@ def sort_candidates(): | |
| to_add = candidates.pop(0) | ||
| direct_child = True | ||
| #ignore top-level comments for now | ||
| if not hasattr(to_add, 'parent_id'): | ||
| if not hasattr(to_add, 'parent_id') or not to_add.parent_id: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above (favour |
||
| p_id = None | ||
| else: | ||
| #find the parent actually being displayed | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -923,6 +923,39 @@ def _new(cls, author, link, parent, body, ip, spam = False, date = None): | |
|
|
||
| return (comment, inbox_rel) | ||
|
|
||
| @classmethod | ||
| def _move(cls, comment, currlink, newlink, top=False): | ||
| author = Account._byID(comment.author_id) | ||
|
|
||
| if top: | ||
| if hasattr(comment, 'parent_id'): | ||
| comment.parent_id = None | ||
| comment.link_id = newlink._id | ||
| comment.sr_id = newlink.sr_id | ||
|
|
||
| comment._commit() | ||
|
|
||
| if not top: | ||
| parent = Comment._byID(comment.parent_id) | ||
| comment.parent_permalink = parent.make_anchored_permalink(Link._byID(parent.link_id), Subreddit._byID(parent.sr_id)) | ||
| comment.permalink = comment.make_permalink_slow() | ||
| comment._commit() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You commit the comment twice. Can one of these be avoided? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, changed. |
||
|
|
||
| currlink._incr('num_comments', -1) | ||
| newlink._incr('num_comments', 1) | ||
|
|
||
| #clear that chache | ||
| clear_memo('builder.link_comments2', newlink._id) | ||
| clear_memo('builder.link_comments2', currlink._id) | ||
|
|
||
| # flag search indexer that something has changed | ||
| tc.changed(comment) | ||
|
|
||
| #update last modified | ||
| set_last_modified(author, 'overview') | ||
| set_last_modified(author, 'commented') | ||
| set_last_modified(newlink, 'comments') | ||
|
|
||
| def try_parent(self, func, default): | ||
| """ | ||
| If this comment has a parent, return `func(parent)`; otherwise | ||
|
|
@@ -956,29 +989,17 @@ def has_children(self): | |
| child = list(q) | ||
| return len(child)>0 | ||
|
|
||
| def recursive_move(self, destination, parent): | ||
| def recursive_move(self, origin, destination, top=False): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to infer What are the types of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could, but then we'd needlessly increase the number of calls to query. I think that this way is better. |
||
| q = Comment._query(Comment.c.parent_id == self._id) | ||
| children = list(q) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
| comment, inbox_rel = Comment._new(Account._byID(self.author_id), | ||
| destination, parent, self.body, | ||
| self.ip) | ||
|
|
||
| Comment._move(self, origin, destination, top) | ||
|
|
||
| if not children: | ||
| pass | ||
| else: | ||
| for child in children: | ||
| child.recursive_move(destination, comment) | ||
|
|
||
|
|
||
| self.moderator_banned = not c.user_is_admin | ||
| self.banner = c.user.name | ||
| self.moved = True | ||
| self._commit() | ||
| # NB: change table updated by reporting | ||
| from r2.models.report import unreport | ||
| unreport(self, correct=True, auto=False) | ||
|
|
||
| if g.write_query_queue: | ||
| queries.new_comment(comment, None) | ||
| child.recursive_move(origin, destination) | ||
|
|
||
| def can_delete(self): | ||
| if not self._loaded: | ||
|
|
@@ -1105,7 +1126,7 @@ def add_props(cls, user, wrapped): | |
| item.link = links.get(item.link_id) | ||
| if not hasattr(item, 'subreddit'): | ||
| item.subreddit = item.subreddit_slow | ||
| if hasattr(item, 'parent_id'): | ||
| if hasattr(item, 'parent_id') and item.parent_id: | ||
| parent = Comment._byID(item.parent_id, data=True) | ||
| parent_author = Account._byID(parent.author_id, data=True) | ||
| item.parent_author = parent_author | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ## The contents of this file are subject to the Common Public Attribution | ||
| ## License Version 1.0. (the "License"); you may not use this file except in | ||
| ## compliance with the License. You may obtain a copy of the License at | ||
| ## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public | ||
| ## License Version 1.1, but Sections 14 and 15 have been added to cover use of | ||
| ## software over a computer network and provide for limited attribution for the | ||
| ## Original Developer. In addition, Exhibit A has been modified to be consistent | ||
| ## with Exhibit B. | ||
| ## | ||
| ## Software distributed under the License is distributed on an "AS IS" basis, | ||
| ## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for | ||
| ## the specific language governing rights and limitations under the License. | ||
| ## | ||
| ## The Original Code is Reddit. | ||
| ## | ||
| ## The Original Developer is the Initial Developer. The Initial Developer of | ||
| ## the Original Code is CondeNet, Inc. | ||
| ## | ||
| ## All portions of the code written by CondeNet are Copyright (c) 2006-2008 | ||
| ## CondeNet, Inc. All Rights Reserved. | ||
| ################################################################################ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "A comment was moved to here." will be a bit clearer. In its current form, you have "here" referring to both the current location and the new location, which is a little confusing.
Also, is it possible to hide the children of the moved comment as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are hidden, you just have to refresh.