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 1 commit
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
Prev Previous commit
Next Next commit
Descendant karma attribute no longer disappears off python objects.
  • Loading branch information
LucasSloan committed Oct 1, 2013
commit 91d0c4e00b451f871adf9afed542b0fe9ee6b9b8
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
21 changes: 17 additions & 4 deletions r2/r2/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@ class Comment(Thing, Printable):
banned_before_moderator = False,
is_html = False,
retracted = False,
show_response_to = False,
_descendant_karma = 0)
show_response_to = False)
#_descendant_karma = 0)

def _markdown(self):
pass
Expand Down Expand Up @@ -1054,8 +1054,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 @@ -1197,6 +1196,20 @@ 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:
print descendant_karma
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