Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
03bae0d
Moderators can now move comment threads between posts.
LucasSloan Jul 23, 2013
a95fa1a
Children of original movers now hidden for non-admins.
LucasSloan Jul 23, 2013
c7fc246
Made it impossible to vote on moved items.
LucasSloan Jul 23, 2013
2739bef
Status message removed in the event of failed call.
LucasSloan Jul 23, 2013
eefd50e
Entering an properly formatted URL that doesn't lead to a post sends …
LucasSloan Jul 23, 2013
f3721e5
Changed movebox doc string, renamed Link._byURL to Link._move_url.
LucasSloan Jul 24, 2013
afe23b1
Added a lock to movement.
LucasSloan Jul 24, 2013
582d9fd
Changed move proceedure to no longer create new comments. All calls …
LucasSloan Jul 27, 2013
ac9ed72
Removed debugging statements, moved boolean.
LucasSloan Jul 27, 2013
fa13a33
Safed movement against editor trying to move children of already move…
LucasSloan Jul 27, 2013
b7e7355
Merge branch 'interesting_comments' of https://github.com/PotatoDumpl…
LucasSloan Sep 21, 2013
91d0c4e
Descendant karma attribute no longer disappears off python objects.
LucasSloan Oct 1, 2013
bedd944
Merge branch 'interesting_comments' of https://github.com/PotatoDumpl…
LucasSloan Oct 1, 2013
cf10a31
Thread movement now properly increments descendant karma.
LucasSloan Oct 1, 2013
2edef55
Descendant karma attribute no longer disappears off python objects.
LucasSloan Oct 1, 2013
33a3850
Merge branch 'interesting_comments' of https://github.com/PotatoDumpl…
LucasSloan Oct 1, 2013
2124bd7
Changed testing syntax.
LucasSloan Dec 9, 2013
9bdf974
Merge branch 'postmovement' of https://github.com/PotatoDumplings/les…
LucasSloan Dec 9, 2013
ce3d6ff
Merge branch 'master' of https://github.com/tricycle/lesswrong into p…
LucasSloan Dec 9, 2013
5e5f092
Variety of small changes for readability.
LucasSloan Dec 9, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions r2/r2/controllers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,11 @@ def POST_move(self, res, thing, destination, reason, ip):
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))
Copy link
Contributor

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:

Module r2.lib.jsonresponse:181 in _Json        
>>  val = func(self, res, *a, **kw)
Module r2.controllers.validator.validator:78 in newfn        
>>  return fn(self, *a, **kw)
Module r2.controllers.api:229 in POST_move        
>>  currlink._incr('_descendant_karma', -(thing._descendant_karma + thing._ups - thing._downs))
Module r2.lib.db.thing:497 in __getattr__        
>>  return DataThing.__getattr__(self, attr)
Module r2.lib.db.thing:124 in __getattr__        
>>  raise AttributeError, '%s not found' % attr
<type 'exceptions.AttributeError'>: _descendant_karma not found 

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you need #94.

else:
parent = None

Expand Down
86 changes: 57 additions & 29 deletions r2/r2/lib/db/tdb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Expand Down Expand Up @@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are types 1 and 7, and is it possible to write this without resorting to magic numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:
Expand Down
32 changes: 28 additions & 4 deletions r2/r2/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,19 @@ def prev_link(self):
q = self._link_nav_query(sort = operators.desc('_date'))
return self._link_for_query(q)

def __init__(self, ups = 0, downs = 0, date = None, deleted = False,
spam = False, id = None, descendant_karma = 0, **attrs):

Thing.__init__(self, ups, downs, date, deleted, spam, id, **attrs)

with self.safe_set_attr:
self._descendant_karma = descendant_karma

@classmethod
def _build(cls, id, bases):
return cls(bases.ups, bases.downs, bases.date,
bases.deleted, bases.spam, id, bases.descendant_karma)

def _commit(self, *a, **kw):
"""Detect when we need to invalidate the sidebar recent posts.

Expand Down Expand Up @@ -892,8 +905,7 @@ class Comment(Thing, Printable):
banned_before_moderator = False,
is_html = False,
retracted = False,
show_response_to = False,
_descendant_karma = 0)
show_response_to = False)

def _markdown(self):
pass
Expand Down Expand Up @@ -1113,8 +1125,7 @@ def reply_costs_karma(self):
return self.try_parent(lambda p: p.reply_costs_karma, False)

def incr_descendant_karma(self, comments, amount):

old_val = getattr(self, '_descendant_karma')
old_val = self._get_item(self._type_id, self._id).descendant_karma

comments.append(self._id)

Expand Down Expand Up @@ -1256,6 +1267,19 @@ def add_props(cls, user, wrapped):
item.permalink = item.make_permalink(item.link, item.subreddit)
item.can_be_deleted = item.can_delete()

def __init__(self, ups = 0, downs = 0, date = None, deleted = False,
spam = False, id = None, descendant_karma = 0, **attrs):

Thing.__init__(self, ups, downs, date, deleted, spam, id, **attrs)

with self.safe_set_attr:
self._descendant_karma = descendant_karma

@classmethod
def _build(cls, id, bases):
return cls(bases.ups, bases.downs, bases.date,
bases.deleted, bases.spam, id, bases.descendant_karma)

def _commit(self, *a, **kw):
"""Detect when we need to invalidate the sidebar recent comments.

Expand Down
7 changes: 7 additions & 0 deletions r2/r2/templates/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@
%if thing.can_ban:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this shown if thing.can_ban? Does this mean that "can_ban" is becoming a flag that means "has moderation powers", and if so, should it be renamed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can_ban already is that flag. I'm against renaming it, it seems pretty self explanatory.

<li class="move">
${parent.simple_button("move", fullname, _("Move"), "move", tool_tip=_("Move"))}
%endif
%if c.user_is_loggedin and not thing.author == c.user:
<li class='subscribe'>
${parent.state_button("commentsubscribe", fullname, _("Subscribe"), \
"return change_state_by_class(this, '%s', 'mod')"%("commentunsubscribe" if thing.comment_subscribed(c.user, thing) else "commentsubscribe"), \
_("Subscribed"), a_class="subscription"+(" mod" if thing.comment_subscribed(c.user, thing) else ""), \
tool_tip = "No longer receive notifications for this comment" if thing.comment_subscribed(c.user, thing) else "Get notifications of immediate replies on this comment")}
</li>
%endif
</ul>
Expand Down