def get(self, *args, **kwargs):
try:
- pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact') or k.endswith('_ptr__pk')][0]
+ pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact'
+ ) or k.endswith('_ptr__pk') or k.endswith('_ptr__id')][0]
except:
pk = None
return '[%s] voted at %s: %s' %(self.user, self.voted_at, self.vote)
def _update_post_vote_count(self, diff):
- post = self.node
+ post = self.node.leaf
field = self.vote == 1 and 'vote_up_count' or 'vote_down_count'
post.__dict__[field] = post.__dict__[field] + diff
post.save()
@super_user_required
def recalculate_denormalized(request):
for n in Node.objects.all():
+ n = n.leaf
n.vote_up_count = n.votes.filter(canceled=False, vote=1).count()
n.vote_down_count = n.votes.filter(canceled=False, vote=-1).count()
n.save()
@command
def vote_post(request, id, vote_type):
- post = get_object_or_404(Node, id=id)
+ post = get_object_or_404(Node, id=id).leaf
vote_score = vote_type == 'up' and 1 or -1
user = request.user
def question(request, id, slug):
try:
- question = Question.objects.get(id=id)
+ question = Question.objects.get(node_type="question", id=id)
except:
question = match_question_slug(slug)
if question is not None: