Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

magic-removal: fixed #1637 - django.contrib.comments still uses old m…

…ethods. Thanks Dave St.Germain and ubernostrum.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2722 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dbf2463cd62002919671e12325f02b2c8b741196 1 parent c3b7f4b
@jkocherhans jkocherhans authored
View
2  django/contrib/comments/feeds.py
@@ -25,7 +25,7 @@ def description(self):
return "Latest comments on %s" % self._site.name
def items(self):
- return self.comments_class.objects.get_list(**self._get_lookup_kwargs())
+ return self.comments_class.objects.filter(**self._get_lookup_kwargs())
def _get_lookup_kwargs(self):
return {
View
20 django/contrib/comments/models.py
@@ -48,9 +48,9 @@ def get_list_with_karma(self, **kwargs):
_karma_total_good and _karma_total_bad filled.
"""
kwargs.setdefault('select', {})
- kwargs['select']['_karma_total_good'] = 'SELECT COUNT(*) FROM comments_karma WHERE comments_karma.comment_id=comments.id AND score=1'
- kwargs['select']['_karma_total_bad'] = 'SELECT COUNT(*) FROM comments_karma WHERE comments_karma.comment_id=comments.id AND score=-1'
- return self.get_list(**kwargs)
+ kwargs['select']['_karma_total_good'] = 'SELECT COUNT(*) FROM comments_karmascore WHERE comments_karmascore.comment_id=comments.id AND score=1'
+ kwargs['select']['_karma_total_bad'] = 'SELECT COUNT(*) FROM comments_karmascore WHERE comments_karmascore.comment_id=comments.id AND score=-1'
+ return self.filter(**kwargs)
def user_is_moderator(self, user):
if user.is_superuser:
@@ -102,7 +102,7 @@ class Admin:
search_fields = ('comment', 'user__username')
def __repr__(self):
- return "%s: %s..." % (self.get_user().username, self.comment[:100])
+ return "%s: %s..." % (self.user.username, self.comment[:100])
def get_absolute_url(self):
return self.get_content_object().get_absolute_url() + "#c" + str(self.id)
@@ -156,7 +156,7 @@ def get_karma_total(self):
def get_as_text(self):
return _('Posted by %(user)s at %(date)s\n\n%(comment)s\n\nhttp://%(domain)s%(url)s') % \
- {'user': self.get_user().username, 'date': self.submit_date,
+ {'user': self.user.username, 'date': self.submit_date,
'comment': self.comment, 'domain': self.get_site().domain, 'url': self.get_absolute_url()}
class FreeComment(models.Model):
@@ -208,7 +208,7 @@ def get_content_object(self):
class KarmaScoreManager(models.Manager):
def vote(self, user_id, comment_id, score):
try:
- karma = self.get_object(comment__id__exact=comment_id, user__id__exact=user_id)
+ karma = self.objects.get(comment__id__exact=comment_id, user__id__exact=user_id)
except self.model.DoesNotExist:
karma = self.model(None, user_id, comment_id, score, datetime.datetime.now())
karma.save()
@@ -238,7 +238,7 @@ class Meta:
unique_together = (('user', 'comment'),)
def __repr__(self):
- return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.get_user()}
+ return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.user}
class UserFlagManager(models.Manager):
def flag(self, comment, user):
@@ -250,7 +250,7 @@ def flag(self, comment, user):
if int(comment.user_id) == int(user.id):
return # A user can't flag his own comment. Fail silently.
try:
- f = self.get_object(user__id__exact=user.id, comment__id__exact=comment.id)
+ f = self.objects.get(user__id__exact=user.id, comment__id__exact=comment.id)
except self.model.DoesNotExist:
from django.core.mail import mail_managers
f = self.model(None, user.id, comment.id, None)
@@ -269,7 +269,7 @@ class Meta:
unique_together = (('user', 'comment'),)
def __repr__(self):
- return _("Flag by %r") % self.get_user()
+ return _("Flag by %r") % self.user
class ModeratorDeletion(models.Model):
user = models.ForeignKey(User, verbose_name='moderator')
@@ -281,4 +281,4 @@ class Meta:
unique_together = (('user', 'comment'),)
def __repr__(self):
- return _("Moderator deletion by %r") % self.get_user()
+ return _("Moderator deletion by %r") % self.user
View
32 django/contrib/comments/templatetags/comments.py
@@ -2,15 +2,15 @@
from django.contrib.comments.models import PHOTOS_REQUIRED, PHOTOS_OPTIONAL, RATINGS_REQUIRED, RATINGS_OPTIONAL, IS_PUBLIC
from django.contrib.comments.models import MIN_PHOTO_DIMENSION, MAX_PHOTO_DIMENSION
from django import template
-from django.core.template import loader
+from django.template import loader
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.contenttypes.models import ContentType
import re
register = template.Library()
-COMMENT_FORM = 'comments/form'
-FREE_COMMENT_FORM = 'comments/freeform'
+COMMENT_FORM = 'comments/form.html'
+FREE_COMMENT_FORM = 'comments/freeform.html'
class CommentFormNode(template.Node):
def __init__(self, content_type, obj_id_lookup_var, obj_id, free,
@@ -77,12 +77,12 @@ def __init__(self, package, module, context_var_name, obj_id, var_name, free):
def render(self, context):
from django.conf import settings
- get_count_function = self.free and FreeComment.objects.get_count or Comment.objects.get_count
+ manager = self.free and FreeComment.objects or Comment.objects
if self.context_var_name is not None:
self.obj_id = template.resolve_variable(self.context_var_name, context)
- comment_count = get_count_function(object_id__exact=self.obj_id,
- content_type__package__label__exact=self.package,
- content_type__python_module_name__exact=self.module, site__id__exact=settings.SITE_ID)
+ comment_count = manager.filter(object_id__exact=self.obj_id,
+ content_type__app_label__exact=self.package,
+ content_type__model__exact=self.module, site__id__exact=settings.SITE_ID).count()
context[self.var_name] = comment_count
return ''
@@ -96,7 +96,7 @@ def __init__(self, package, module, context_var_name, obj_id, var_name, free, or
def render(self, context):
from django.conf import settings
- get_list_function = self.free and FreeComment.objects.get_list or Comment.objects.get_list_with_karma
+ get_list_function = self.free and FreeComment.objects.filter or Comment.objects.get_list_with_karma
if self.context_var_name is not None:
try:
self.obj_id = template.resolve_variable(self.context_var_name, context)
@@ -104,16 +104,14 @@ def render(self, context):
return ''
kwargs = {
'object_id__exact': self.obj_id,
- 'content_type__package__label__exact': self.package,
- 'content_type__python_module_name__exact': self.module,
+ 'content_type__app_label__exact': self.package,
+ 'content_type__model__exact': self.module,
'site__id__exact': settings.SITE_ID,
- 'select_related': True,
- 'order_by': (self.ordering + 'submit_date',),
}
kwargs.update(self.extra_kwargs)
if not self.free and settings.COMMENTS_BANNED_USERS_GROUP:
- kwargs['select'] = {'is_hidden': 'user_id IN (SELECT user_id FROM auth_users_groups WHERE group_id = %s)' % settings.COMMENTS_BANNED_USERS_GROUP}
- comment_list = get_list_function(**kwargs)
+ kwargs['select'] = {'is_hidden': 'user_id IN (SELECT user_id FROM auth_user_groups WHERE group_id = %s)' % settings.COMMENTS_BANNED_USERS_GROUP}
+ comment_list = get_list_function(**kwargs).order_by(self.ordering + 'submit_date').select_related()
if not self.free:
if context.has_key('user') and not context['user'].is_anonymous():
@@ -157,7 +155,7 @@ def __call__(self, parser, token):
except ValueError: # unpack list of wrong size
raise template.TemplateSyntaxError, "Third argument in %r tag must be in the format 'package.module'" % tokens[0]
try:
- content_type = ContentType.objects.get_object(package__label__exact=package, python_module_name__exact=module)
+ content_type = ContentType.objects.get(app_label__exact=package, model__exact=module)
except ContentType.DoesNotExist:
raise template.TemplateSyntaxError, "%r tag has invalid content-type '%s.%s'" % (tokens[0], package, module)
obj_id_lookup_var, obj_id = None, None
@@ -237,7 +235,7 @@ def __call__(self, parser, token):
except ValueError: # unpack list of wrong size
raise template.TemplateSyntaxError, "Third argument in %r tag must be in the format 'package.module'" % tokens[0]
try:
- content_type = ContentType.objects.get_object(package__label__exact=package, python_module_name__exact=module)
+ content_type = ContentType.objects.get(app_label__exact=package, model__exact=module)
except ContentType.DoesNotExist:
raise template.TemplateSyntaxError, "%r tag has invalid content-type '%s.%s'" % (tokens[0], package, module)
var_name, obj_id = None, None
@@ -292,7 +290,7 @@ def __call__(self, parser, token):
except ValueError: # unpack list of wrong size
raise template.TemplateSyntaxError, "Third argument in %r tag must be in the format 'package.module'" % tokens[0]
try:
- content_type = ContentType.objects.get_object(package__label__exact=package, python_module_name__exact=module)
+ content_type = ContentType.objects.get(app_label__exact=package,model__exact=module)
except ContentType.DoesNotExist:
raise template.TemplateSyntaxError, "%r tag has invalid content-type '%s.%s'" % (tokens[0], package, module)
var_name, obj_id = None, None
View
10 django/contrib/comments/views/comments.py
@@ -90,7 +90,7 @@ def get_comment(self, new_data):
def save(self, new_data):
today = datetime.date.today()
c = self.get_comment(new_data)
- for old in Comment.objects.get_list(content_type__id__exact=new_data["content_type_id"],
+ for old in Comment.objects.filter(content_type__id__exact=new_data["content_type_id"],
object_id__exact=new_data["object_id"], user__id__exact=self.get_user_id()):
# Check that this comment isn't duplicate. (Sometimes people post
# comments twice by mistake.) If it is, fail silently by pretending
@@ -146,7 +146,7 @@ def save(self, new_data):
# Check that this comment isn't duplicate. (Sometimes people post
# comments twice by mistake.) If it is, fail silently by pretending
# the comment was posted successfully.
- for old_comment in FreeComment.objects.get_list(content_type__id__exact=new_data["content_type_id"],
+ for old_comment in FreeComment.objects.filter(content_type__id__exact=new_data["content_type_id"],
object_id__exact=new_data["object_id"], person_name__exact=new_data["person_name"],
submit_date__year=today.year, submit_date__month=today.month,
submit_date__day=today.day):
@@ -202,7 +202,7 @@ def post_comment(request):
rating_range, rating_choices = [], []
content_type_id, object_id = target.split(':') # target is something like '52:5157'
try:
- obj = ContentType.objects.get_object(pk=content_type_id).get_object_for_this_type(pk=object_id)
+ obj = ContentType.objects.get(pk=content_type_id).get_object_for_this_type(pk=object_id)
except ObjectDoesNotExist:
raise Http404, _("The comment form had an invalid 'target' parameter -- the object ID was invalid")
option_list = options.split(',') # options is something like 'pa,ra'
@@ -285,7 +285,7 @@ def post_free_comment(request):
if Comment.objects.get_security_hash(options, '', '', target) != security_hash:
raise Http404, _("Somebody tampered with the comment form (security violation)")
content_type_id, object_id = target.split(':') # target is something like '52:5157'
- content_type = ContentType.objects.get_object(pk=content_type_id)
+ content_type = ContentType.objects.get(pk=content_type_id)
try:
obj = content_type.get_object_for_this_type(pk=object_id)
except ObjectDoesNotExist:
@@ -333,7 +333,7 @@ def comment_was_posted(request):
if request.GET.has_key('c'):
content_type_id, object_id = request.GET['c'].split(':')
try:
- content_type = ContentType.objects.get_object(pk=content_type_id)
+ content_type = ContentType.objects.get(pk=content_type_id)
obj = content_type.get_object_for_this_type(pk=object_id)
except ObjectDoesNotExist:
pass
View
12 django/contrib/comments/views/karma.py
@@ -1,7 +1,7 @@
from django.http import Http404
from django.shortcuts import render_to_response
from django.template import RequestContext
-from django.models.comments import comments, karma
+from django.contrib.comments.models import Comment, KarmaScore
def vote(request, comment_id, vote):
"""
@@ -18,12 +18,12 @@ def vote(request, comment_id, vote):
if request.user.is_anonymous():
raise Http404, _("Anonymous users cannot vote")
try:
- comment = comments.get_object(pk=comment_id)
- except comments.CommentDoesNotExist:
+ comment = Comment.objects.get(pk=comment_id)
+ except Comment.DoesNotExist:
raise Http404, _("Invalid comment ID")
- if comment.user_id == request.user.id:
+ if comment.user.id == request.user.id:
raise Http404, _("No voting for yourself")
- karma.vote(request.user.id, comment_id, rating)
+ KarmaScore.objects.vote(request.user.id, comment_id, rating)
# Reload comment to ensure we have up to date karma count
- comment = comments.get_object(pk=comment_id)
+ comment = Comment.objects.get(pk=comment_id)
return render_to_response('comments/karma_vote_accepted.html', {'comment': comment}, context_instance=RequestContext(request))
View
30 django/contrib/comments/views/userflags.py
@@ -1,7 +1,7 @@
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import Http404
-from django.models.comments import comments, moderatordeletions, userflags
+from django.contrib.comments.models import Comment, ModeratorDeletion, UserFlag
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.conf import settings
@@ -15,21 +15,15 @@ def flag(request, comment_id):
comment
the flagged `comments.comments` object
"""
- try:
- comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
- except comments.CommentDoesNotExist:
- raise Http404
+ comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
if request.POST:
- userflags.flag(comment, request.user)
+ UserFlag.objects.flag(comment, request.user)
return HttpResponseRedirect('%sdone/' % request.path)
return render_to_response('comments/flag_verify.html', {'comment': comment}, context_instance=RequestContext(request))
flag = login_required(flag)
def flag_done(request, comment_id):
- try:
- comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
- except comments.CommentDoesNotExist:
- raise Http404
+ comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
return render_to_response('comments/flag_done.html', {'comment': comment}, context_instance=RequestContext(request))
def delete(request, comment_id):
@@ -41,26 +35,20 @@ def delete(request, comment_id):
comment
the flagged `comments.comments` object
"""
- try:
- comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
- except comments.CommentDoesNotExist:
- raise Http404
- if not comments.user_is_moderator(request.user):
+ comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
+ if not Comment.objects.user_is_moderator(request.user):
raise Http404
if request.POST:
# If the comment has already been removed, silently fail.
if not comment.is_removed:
comment.is_removed = True
comment.save()
- m = moderatordeletions.ModeratorDeletion(None, request.user.id, comment.id, None)
+ m = ModeratorDeletion(None, request.user.id, comment.id, None)
m.save()
return HttpResponseRedirect('%sdone/' % request.path)
return render_to_response('comments/delete_verify.html', {'comment': comment}, context_instance=RequestContext(request))
delete = login_required(delete)
def delete_done(request, comment_id):
- try:
- comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
- except comments.CommentDoesNotExist:
- raise Http404
+ comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
return render_to_response('comments/delete_done.html', {'comment': comment}, context_instance=RequestContext(request))
Please sign in to comment.
Something went wrong with that request. Please try again.