Skip to content

Commit

Permalink
Merge pull request #60 from praekelt/feature/upgrade-to-django-1.10-a…
Browse files Browse the repository at this point in the history
…nd-wagtail-1.10

Feature/upgrade to django 1.10 and wagtail 1.10
  • Loading branch information
codiebeulaine committed Nov 17, 2017
2 parents 078cc78 + 8a18bda commit b1300d6
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ cache:
directories:
- $HOME/.pip-cache/
install:
- pip install twine
- pip install --upgrade pip --cache-dir $HOME/.pip-cache/
- pip install coveralls coverage --cache-dir $HOME/.pip-cache/
- pip install flake8 --cache-dir $HOME/.pip-cache/
- pip install -r requirements-dev.txt --cache-dir $HOME/.pip-cache/
- pip install -e . --cache-dir $HOME/.pip-cache/
script:
Expand All @@ -24,6 +22,8 @@ script:
- py.test --cov=molo
after_success:
- coveralls
before_deploy:
- pip install twine
deploy:
provider: pypi
user: Praekelt
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ Django setup::

In your urls.py::

urlpatterns += patterns('',
urlpatterns += [,
url(r'^commenting/',include('molo.commenting.urls', namespace='molo.commenting', app_name='molo.commenting')),
url(r'', include('django_comments.urls')),
)
]

In your article_page.html::

Expand Down
14 changes: 6 additions & 8 deletions molo/commenting/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.admin.templatetags.admin_static import static
from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied
from django.conf.urls import patterns, url
from django.conf.urls import url
from django.contrib.admin.views.main import ChangeList
from django.shortcuts import get_object_or_404
from django.contrib.admin.utils import unquote
Expand Down Expand Up @@ -36,13 +36,12 @@ class MoloCommentAdmin(MPTTModelAdmin, CommentsAdmin):

def get_urls(self):
urls = super(MoloCommentAdmin, self).get_urls()
my_urls = patterns(
'',
my_urls = [
url(
r'(?P<parent>\d+)/reply/$',
self.admin_site.admin_view(AdminCommentReplyView.as_view()),
name="commenting_molocomment_reply")
)
]
return my_urls + urls

def is_reported(self, obj):
Expand Down Expand Up @@ -173,15 +172,14 @@ def get_urls(self):
"""
Add aditional moderate url.
"""
from django.conf.urls import patterns, url
from django.conf.urls import url
urls = super(AdminModeratorMixin, self).get_urls()
info = self.model._meta.app_label, self.model._meta.model_name
return patterns(
'',
return [
url(r'^(.+)/moderate/$',
self.admin_site.admin_view(self.moderate_view),
name='%s_%s_moderate' % info),
) + urls
] + urls

def moderate_view(self, request, object_id, extra_context=None):
"""
Expand Down
18 changes: 18 additions & 0 deletions molo/commenting/managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import force_text
from django_comments.managers import CommentManager


class MoloCommentManager(CommentManager):

def for_model(self, model):
"""
QuerySet for all comments for a particular model (either an instance or
a class).
"""
ct = ContentType.objects.get_for_model(model)
qs = self.get_queryset().filter(content_type=ct)
if isinstance(model, models.Model):
qs = qs.filter(object_pk=force_text(model._get_pk_val()))
return qs
3 changes: 3 additions & 0 deletions molo/commenting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from wagtail.wagtailcore.models import Site, Page
from notifications.signals import notify
from .rules import CommentDataRule # noqa
from .managers import MoloCommentManager


class MoloComment(MPTTModel, Comment):
Expand All @@ -24,6 +25,8 @@ class MoloComment(MPTTModel, Comment):
related_name='children')
wagtail_site = models.ForeignKey(Site, null=True, blank=True)

objects = MoloCommentManager()

class MPTTMeta:
# comments on one level will be ordered by date of creation
order_insertion_by = ['submit_date']
Expand Down
5 changes: 2 additions & 3 deletions molo/commenting/templatetags/molo_commenting_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ def __init__(self, obj, variable_name, limit=5, child_limit=0):

def render(self, context):
try:
obj = template.resolve_variable(self.obj, context)
obj = template.Variable(self.obj).resolve(context)
except template.VariableDoesNotExist:
return ''

qs = MoloComment.objects.for_model(obj.__class__).filter(
object_pk=obj.pk, parent__isnull=True)

if self.limit > 0:
qs = qs[:self.limit]

Expand Down Expand Up @@ -104,7 +103,7 @@ def __init__(self, obj, variable_name):

def render(self, context):
try:
form = template.resolve_variable(self.obj, context)
form = template.Variable(self.obj).resolve(context)
except template.VariableDoesNotExist:
return ''

Expand Down
37 changes: 29 additions & 8 deletions molo/commenting/tests/test_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from datetime import datetime

from django.contrib.auth.models import User
Expand Down Expand Up @@ -56,9 +58,15 @@ def test_template_tags_default(self):
output = template.render(Context({
'object': self.user,
}))
expected_output = [
'comment 9\s+',
'comment 8\s+',
'comment 7\s+',
'comment 6\s+',
'comment 5\s+',
]
self.assertNotEqual(re.search(''.join(expected_output), output), None)
self.assertFalse('comment 4' in output)
self.assertTrue('comment 5' in output)
self.assertTrue('comment 9' in output)

def test_template_tags_limits(self):
template = Template("""
Expand All @@ -74,10 +82,12 @@ def test_template_tags_limits(self):
output = template.render(Context({
'object': self.user,
}))
self.assertFalse('comment 4' in output)
self.assertFalse('comment 5' in output)
self.assertTrue('comment 8' in output)
self.assertTrue('comment 9' in output)
expected_output = [
'comment 9\s+',
'comment 8\s+',
]
self.assertNotEqual(re.search(''.join(expected_output), output), None)
self.assertFalse('comment 7' in output)

