Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop' into fix-comment-form
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Dec 28, 2016
2 parents 740d207 + a5f1eff commit 170d270
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 116 deletions.
2 changes: 1 addition & 1 deletion config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pillow
markdown2>=2.3.0
djangorestframework
django-permission>=0.8.8
django-filter>=0.15.3,<1
django-filter>=1.0.0
django-roughpages>=0.1.2
django-thumbnailfield>=0.2.3
django-inspectional-registration
Expand Down
4 changes: 2 additions & 2 deletions src/kawaz/apps/events/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ def test_list_with_categories(self):
password='password'))
r = self.client.get('/events/?category={}'.format(category.pk))
self.assertTemplateUsed(r, 'events/event_list.html')
self.assertEqual(len(r.context['filter']), 1)
self.assertTrue(event1 in r.context['filter'])
self.assertEqual(r.context['filter'].qs.count(), 1)
self.assertTrue(event1 in r.context['filter'].qs)


@mock.patch('django.utils.timezone.now', static_now)
Expand Down
2 changes: 1 addition & 1 deletion src/kawaz/apps/kfm/extras/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


PATTERN = re.compile(
r"https?://www\.youtube\.com/watch\?v=(?P<id>[a-zA-Z0-9_\-]+)"
r"https?://(:?www\.youtube\.com/watch\?v=|youtu\.be/)(?P<id>[a-zA-Z0-9_\-]+)"
)
TEMPLATE_NAME = r"kfm/extras/youtube.html"

Expand Down
6 changes: 6 additions & 0 deletions src/kawaz/apps/kfm/tests/test_extras/test_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def test_parse_youtube_urls(self):
value = parse_youtube_urls(value)
self.assertEqual(value, self._render_template(self.video_id))

def test_parse_shorten_youtube_urls(self):
"""短縮されたYouTubeのURLは展開される"""
value = "https://youtu.be/{}".format(self.video_id)
value = parse_youtube_urls(value)
self.assertEqual(value, self._render_template(self.video_id))

def test_parse_youtube_urls_responsive(self):
"""YouTubeのURLはレスポンシブ展開される"""
value = self.template_str.format(self.video_id)
Expand Down
14 changes: 7 additions & 7 deletions src/kawaz/apps/products/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_anyone_can_see_product_list(self):
r = self.client.get('/products/')
self.assertEqual(r.status_code, 200)
self.assertTemplateUsed(r, 'products/product_list.html')
self.assertIn(product, r.context['filter'])
self.assertIn(product, r.context['filter'].qs)

def test_list_with_platforms(self):
"""
Expand All @@ -110,9 +110,9 @@ def test_list_with_platforms(self):
self.prefer_login(user)
r = self.client.get('/products/?platforms={}'.format(self.p0.pk))
self.assertTemplateUsed(r, 'products/product_list.html')
self.assertEqual(len(r.context['filter']), 1)
self.assertIn(product1, r.context['filter'])
self.assertNotIn(product2, r.context['filter'])
self.assertEqual(r.context['filter'].qs.count(), 1)
self.assertIn(product1, r.context['filter'].qs)
self.assertNotIn(product2, r.context['filter'].qs)

def test_list_with_categories(self):
"""
Expand All @@ -123,9 +123,9 @@ def test_list_with_categories(self):
self.prefer_login(self.members[0])
r = self.client.get('/products/?categories={}'.format(self.c0.pk))
self.assertTemplateUsed(r, 'products/product_list.html')
self.assertEqual(len(r.context['filter']), 1)
self.assertIn(product1, r.context['filter'])
self.assertNotIn(product2, r.context['filter'])
self.assertEqual(r.context['filter'].qs.count(), 1)
self.assertIn(product1, r.context['filter'].qs)
self.assertNotIn(product2, r.context['filter'].qs)


class ProductCreateViewTestCase(ViewTestCaseBase):
Expand Down
1 change: 0 additions & 1 deletion src/kawaz/core/activities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.views.generic.list import ListView
from activities.models import Activity


class ActivityListView(ListView):
paginate_by = 10
model = Activity
Expand Down
1 change: 1 addition & 0 deletions src/kawaz/core/personas/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class PersonaFilter(FilterSet):

class Meta:
model = Persona
exclude = ('avatar',)
2 changes: 1 addition & 1 deletion src/kawaz/core/personas/fixtures/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
pk: 15
fields:
label: Steam
url_pattern: http://steamcommunity.com/personas/{username}/
url_pattern: http://steamcommunity.com/id/{username}/
icon: personas/services/steam.png
- model: personas.service
pk: 16
Expand Down
21 changes: 13 additions & 8 deletions src/lib/django-activities/activities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pickle
from django.db import models
from django.db.models import Max
from django.core import serializers
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.utils.translation import ugettext as _
Expand All @@ -23,14 +25,17 @@ def latests(self):
"""
Return latest activities of each particular content_objects
"""
# find created_at list of latest activities of each particular
# content_objects
# it use 'pk' instead of 'created_at' to filter latest while
# - more than two activities which has same 'created_at' is possible
# - newer activity have grater pk
qs = super().get_queryset()
qs = qs.raw(
'SELECT * FROM '
'(SELECT * FROM activities_activity ORDER BY id DESC) AS A '
'GROUP BY content_type_id, object_id ORDER BY id DESC'
)
qs.count = lambda: len(list(qs))
return qs
qs = qs.values('content_type_id', 'object_id')
qs = qs.annotate(pk=Max('pk'))
pks = qs.values_list('pk', flat=True)
# return activities corresponding to the latests
return self.filter(pk__in=pks)

def get_for_model(self, model):
"""
Expand Down Expand Up @@ -65,7 +70,7 @@ class Activity(models.Model):
objects = ActivityManager()

class Meta:
ordering = ('-pk',)
ordering = ('-created_at',)
verbose_name = _('Activity')
verbose_name_plural = _('Activities')

Expand Down
4 changes: 3 additions & 1 deletion src/lib/django-activities/activities/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_all(self):

def test_latests(self):
latests = Activity.objects.latests()
self.assertEqual(latests.count(), 6)
# the status of latest activity should be 'deleted'
for latest in latests:
self.assertEqual(latest.status, 'deleted')

def test_get_for_model(self):
qs = Activity.objects.get_for_model(ModelA)
Expand Down
Loading

0 comments on commit 170d270

Please sign in to comment.