-
Notifications
You must be signed in to change notification settings - Fork 23
Postmovement #80
base: master
Are you sure you want to change the base?
Postmovement #80
Changes from 16 commits
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
from reddit_base import RedditController | ||
|
||
from pylons.i18n import _ | ||
from pylons import c, request, response | ||
from pylons import c, request, response, g | ||
from pylons.controllers.util import etag_cache | ||
|
||
import hashlib | ||
|
@@ -199,6 +199,58 @@ def POST_verifyemail(self, res, code): | |
c.user._commit() | ||
res._success() | ||
|
||
@Json | ||
@validate(VModhash(), | ||
VSrCanBan('id'), | ||
thing = VByName('id'), | ||
ip = ValidIP(), | ||
destination = VMoveURL('destination'), | ||
reason = VComment('comment')) | ||
def POST_move(self, res, thing, destination, reason, ip): | ||
res._update('status_' + thing._fullname, innerHTML = '') | ||
if res._chk_errors((errors.NO_URL, errors.BAD_URL), | ||
thing._fullname): | ||
res._focus("destination_url_" + thing._fullname) | ||
return | ||
if res._chk_error(errors.COMMENT_TOO_LONG, | ||
thing._fullname): | ||
res._focus("comment_replacement_" + thing._fullname) | ||
return | ||
if destination._id == thing.link_id: | ||
c.errors.add(errors.ALREADY_MOVED) | ||
res._chk_error(errors.ALREADY_MOVED, thing._fullname) | ||
res._focus("destination_url_" + thing._fullname) | ||
return | ||
|
||
currlink = Link._byID(thing.link_id) | ||
currlink._incr('_descendant_karma', -(thing._descendant_karma + thing._ups - thing._downs)) | ||
destination._incr('_descendant_karma', thing._descendant_karma + thing._ups - thing._downs) | ||
if hasattr(thing, 'parent_id'): | ||
parent = Comment._byID(thing.parent_id) | ||
parent.incr_descendant_karma([], -(thing._descendant_karma + thing._ups - thing._downs)) | ||
else: | ||
parent = None | ||
|
||
from r2.lib.comment_tree import lock_key, comments_key | ||
|
||
with g.make_lock(lock_key(thing.link_id)): | ||
thing.recursive_move(currlink, destination, True) | ||
|
||
g.permacache.delete(comments_key(currlink._id)) | ||
g.permacache.delete(comments_key(destination._id)) | ||
|
||
body = "A comment was moved from here to [here]({0}).\n\n".format(thing.make_anchored_permalink(destination)) + (reason if reason else '') | ||
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 "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 commentThe reason will be displayed to describe this comment to others. Learn more. They are hidden, you just have to refresh. |
||
|
||
comment, inbox_rel = Comment._new(c.user, | ||
currlink, parent, body, | ||
ip) | ||
|
||
|
||
if g.write_query_queue: | ||
queries.new_comment(comment, None) | ||
|
||
res._send_things([comment, thing]) | ||
|
||
@Json | ||
@validate(VCaptcha(), | ||
VUser(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,30 +129,50 @@ def get_rel_type_table(metadata): | |
|
||
|
||
def get_thing_table(metadata, name): | ||
table = sa.Table(settings.DB_APP_NAME + '_thing_' + name, metadata, | ||
sa.Column('thing_id', BigInteger, primary_key = True), | ||
sa.Column('ups', sa.Integer, default = 0, nullable = False), | ||
sa.Column('downs', | ||
sa.Integer, | ||
default = 0, | ||
nullable = False), | ||
sa.Column('deleted', | ||
sa.Boolean, | ||
default = False, | ||
nullable = False), | ||
sa.Column('spam', | ||
sa.Boolean, | ||
default = False, | ||
nullable = False), | ||
sa.Column('date', | ||
sa.DateTime(timezone = True), | ||
default = sa.func.now(), | ||
nullable = False)) | ||
if name in ('comment', 'link'): | ||
table.append_column(sa.Column('descendant_karma', | ||
sa.Integer, | ||
default = 0, | ||
nullable = False)) | ||
if name not in ('comment', 'link'): | ||
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. Looks like you've caused a fair bit of duplication here. Why is this? 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. Just adding the column doesn't work. |
||
table = sa.Table(settings.DB_APP_NAME + '_thing_' + name, metadata, | ||
sa.Column('thing_id', BigInteger, primary_key = True), | ||
sa.Column('ups', sa.Integer, default = 0, nullable = False), | ||
sa.Column('downs', | ||
sa.Integer, | ||
default = 0, | ||
nullable = False), | ||
sa.Column('deleted', | ||
sa.Boolean, | ||
default = False, | ||
nullable = False), | ||
sa.Column('spam', | ||
sa.Boolean, | ||
default = False, | ||
nullable = False), | ||
sa.Column('date', | ||
sa.DateTime(timezone = True), | ||
default = sa.func.now(), | ||
nullable = False)) | ||
else: | ||
table = sa.Table(settings.DB_APP_NAME + '_thing_' + name, metadata, | ||
sa.Column('thing_id', BigInteger, primary_key = True), | ||
sa.Column('ups', sa.Integer, default = 0, nullable = False), | ||
sa.Column('downs', | ||
sa.Integer, | ||
default = 0, | ||
nullable = False), | ||
sa.Column('deleted', | ||
sa.Boolean, | ||
default = False, | ||
nullable = False), | ||
sa.Column('spam', | ||
sa.Boolean, | ||
default = False, | ||
nullable = False), | ||
sa.Column('date', | ||
sa.DateTime(timezone = True), | ||
default = sa.func.now(), | ||
nullable = False), | ||
sa.Column('descendant_karma', | ||
sa.Integer, | ||
default = 0, | ||
nullable = False)) | ||
|
||
return table | ||
|
||
|
@@ -542,11 +562,19 @@ def get_thing(type_id, thing_id): | |
#if single, only return one storage, otherwise make a dict | ||
res = {} if not single else None | ||
for row in r: | ||
stor = storage(ups = row.ups, | ||
downs = row.downs, | ||
date = row.date, | ||
deleted = row.deleted, | ||
spam = row.spam) | ||
if type_id in (1, 7): | ||
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. What are types 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. Comment and Link. Maybe... could ask the comment and link classes for their type ids. 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 it turns out yes. Changed. |
||
stor = storage(ups = row.ups, | ||
downs = row.downs, | ||
date = row.date, | ||
deleted = row.deleted, | ||
spam = row.spam, | ||
descendant_karma = row.descendant_karma) | ||
else: | ||
stor = storage(ups = row.ups, | ||
downs = row.downs, | ||
date = row.date, | ||
deleted = row.deleted, | ||
spam = row.spam) | ||
if single: | ||
res = stor | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -644,6 +644,7 @@ def __init__(self, link = None, comment = None, | |
|
||
# link is a wrapped Link object | ||
self.link = self.link_listing.things[0] | ||
self.movebox = MoveBox() | ||
|
||
link_title = ((self.link.title) if hasattr(self.link, 'title') else '') | ||
if comment: | ||
|
@@ -665,7 +666,7 @@ def __init__(self, link = None, comment = None, | |
Reddit.__init__(self, title = title, body_class = 'post', robots = self.robots, *a, **kw) | ||
|
||
def content(self): | ||
return self.content_stack(self.infobar, self.link_listing, self._content) | ||
return self.content_stack(self.infobar, self.link_listing, self.movebox, self._content) | ||
|
||
def build_toolbars(self): | ||
return [] | ||
|
@@ -989,6 +990,12 @@ def __init__(self, link_name='', captcha=None, action = 'comment'): | |
Wrapped.__init__(self, link_name = link_name, captcha = captcha, | ||
action = action) | ||
|
||
class MoveBox(Wrapped): | ||
"""Used on LinkInfoPage to render the move thread form.""" | ||
def __init__(self, link_name='', captcha=None, action = 'comment'): | ||
Wrapped.__init__(self, link_name = link_name, captcha = captcha, | ||
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. Why is the default action for a move thread form "comment"? 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. No reason. Holdover from the initialization for what the movebox was created from. I'll remove it. |
||
action = action) | ||
|
||
class CommentListing(Wrapped): | ||
"""Comment heading and sort, limit options""" | ||
def __init__(self, content, num_comments, nav_menus = []): | ||
|
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 | ||
|
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.
Pylons gives me an error here when I try to move a comment thread to a different article:
I had created a couple of articles while on the master branch, then switched to the postmovement branch and tried to move some comments around and got this error. Perhaps it is relying on something that is not being set by current (in production) code?
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.
You have to run a script in the sql folder to add descendant karma to the SQL database.
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.
Also, you need #94.