def test_template_tags_unlimited(self):
template = Template("""
Expand All @@ -93,8 +103,19 @@ def test_template_tags_unlimited(self):
output = template.render(Context({
'object': self.user,
}))
self.assertTrue('comment 1' in output)
self.assertTrue('comment 9' in output)
expected_output = [
'comment 9\s+',
'comment 8\s+',
'comment 7\s+',
'comment 6\s+',
'comment 5\s+',
'comment 4\s+',
'comment 3\s+',
'comment 2\s+',
'comment 1\s+',
'comment 0\s+',
]
self.assertNotEqual(re.search(''.join(expected_output), output), None)


class GetCommentsContentObjectTest(TestCase, MoloTestCaseMixin):
Expand Down
8 changes: 3 additions & 5 deletions molo/commenting/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from bs4 import BeautifulSoup
from datetime import datetime

from django.conf.urls import patterns, url, include
from django.conf.urls import url, include
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
Expand All @@ -16,14 +16,13 @@

from notifications.models import Notification

urlpatterns = patterns(
'',
urlpatterns = [
url(r'^commenting/',
include('molo.commenting.urls', namespace='molo.commenting')),
url(r'', include('django_comments.urls')),
url(r'', include('molo.core.urls')),
url(r'', include('wagtail.wagtailcore.urls')),
)
]


@override_settings(ROOT_URLCONF='molo.commenting.tests.test_views')
Expand Down Expand Up @@ -470,7 +469,6 @@ def test_restrict_article_comment_count(self):

response = self.client.get(self.article.url)
self.assertEqual(response.status_code, 200)

self.assertContains(response, "comment 2")
self.assertContains(response, "comment 1")
self.assertNotContains(response, "comment 0")
Expand Down
7 changes: 3 additions & 4 deletions molo/commenting/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.conf.urls import patterns, url
from django.conf.urls import url

from molo.commenting import views
from molo.commenting.views import CommentReplyView

urlpatterns = patterns(
'',
urlpatterns = [
url(r'molo/report/(\d+)/$', views.report, name='molo-comments-report'),
url(r'^comments/reported/(?P<comment_pk>\d+)/$',
views.report_response, name='report_response'),
Expand All @@ -20,4 +19,4 @@
name='more-comments'),
url(r'molo/replies/$',
views.reply_list, name='reply_list'),
)
]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
molo.core<6.0.0,>=5.0.0
molo.core<7.0.0,>=6.0.0
django-contrib-comments==1.7.1
django-mptt==0.8.5
django-import-export
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
exclude = ve,docs,molo/*/migrations/*
ignore = F403

[pytest]
[tool:pytest]
addopts = --doctest-modules --verbose --ds=testapp.settings --nomigrations --cov=molo --cov-report=term -s ./molo
looponfailroots = molo

0 comments on commit b1300d6

Please sign in to comment.