Do not include developer replies in user review lists (bug 555859)
This commit is contained in:
Родитель
1779277fb2
Коммит
6b6e53ddda
|
@ -10,7 +10,7 @@ from translations.models import Translation
|
|||
class Review(amo.models.ModelBase):
|
||||
|
||||
version = models.ForeignKey('versions.Version', related_name='reviews')
|
||||
user = models.ForeignKey('users.UserProfile', related_name='reviews')
|
||||
user = models.ForeignKey('users.UserProfile', related_name='_reviews_all')
|
||||
reply_to = models.ForeignKey('self', null=True, unique=True,
|
||||
db_column='reply_to')
|
||||
|
||||
|
|
|
@ -107,6 +107,11 @@ class UserProfile(amo.models.ModelBase):
|
|||
|
||||
return ''
|
||||
|
||||
@amo.cached_property
|
||||
def reviews(self):
|
||||
"""All reviews that are not dev replies."""
|
||||
return self._reviews_all.filter(reply_to=None)
|
||||
|
||||
def save(self, force_insert=False, force_update=False, using=None):
|
||||
# we have to fix stupid things that we defined poorly in remora
|
||||
if self.resetcode_expires is None:
|
||||
|
|
|
@ -40,11 +40,13 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% set reviews = profile.reviews %}
|
||||
{% cache reviews %}
|
||||
<div class="primary" id="userprofile-reviews">
|
||||
<h3>{{ _('My Reviews') }}</h3>
|
||||
<div class="article">
|
||||
{% if profile.reviews.all()|length %}
|
||||
{% for review in profile.reviews.all() %}
|
||||
{% if reviews %}
|
||||
{% for review in reviews %}
|
||||
{% set addon = review.version.addon %}
|
||||
<div class="hreview">
|
||||
<h4 class="summary">
|
||||
|
@ -60,12 +62,13 @@
|
|||
</abbr>
|
||||
</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="noreviews">{{ _('No add-on reviews yet.') }}</p>
|
||||
{% endif %}
|
||||
</div>{# /article #}
|
||||
</div>{# /primary #}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p class="noreviews">{{ _('No add-on reviews yet.') }}</p>
|
||||
{% endif %}
|
||||
</div>{# /article #}
|
||||
</div>{# /primary #}
|
||||
{% endcache %}
|
||||
|
||||
{% if own_coll or fav_coll %}
|
||||
<div class="secondary" role="complementary">
|
||||
|
|
|
@ -5,10 +5,13 @@ from django import test
|
|||
|
||||
from nose.tools import eq_
|
||||
|
||||
from addons.models import Addon
|
||||
from reviews.models import Review
|
||||
from users.models import UserProfile, get_hexdigest
|
||||
|
||||
|
||||
class TestUserProfile(test.TestCase):
|
||||
fixtures = ['base/addons.json']
|
||||
|
||||
def test_display_name_nickname(self):
|
||||
u = UserProfile(nickname='Terminator', pk=1)
|
||||
|
@ -25,7 +28,7 @@ class TestUserProfile(test.TestCase):
|
|||
eq_(u4.welcome_name, '')
|
||||
|
||||
def test_empty_nickname(self):
|
||||
u = UserProfile.objects.create(email='yoyoyo@yo.yo')
|
||||
u = UserProfile.objects.create(email='yoyoyo@yo.yo', nickname='yoyo')
|
||||
assert u.user is None
|
||||
u.create_django_user()
|
||||
eq_(u.user.username, 'yoyoyo@yo.yo')
|
||||
|
@ -58,6 +61,28 @@ class TestUserProfile(test.TestCase):
|
|||
u = UserProfile(id=1234, picture_type=None)
|
||||
assert u.picture_url.endswith('/anon_user.png')
|
||||
|
||||
def test_review_replies(self):
|
||||
"""
|
||||
Make sure that developer replies are not returned as if they were
|
||||
original reviews.
|
||||
"""
|
||||
addon = Addon.objects.get(id=3615)
|
||||
u = UserProfile.objects.get(pk=2519)
|
||||
version = addon.current_version
|
||||
new_review = Review(version=version, user=u, rating=2, body='hello')
|
||||
new_review.save()
|
||||
new_reply = Review(version=version, user=u, reply_to=new_review,
|
||||
body='my reply')
|
||||
new_reply.save()
|
||||
|
||||
review_list = [ r.pk for r in u.reviews ]
|
||||
|
||||
eq_(len(review_list), 1)
|
||||
assert new_review.pk in review_list, (
|
||||
'Original review must show up in review list.')
|
||||
assert new_reply.pk not in review_list, (
|
||||
'Developer reply must not show up in review list.')
|
||||
|
||||
|
||||
class TestPasswords(test.TestCase):
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче