Skip to content

Commit b668fdb

Browse files
committed
simplify getting content_type for comment
1 parent 70839d2 commit b668fdb

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

django_comments_xtd/api/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def validate(self, data):
210210
elif data['flag'] == 'report':
211211
option = 'allow_flagging'
212212
comment = data['comment']
213-
ctype = ContentType.objects.get_for_model(comment.content_object)
213+
ctype = comment.content_type
214214
key = "%s.%s" % (ctype.app_label, ctype.model)
215215
if not get_app_model_options(content_type=key)[option]:
216216
raise serializers.ValidationError(

django_comments_xtd/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from urllib import urlencode
1515

1616
from django.core.mail import EmailMultiAlternatives
17-
from django.contrib.contenttypes.models import ContentType
1817
from django.contrib.sites.shortcuts import get_current_site
1918
from django.utils.crypto import salted_hmac
2019

@@ -86,7 +85,7 @@ def get_app_model_options(comment=None, content_type=None):
8685
default = copy(settings.COMMENTS_XTD_APP_MODEL_OPTIONS['default'])
8786

8887
if comment:
89-
content_type = ContentType.objects.get_for_model(comment.content_object)
88+
content_type = comment.content_type
9089
key = "%s.%s" % (content_type.app_label, content_type.model)
9190
elif content_type:
9291
key = content_type

django_comments_xtd/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def flag(request, comment_id, next=None):
391391
get_comment_model(), pk=comment_id,
392392
site__pk=get_current_site_id(request))
393393
if not get_app_model_options(comment=comment)['allow_flagging']:
394-
ctype = ContentType.objects.get_for_model(comment.content_object)
394+
ctype = comment.content_type
395395
raise Http404("Comments posted to instances of '%s.%s' are not "
396396
"explicitly allowed to receive 'removal suggestion' "
397397
"flags. Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
@@ -423,7 +423,7 @@ def like(request, comment_id, next=None):
423423
comment = get_object_or_404(get_comment_model(), pk=comment_id,
424424
site__pk=get_current_site_id(request))
425425
if not get_app_model_options(comment=comment)['allow_feedback']:
426-
ctype = ContentType.objects.get_for_model(comment.content_object)
426+
ctype = comment.content_type
427427
raise Http404("Comments posted to instances of '%s.%s' are not "
428428
"explicitly allowed to receive 'liked it' flags. "
429429
"Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
@@ -459,7 +459,7 @@ def dislike(request, comment_id, next=None):
459459
comment = get_object_or_404(get_comment_model(), pk=comment_id,
460460
site__pk=get_current_site_id(request))
461461
if not get_app_model_options(comment=comment)['allow_feedback']:
462-
ctype = ContentType.objects.get_for_model(comment.content_object)
462+
ctype = comment.content_type
463463
raise Http404("Comments posted to instances of '%s.%s' are not "
464464
"explicitly allowed to receive 'disliked it' flags. "
465465
"Check the COMMENTS_XTD_APP_MODEL_OPTIONS "

0 commit comments

Comments
 (0)