Merge pull request #28 from benjaminabel/pep8-check

Pep8 check
This commit is contained in:
Esteban Castro Borsani 2014-11-17 21:19:03 -03:00
commit 39e6dc2c19
171 changed files with 757 additions and 492 deletions

24
.editorconfig Normal file
View File

@ -0,0 +1,24 @@
# This file is for unifying the coding style for different editors and IDEs.
# More information at http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# 4 space indentation
[*.py]
indent_style = space
indent_size = 4
# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

View File

@ -7,8 +7,10 @@ python:
install:
- pip install -r requirements.txt --use-mirrors
- pip install coveralls
- pip install coveralls pep8 flake8
script:
- pep8 --max-line-length=120 --exclude='migrations,tests' .
- flake8 --select=F401 ./spirit
- coverage run --source=. run_tests.py
after_success:
- coveralls

View File

@ -8,7 +8,7 @@ To see it in action, please visit [The Spirit Project](http://spirit-project.com
Spirit requires the following software to be installed:
* Python 2.7 3.3 3.4
* Python 2.7, 3.3 or 3.4 (recommended)
* Django 1.7
* PostgreSQL or MySQL or Oracle Database
@ -72,7 +72,7 @@ Run:
pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic
python manage.py rebuild_index
python manage.py rebuild_index --noinput
## Contributing

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
# THIS IS FOR DEVELOPMENT ENVIRONMENT, MOSTLY TO SPEED UP TESTS
# DO NOT USE IT IN PRODUCTION
from __future__ import unicode_literals
import os
import sys
@ -53,4 +53,4 @@ else:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
)

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# MINIMAL CONFIGURATION FOR PRODUCTION ENV
from __future__ import unicode_literals
DEBUG = False
TEMPLATE_DEBUG = False
@ -39,4 +40,4 @@ LANGUAGES = (
)
# Default language
LANGUAGE_CODE = 'en'
LANGUAGE_CODE = 'en'

View File

@ -8,9 +8,12 @@ https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
from __future__ import absolute_import
from __future__ import unicode_literals
import os
# You may override spirit settings below...
from spirit.settings import *
@ -18,7 +21,6 @@ from spirit.settings import *
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
@ -40,28 +42,28 @@ ALLOWED_HOSTS = []
# Extend the Spirit installed apps (notice the plus sign)
# Check out the spirit.settings.py so you do not end up with duplicate apps.
INSTALLED_APPS += (
#'my_app1',
#'my_app2',
# 'my_app1',
# 'my_app2',
'debug_toolbar',
)
# same here, check out the spirit.settings.py
MIDDLEWARE_CLASSES += (
#'my_middleware1',
#'my_middleware2',
# 'my_middleware1',
# 'my_middleware2',
)
# same here
TEMPLATE_CONTEXT_PROCESSORS += (
#'my_template_proc1',
#'my_template_proc2',
# 'my_template_proc1',
# 'my_template_proc2',
)
# same here (we update the Spirit caches)
CACHES.update({
#'default': {
# 'BACKEND': 'my.backend.path',
#},
# 'default': {
# 'BACKEND': 'my.backend.path',
# },
})
@ -135,6 +137,6 @@ LOGGING = {
try:
# devs must create this file to override settings
# local_settings_sample.py is provided
from local_settings import *
from .local_settings import *
except ImportError:
pass
pass

View File

@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from .settings import *
from .local_settings_sample_dev import *

View File

@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
# Uncomment the next two lines to enable the django admin:
from django.contrib import admin
admin.autodiscover()
# Override admin login for security purposes
from django.contrib.auth.decorators import login_required
@ -15,18 +13,18 @@ admin.site.login = login_required(admin.site.login)
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'example.views.home', name='home'),
# url(r'^example/', include('example.foo.urls')),
# Examples:
# url(r'^$', 'example.views.home', name='home'),
# url(r'^example/', include('example.foo.urls')),
url(r'^', include('spirit.urls', namespace="spirit", app_name="spirit")),
url(r'^', include('spirit.urls', namespace="spirit", app_name="spirit")),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -14,8 +14,6 @@ middleware here, or combine a Django application with an application of another
framework.
"""
from __future__ import absolute_import
from __future__ import unicode_literals
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks

View File

@ -1,9 +1,9 @@
Django>=1.7,<1.8
django-haystack>=2.1,<2.2
django-haystack>=2.3,<2.4
whoosh>=2.5,<2.6
mistune>=0.3.1,<0.4
Pillow>=2.4,<2.5
git+https://git@github.com/nitely/django-djconfig.git
django-infinite-scroll-pagination>=0.1.2,<0.2
Pillow>=2.6,<2.7
django-infinite-scroll-pagination>=0.1.3,<0.2
django-djconfig>=0.1.7,<0.2
django-debug-toolbar
pytz
pytz

2
run_tests.py Normal file → Executable file
View File

@ -18,4 +18,4 @@ def run_tests():
if __name__ == "__main__":
django.setup()
run_tests()
run_tests()

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
__version__ = '0.1.3'
default_app_config = 'spirit.apps.SpiritConfig'

View File

@ -1,4 +1,6 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
@ -6,4 +8,4 @@ from django.apps import AppConfig
class SpiritConfig(AppConfig):
name = 'spirit'
verbose_name = "Spirit"
verbose_name = "Spirit"

View File

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
__author__ = 'Admin'

View File

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.backends import ModelBackend
from __future__ import unicode_literals
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import get_user_model
@ -16,4 +18,4 @@ class EmailAuthBackend(ModelBackend):
if user.check_password(password):
return user
except User.DoesNotExist:
pass
pass

View File

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
__author__ = 'Admin'

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from djconfig.forms import ConfigForm
@ -27,7 +28,7 @@ class CategoryForm(forms.ModelForm):
class Meta:
model = Category
fields = ("parent", "title", "description", "is_closed", "is_removed")
def __init__(self, *args, **kwargs):
super(CategoryForm, self).__init__(*args, **kwargs)
queryset = Category.objects.for_parent()
@ -71,4 +72,4 @@ class BasicConfigForm(ConfigForm):
site_description = forms.CharField(initial="", label=_("site description"), max_length=75, required=False)
template_footer = forms.CharField(initial="", label=_("footer snippet"), required=False,
widget=forms.Textarea(attrs={'rows': 2, }),
help_text=_("This gets rendered just before the footer in your template."))
help_text=_("This gets rendered just before the footer in your template."))

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import hashlib

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -22,4 +23,4 @@ class BookmarkForm(forms.ModelForm):
# Bookmark is created/updated on topic view.
CommentBookmark.objects.filter(user=self.user, topic=self.topic)\
.update(comment_number=comment_number)
.update(comment_number=comment_number)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -44,4 +45,4 @@ class FlagForm(forms.ModelForm):
CommentFlag.objects.filter(comment=self.comment)\
.update(date=timezone.now())
return super(FlagForm, self).save(commit)
return super(FlagForm, self).save(commit)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -35,4 +36,4 @@ class LikeForm(forms.ModelForm):
self.instance.user = self.user
self.instance.comment = self.comment
return super(LikeForm, self).save(commit)
return super(LikeForm, self).save(commit)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -55,4 +56,4 @@ class AdvancedSearchForm(BaseSearchForm):
if categories:
topics = topics.filter(category_id__in=[c.pk for c in categories])
return topics.filter(is_removed=False, is_category_removed=False, is_subcategory_removed=False)
return topics.filter(is_removed=False, is_category_removed=False, is_subcategory_removed=False)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -43,4 +44,4 @@ class TopicForm(forms.ModelForm):
if not self.instance.pk:
self.instance.user = self.user
return super(TopicForm, self).save(commit)
return super(TopicForm, self).save(commit)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -35,4 +36,4 @@ class FavoriteForm(forms.ModelForm):
self.instance.user = self.user
self.instance.topic = self.topic
return super(FavoriteForm, self).save(commit)
return super(FavoriteForm, self).save(commit)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -40,4 +41,4 @@ class NotificationCreationForm(NotificationForm):
self.instance.user = self.user
self.instance.topic = self.topic
return super(NotificationCreationForm, self).save(commit)
return super(NotificationCreationForm, self).save(commit)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -68,6 +69,7 @@ class TopicPollVoteManyForm(forms.Form):
This special form allows single vote and multi vote as well.
Its beauty is that it doesn't care if the choice_limit is increased or decreased later.
"""
def __init__(self, user=None, poll=None, *args, **kwargs):
super(TopicPollVoteManyForm, self).__init__(*args, **kwargs)
self.user = user
@ -125,4 +127,4 @@ class TopicPollVoteManyForm(forms.Form):
.delete()
return TopicPollVote.objects.bulk_create([TopicPollVote(user=self.user, choice=choice)
for choice in choices])
for choice in choices])

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -126,4 +127,4 @@ class TopicPrivateJoinForm(forms.ModelForm):
self.instance.topic = self.topic
self.instance.user = self.user
return super(TopicPrivateJoinForm, self).save(commit)
return super(TopicPrivateJoinForm, self).save(commit)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
@ -113,4 +114,4 @@ class ResendActivationForm(forms.Form):
return email
def get_user(self):
return self.user
return self.user

View File

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
__author__ = 'Admin'

View File

@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models import Manager
from django.db.models import Q
from django.shortcuts import get_object_or_404
@ -26,4 +29,4 @@ class CategoryManager(Manager):
def get_public_or_404(self, pk):
return get_object_or_404(self.for_public(),
pk=pk)
pk=pk)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models import Manager
@ -40,4 +41,4 @@ class CommentManager(Manager):
if user.is_moderator:
return get_object_or_404(self, pk=pk)
else:
return get_object_or_404(self.for_access(user), user=user, pk=pk)
return get_object_or_404(self.for_access(user), user=user, pk=pk)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models import Manager
@ -8,4 +9,4 @@ class CommentLikeManager(Manager):
def for_user(self, user):
return self.filter(user=user)\
.select_related('user', 'comment__user')
.select_related('user', 'comment__user')

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models import Manager
@ -57,4 +58,4 @@ class TopicManager(Manager):
def for_access_open(self, user):
return self.for_access(user)\
.filter(is_closed=False)
.filter(is_closed=False)

View File

@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models import Manager
from django.db.models import Q
@ -19,4 +22,4 @@ class TopicNotificationManager(Manager):
def read(self, user):
# returns updated rows count (int)
return self.filter(user=user)\
.update(is_read=True)
.update(is_read=True)

View File

@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models import Manager
from django.shortcuts import get_object_or_404
from django.db.models import Q
@ -17,4 +20,4 @@ class TopicPrivateManager(Manager):
return get_object_or_404(self,
topic_id=topic_id,
user=user,
topic__user=user)
topic__user=user)

View File

@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.models import Manager
@ -10,4 +13,4 @@ class TopicUnreadManager(Manager):
def read(self, user, topic):
# returns updated rows count (int)
return self.filter(user=user, topic=topic)\
.update(is_read=True)
.update(is_read=True)

View File

@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import pytz
from django.utils import timezone
from django.contrib.auth import get_user_model
@ -69,7 +68,7 @@ class ActiveUserMiddleware(object):
return
if not request.user.is_active:
logout(request)
logout(request)
class PrivateForumMiddleware(object):
@ -101,4 +100,4 @@ class PrivateForumMiddleware(object):
return
return redirect_to_login(next=request.get_full_path(),
login_url=settings.LOGIN_URL)
login_url=settings.LOGIN_URL)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
from django.conf import settings

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from .category import Category
from .comment import Comment
from .comment_history import CommentHistory
@ -12,3 +13,9 @@ from .topic_notification import TopicNotification
from .topic_poll import TopicPoll, TopicPollChoice
from .topic_private import TopicPrivate
from .user import User
__all__ = [
'Category', 'Comment', 'CommentHistory', 'CommentBookmark', 'Flag',
'CommentLike', 'Topic', 'TopicUnread', 'TopicFavorite',
'TopicNotification', 'TopicPoll', 'TopicPollChoice', 'TopicPrivate', 'User'
]

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
@ -23,7 +24,7 @@ class Category(models.Model):
is_removed = models.BooleanField(_("removed"), default=False)
is_private = models.BooleanField(_("private"), default=False)
#topic_count = models.PositiveIntegerField(_("topic count"), default=0)
# topic_count = models.PositiveIntegerField(_("topic count"), default=0)
objects = CategoryManager()
@ -52,7 +53,7 @@ class Category(models.Model):
return self.title
#def topic_posted_handler(sender, topic, **kwargs):
# def topic_posted_handler(sender, topic, **kwargs):
# if topic.category.is_subcategory:
# category = Category.objects.filter(pk__in=[topic.category.pk, topic.category.parent.pk])
# else:
@ -61,4 +62,4 @@ class Category(models.Model):
# category.update(topic_count=F('topic_count') + 1)
#topic_posted.connect(topic_posted_handler, dispatch_uid=__name__)
# topic_posted.connect(topic_posted_handler, dispatch_uid=__name__)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
@ -6,7 +7,6 @@ from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.conf import settings
from django.db.models import F
from django.utils.six.moves import xrange
from django.utils.encoding import python_2_unicode_compatible
from ..signals.comment_like import comment_like_post_create, comment_like_post_delete
@ -18,7 +18,7 @@ from ..signals.comment import comment_post_update
COMMENT_MAX_LEN = 3000 # changing this needs migration
COMMENT, MOVED, CLOSED, UNCLOSED, PINNED, UNPINNED = xrange(6)
COMMENT, MOVED, CLOSED, UNCLOSED, PINNED, UNPINNED = range(6)
ACTION = (
(COMMENT, _("comment")),
@ -29,6 +29,7 @@ ACTION = (
(UNPINNED, _("topic unpinned")),
)
@python_2_unicode_compatible
class Comment(models.Model):

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.conf import settings
from django.db import IntegrityError
from django.utils.encoding import python_2_unicode_compatible

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
@ -28,8 +28,8 @@ class CommentFlag(models.Model):
verbose_name = _("comment flag")
verbose_name_plural = _("comments flags")
#def get_absolute_url(self):
#pass
# def get_absolute_url(self):
# pass
def __str__(self):
return "%s flagged" % self.comment

View File

@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.conf import settings
from django.db.models import signals
from django.utils.encoding import python_2_unicode_compatible
from spirit.signals.comment import comment_pre_update, comment_post_update

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models

View File

@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils import timezone
from django.db import IntegrityError
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
from spirit.signals.comment import comment_posted
@ -17,7 +16,7 @@ from spirit.signals.topic import topic_viewed
from spirit.managers.topic_notifications import TopicNotificationManager
UNDEFINED, MENTION, COMMENT = six.moves.xrange(3)
UNDEFINED, MENTION, COMMENT = range(3)
ACTION_CHOICES = (
(UNDEFINED, _("Undefined")),
@ -85,7 +84,7 @@ def mention_comment_posted_handler(sender, comment, mentions, **kwargs):
if not mentions:
return
for username, user in six.iteritems(mentions):
for username, user in mentions.items():
try:
TopicNotification.objects.create(user=user, topic=comment.topic,
comment=comment, action=MENTION)

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from django.db.models import F

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.utils.encoding import python_2_unicode_compatible
from spirit.managers.topic_private import TopicPrivateManager

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils import timezone
from django.db import IntegrityError

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
@ -24,7 +25,7 @@ class AbstractForumUser(models.Model):
timezone = models.CharField(_("time zone"), max_length=32, choices=TIMEZONE_CHOICES, default='UTC')
is_administrator = models.BooleanField(_('administrator status'), default=False)
is_moderator = models.BooleanField(_('moderator status'), default=False)
#is_verified = models.BooleanField(_('verified'), default=False)
# is_verified = models.BooleanField(_('verified'), default=False)
topic_count = models.PositiveIntegerField(_("topic count"), default=0)
comment_count = models.PositiveIntegerField(_("comment count"), default=0)
@ -51,7 +52,7 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin, AbstractForumUser):
validators=[
validators.RegexValidator(re.compile('^[\w.@+-]+$'), _('Enter a valid username.'),
'invalid')
])
])
first_name = models.CharField(_("first name"), max_length=30, blank=True)
last_name = models.CharField(_("last name"), max_length=30, blank=True)
email = models.EmailField(_("email"), max_length=254, unique=True)

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from django.conf import settings
@ -24,4 +24,4 @@ class TopicIndex(indexes.SearchIndex, indexes.Indexable):
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
topics = super(TopicIndex, self).index_queryset(using=using)
return topics.exclude(category_id=settings.ST_TOPIC_PRIVATE_CATEGORY_PK)
return topics.exclude(category_id=settings.ST_TOPIC_PRIVATE_CATEGORY_PK)

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
# DO NOT EDIT THIS FILE
# YOU MAY EXTEND/OVERWRITE THE DEFAULT VALUES IN YOUR settings.py FILE
from __future__ import unicode_literals
import os
ST_COMMENTS_PER_PAGE = 20
@ -73,7 +72,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
#'spirit.middleware.XForwardedForMiddleware',
# 'spirit.middleware.XForwardedForMiddleware',
'spirit.middleware.TimezoneMiddleware',
'spirit.middleware.LastIPMiddleware',
'spirit.middleware.LastSeenMiddleware',
@ -137,4 +136,4 @@ HAYSTACK_CONNECTIONS = {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}
}

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.dispatch import Signal
@ -7,4 +8,4 @@ from django.dispatch import Signal
comment_posted = Signal(providing_args=['comment', 'mentions'])
comment_pre_update = Signal(providing_args=['comment', ])
comment_post_update = Signal(providing_args=['comment', ])
comment_moved = Signal(providing_args=['comments', 'topic_from'])
comment_moved = Signal(providing_args=['comments', 'topic_from'])

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.dispatch import Signal
comment_like_post_create = Signal(providing_args=['comment', ])
comment_like_post_delete = Signal(providing_args=['comment', ])
comment_like_post_delete = Signal(providing_args=['comment', ])

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.dispatch import Signal
topic_viewed = Signal(providing_args=['request', 'topic'])
topic_post_moderate = Signal(providing_args=['user', 'topic', 'action'])
topic_post_moderate = Signal(providing_args=['user', 'topic', 'action'])

View File

@ -1,7 +1,9 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.dispatch import Signal
topic_poll_pre_vote = Signal(providing_args=['poll, user'])
topic_poll_post_vote = Signal(providing_args=['poll, user'])
topic_poll_post_vote = Signal(providing_args=['poll, user'])

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.dispatch import Signal
topic_private_post_create = Signal(providing_args=['topics_private', 'comment'])
topic_private_access_pre_create = Signal(providing_args=['topic', 'user'])
topic_private_access_pre_create = Signal(providing_args=['topic', 'user'])

37
spirit/tasks.py Normal file
View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
try:
# TODO: remove this try block.
from celery.decorators import task
except ImportError:
task = None
if not hasattr(settings, 'BROKER_URL'):
def task(f):
f.delay = f
return f
@task
def send_notification():
pass
@task
def backup_database():
pass
@task
def search_index_update():
pass
@task
def clean_sessions():
pass

View File

@ -1,6 +1,6 @@
{# django.contrib.messages #}
{% if messages_grouped %}
{% for level, messages in messages_grouped.iteritems %}
{% for level, messages in messages_grouped.items %}
<ul class="messages-{{ level }}">
{% for message in messages %}
<li>{{ message }}</li>

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from .tags import comment
from .tags import comment_bookmark
from .tags import comment_like
@ -13,5 +14,10 @@ from .tags.utils import messages
from .tags.utils import paginator
from .tags.utils import social_share
from .tags.utils import time
from .tags import register
from .tags import register
__all__ = [
'comment', 'comment_bookmark', 'comment_like', 'topic_poll', 'search',
'topic_favorite', 'topic_notification', 'topic_private', 'filters',
'gravatar', 'messages', 'paginator', 'social_share', 'time', 'register'
]

View File

@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import template
register = template.Library()
register = template.Library()

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
@ -33,4 +34,4 @@ def get_comment_action_text(action):
elif action == UNPINNED:
return _("This topic has been unpinned")
else:
return _("Unknown topic moderation action")
return _("Unknown topic moderation action")

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from . import register
@ -14,4 +15,4 @@ def populate_bookmarks(topics, user, to_attr='bookmark'):
for t in topics:
setattr(t, to_attr, bookmarks_dict.get(t.pk))
return ""
return ""

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from . import register
@ -21,4 +22,4 @@ def populate_likes(comments, user, to_attr='like'):
for c in comments:
setattr(c, to_attr, likes_dict.get(c.pk))
return ""
return ""

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from . import register
@ -15,4 +16,4 @@ def render_search_form():
def get_topics_from_search_result(results):
# Since Im only indexing Topics this is ok.
topics = [r.object for r in results]
return topics
return topics

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from . import register
@ -14,4 +15,4 @@ def render_favorite_form(topic, user, next=None):
favorite = None
form = FavoriteForm()
return {'form': form, 'topic_id': topic.pk, 'favorite': favorite, 'next': next}
return {'form': form, 'topic_id': topic.pk, 'favorite': favorite, 'next': next}

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from . import register
@ -27,4 +28,4 @@ def render_notification_form(user, topic, next=None):
initial['is_active'] = not notification.is_active
form = NotificationForm(initial=initial)
return {'form': form, 'topic_id': topic.pk, 'notification': notification, 'next': next}
return {'form': form, 'topic_id': topic.pk, 'notification': notification, 'next': next}

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
@ -19,4 +20,4 @@ def render_poll_form(topic, user, next=None):
if user.is_authenticated():
form.load_initial()
return {'form': form, 'poll': poll, 'next': next}
return {'form': form, 'poll': poll, 'next': next}

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from . import register
@ -8,4 +9,4 @@ from spirit.forms.topic_private import TopicPrivateInviteForm
@register.inclusion_tag('spirit/topic_private/_private_invite_form.html')
def render_invite_form(topic, next=None):
form = TopicPrivateInviteForm()
return {'form': form, 'topic': topic, 'next': next}
return {'form': form, 'topic': topic, 'next': next}

View File

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
__author__ = 'Admin'

View File

@ -1,8 +1,10 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from .. import register
@register.filter
def has_errors(formset):
"""Checks if a FormSet has errors"""
@ -11,4 +13,4 @@ def has_errors(formset):
if form.errors:
return True
return False
return False

View File

@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals
import hashlib
from django.utils.http import urlencode, urlquote
from django.utils.encoding import force_bytes
from .. import register
@ -13,6 +12,8 @@ from .. import register
@register.simple_tag()
def get_gravatar_url(user, size, rating='g', default='identicon'):
url = "http://www.gravatar.com/avatar/"
hash = hashlib.md5(force_bytes(user.email.strip().lower().encode('utf_8'))).hexdigest()
data = urlencode({'d': urlquote(default), 's': str(size), 'r': rating})
hash = hashlib.md5(user.email.strip().lower().encode('utf-8')).hexdigest()
data = urlencode([('d', urlquote(default)),
('s', str(size)),
('r', rating)])
return "".join((url, hash, '?', data))

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals
from collections import OrderedDict
from django.contrib.messages import constants
@ -26,4 +26,4 @@ def render_messages(messages):
messages_group.append(m)
grouped[TAGS[m.level]] = messages_group
return {'messages_grouped': grouped, }
return {'messages_grouped': grouped, }

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.http import Http404
@ -63,4 +64,4 @@ def paginator_autopaginate(context, object_list, per_page=15, page_var='page', p
@register.inclusion_tag("spirit/paginator/_paginator.html", takes_context=True)
def render_paginator(context, page, page_var='page', hashtag=''):
return _render_paginator(context, page, page_var, hashtag)
return _render_paginator(context, page, page_var, hashtag)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.utils.http import urlencode
@ -60,4 +61,4 @@ def get_email_share_url(context, url, title):
@register.simple_tag(takes_context=True)
def get_share_url(context, url):
request = context['request']
return request.build_absolute_uri(url)
return request.build_absolute_uri(url)

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals
from datetime import datetime
from django.template import defaultfilters
@ -41,4 +41,4 @@ def shortnaturaltime(value):
return _('%(count)sm') % {'count': count}
count //= 60
return _('%(count)sh') % {'count': count}
return _('%(count)sh') % {'count': count}

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations

View File

@ -1 +0,0 @@
__author__ = 'Admin'

View File

@ -1,4 +1,13 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from .auto_slug import AutoSlugPopulateFromModel, AutoSlugModel, AutoSlugDefaultModel, \
AutoSlugBadPopulateFromModel
from __future__ import unicode_literals
from .auto_slug import (
AutoSlugPopulateFromModel, AutoSlugModel,
AutoSlugDefaultModel, AutoSlugBadPopulateFromModel
)
__all__ = [
'AutoSlugPopulateFromModel', 'AutoSlugModel',
'AutoSlugDefaultModel', 'AutoSlugBadPopulateFromModel'
]

View File

@ -1,4 +1,4 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from django.db import models
@ -23,4 +23,4 @@ class AutoSlugPopulateFromModel(models.Model):
class AutoSlugBadPopulateFromModel(models.Model):
slug = AutoSlugField(populate_from='bad', max_length=50)
slug = AutoSlugField(populate_from='bad', max_length=50)

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase, RequestFactory
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.http import Http404
from django.core.exceptions import PermissionDenied
from django.contrib.auth.models import User as UserModel
from django.contrib.auth import get_user_model
@ -332,4 +332,4 @@ class AdminFormTest(TestCase):
form_data = {"is_closed": True, }
form = CommentFlagForm(user=self.user, data=form_data, instance=comment_flag)
self.assertEqual(form.is_valid(), True)
self.assertEqual(repr(form.save().moderator), repr(self.user))
self.assertEqual(repr(form.save().moderator), repr(self.user))

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
@ -28,8 +29,7 @@ class CategoryViewTest(TestCase):
"""
response = self.client.get(reverse('spirit:category-list'))
self.assertQuerysetEqual(response.context['categories'],
['<Category: Uncategorized>', repr(self.category_1), repr(self.category_2)],
ordered=False)
['<Category: Uncategorized>', repr(self.category_1), repr(self.category_2)])
def test_category_detail_view(self):
"""

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
@ -8,7 +9,6 @@ from django.test import TestCase, RequestFactory
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.template import Template, Context
from django.utils.translation import ugettext as _
from django.core.exceptions import PermissionDenied
from django.contrib.auth.models import User as UserModel
from django.contrib.auth import get_user_model
@ -360,7 +360,7 @@ class CommentViewTest(TestCase):
"""
utils.login(self)
img = BytesIO(b'GIF87a\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00ccc,\x00'
b'\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;')
b'\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;')
files = {'image': SimpleUploadedFile('image.gif', img.read(), content_type='image/gif'), }
response = self.client.post(reverse('spirit:comment-image-upload-ajax'),
HTTP_X_REQUESTED_WITH='XMLHttpRequest',

View File

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase, RequestFactory
from django.core.urlresolvers import reverse
from django.template import Template, Context, TemplateSyntaxError
from django.template import Template, Context
from django.core.cache import cache
from django.conf import settings
from django.utils.six.moves import xrange
from . import utils
@ -43,7 +43,7 @@ class CommentBookmarkSignalTest(TestCase):
self.category = utils.create_category()
self.topic = utils.create_topic(category=self.category, user=self.user)
for _ in xrange(settings.ST_COMMENTS_PER_PAGE * 4): # 4 pages
for _ in range(settings.ST_COMMENTS_PER_PAGE * 4): # 4 pages
utils.create_comment(user=self.user, topic=self.topic)
def test_comment_bookmark_topic_page_viewed_handler(self):

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.template import Template, Context, TemplateSyntaxError
from django.core.cache import cache
from . import utils
@ -54,4 +53,4 @@ class FlagFormTest(TestCase):
form.user = self.user
self.assertEqual(form.is_valid(), True)
form.save()
self.assertEqual(len(CommentFlag.objects.all()), 1)
self.assertEqual(len(CommentFlag.objects.all()), 1)

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.template import Template, Context, TemplateSyntaxError
from django.core.cache import cache
from . import utils
@ -111,4 +110,4 @@ class CommentHistorySignalTest(TestCase):
comment_post_update.send(sender=comment.__class__, comment=comment)
self.assertEqual(CommentHistory.objects.get(comment_fk=comment.pk).comment_html, comment.comment_html)
comment_post_update.send(sender=comment.__class__, comment=comment)
self.assertEqual(len(CommentHistory.objects.filter(comment_fk=comment.pk)), 2)
self.assertEqual(len(CommentHistory.objects.filter(comment_fk=comment.pk)), 2)

View File

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.template import Template, Context, TemplateSyntaxError
from django.template import Template, Context
from django.core.cache import cache
from . import utils
@ -151,4 +151,4 @@ class LikeTemplateTagsTest(TestCase):
"{% populate_likes comments=comments user=user %}"
"{{ comments.0.like }}"
).render(Context({'comments': [self.comment, ], 'user': self.user}))
self.assertEqual(out, str(like))
self.assertEqual(out, str(like))

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.template import Template, Context, TemplateSyntaxError
from django.utils import six
from django.template import Template, Context
from . import utils
@ -20,5 +20,4 @@ class GravatarTemplateTagTests(TestCase):
"{% load spirit_tags %}"
"{% get_gravatar_url user 21 %}"
).render(Context({'user': self.user, }))
# Argument order may change between py2 and py3
six.assertRegex(self, out, 'http://www.gravatar.com/avatar/441cf33d0e5b36a95bae87e400783ca4\?[srd]=\w+&[srd]=\w+&[srd]=\w+')
self.assertEqual(out, "http://www.gravatar.com/avatar/441cf33d0e5b36a95bae87e400783ca4?d=identicon&s=21&r=g")

View File

@ -1,21 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.test.utils import override_settings
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.template import Template, Context, TemplateSyntaxError
from django.template import Template, Context
from django.conf import settings
from django.core.management import call_command
import haystack
from haystack.query import SearchQuerySet
from . import utils
from spirit.models.topic import Topic
from spirit.forms.search import BasicSearchForm, BaseSearchForm, AdvancedSearchForm
from spirit.forms.search import BasicSearchForm, AdvancedSearchForm
from spirit.templatetags.tags.search import render_search_form
from spirit.search_indexes import TopicIndex
@ -60,8 +59,8 @@ class SearchViewTest(TestCase):
def setUp(self):
# TODO: simple backend wont work on django +1.6 coz of a bug on haystack 2.1
#self.connections = haystack.connections
#haystack.connections = haystack.loading.ConnectionHandler(HAYSTACK_TEST)
# self.connections = haystack.connections
# haystack.connections = haystack.loading.ConnectionHandler(HAYSTACK_TEST)
cache.clear()
self.user = utils.create_user()
@ -71,8 +70,8 @@ class SearchViewTest(TestCase):
call_command("rebuild_index", interactive=False)
#def tearDown(self):
#haystack.connections = self.connections
# def tearDown(self):
# haystack.connections = self.connections
def test_advanced_search_detail(self):
"""
@ -150,4 +149,4 @@ class SearchTemplateTagTests(TestCase):
"{% render_search_form %}"
).render(Context())
context = render_search_form()
self.assertIsInstance(context['form'], BasicSearchForm)
self.assertIsInstance(context['form'], BasicSearchForm)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
@ -6,7 +7,6 @@ import datetime
from django.test import TestCase, RequestFactory
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.utils import timezone
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
@ -502,4 +502,4 @@ class TopicSignalTest(TestCase):
comment2 = utils.create_comment(topic=self.topic)
Topic.objects.filter(pk=self.topic.pk).update(comment_count=10)
comment_moved.send(sender=comment.__class__, comments=[comment, comment2], topic_from=self.topic)
self.assertEqual(Topic.objects.get(pk=self.topic.pk).comment_count, 8)
self.assertEqual(Topic.objects.get(pk=self.topic.pk).comment_count, 8)

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.template import Template, Context, TemplateSyntaxError
from django.core.cache import cache
from . import utils
@ -107,4 +106,4 @@ class FavoriteFormTest(TestCase):
form = FavoriteForm(data=form_data)
form.topic = self.topic
form.user = self.user
self.assertEqual(form.is_valid(), False)
self.assertEqual(form.is_valid(), False)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
@ -8,13 +9,10 @@ from django.test import TestCase, TransactionTestCase, RequestFactory
from django.test.utils import override_settings
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.conf import settings
from django.template import Template, Context
from django.utils import timezone
from django.utils import six
from django.utils.six.moves import xrange
from . import utils
from . import utils
from spirit.models.topic_private import TopicPrivate
from spirit.models.topic_notification import TopicNotification, comment_posted, \
@ -149,16 +147,12 @@ class TopicNotificationViewTest(TestCase):
self.assertEqual(len(res['n']), 1)
expected = {
'user': self.topic_notification.comment.user.username,
'action': self.topic_notification.text_action,
'action': self.topic_notification.action,
'title': self.topic_notification.comment.topic.title,
'url': self.topic_notification.get_absolute_url(),
'is_read': self.topic_notification.is_read
}
# django.utils.six will provide a method in django 1.8
if six.PY3:
self.assertCountEqual(res['n'][0], expected)
else:
self.assertItemsEqual(res['n'][0], expected)
self.assertDictEqual(res['n'][0], expected)
self.assertFalse(TopicNotification.objects.get(pk=self.topic_notification.pk).is_read)
def test_topic_notification_ajax_limit(self):
@ -185,7 +179,7 @@ class TopicNotificationViewTest(TestCase):
"""
user = utils.create_user()
for _ in xrange(10):
for _ in range(10):
topic = utils.create_topic(self.category, user=user)
comment = utils.create_comment(topic=topic, user=user)
TopicNotification.objects.create(user=self.user, topic=topic, comment=comment,

View File

@ -1,7 +1,8 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase, RequestFactory
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.contrib.auth import get_user_model

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
@ -353,7 +354,7 @@ class TopicPrivateFormTest(TestCase):
self.assertCountEqual(map(repr, privates_saved), map(repr, privates))
else:
self.assertItemsEqual(map(repr, privates_saved), map(repr, privates))
def test_private_create(self):
"""
create single private topic access

View File

@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.cache import cache
from django.test import TestCase, TransactionTestCase, RequestFactory
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.utils import timezone
from . import utils

View File

@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.template import Template, Context, TemplateSyntaxError
from django.core.cache import cache
from django.contrib.auth import get_user_model
from django.core import mail
from django.utils.translation import ugettext as _
from django.utils import timezone
from django.utils.six.moves import xrange
from . import utils
@ -289,7 +288,7 @@ class UserViewTest(TestCase):
utils.login(self)
response = self.client.get(reverse("spirit:profile-likes", kwargs={'pk': self.user2.pk,
'slug': self.user2.slug}))
'slug': self.user2.slug}))
self.assertQuerysetEqual(response.context['comments'], [])
def test_profile_likes_invalid_slug(self):
@ -326,7 +325,7 @@ class UserViewTest(TestCase):
"""
form_data = {'username': self.user.email, 'password': "badpassword"}
url = reverse('spirit:user-login') + "?next=/path/"
for _ in xrange(6):
for _ in range(6):
response = self.client.post(url, form_data)
self.assertRedirects(response, url, status_code=302)
@ -335,7 +334,7 @@ class UserViewTest(TestCase):
test rate limit 5/5m
"""
form_data = {'email': "bademail@bad.com", }
for _ in xrange(6):
for _ in range(6):
response = self.client.post(reverse('spirit:password-reset'),
form_data)
expected_url = reverse("spirit:password-reset")

View File

@ -1,4 +1,5 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
@ -8,16 +9,14 @@ import os
from django.core.cache import cache
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.template import Template, Context, TemplateSyntaxError
from django import forms
from django.template import Template, Context
from django.utils import translation
from django.utils import timezone
from django.contrib.auth.models import AnonymousUser, User
from django.http import HttpResponseRedirect
from django.http import Http404, HttpResponse
from django.http import HttpResponse
from django.conf import settings
from django.core import mail
from django.template.loader import render_to_string
from django.core.exceptions import PermissionDenied
from django.contrib import messages
from django.utils.translation import ugettext as _
@ -159,6 +158,7 @@ class UtilsTemplateTagTests(TestCase):
"""
Test messages grouped by level
"""
# TODO: test template rendering
class MockMessage:
def __init__(self, level, message):
self.level = level
@ -289,7 +289,7 @@ class UtilsMarkdownTests(TestCase):
cache.clear()
self.user = test_utils.create_user(username="nitely", slug="nitely")
self.user2 = test_utils.create_user(username="esteban")
self.user3 = test_utils.create_user(username=u"áéíóú")
self.user3 = test_utils.create_user(username="áéíóú")
def test_markdown_mentions(self):
"""
@ -325,7 +325,7 @@ class UtilsMarkdownTests(TestCase):
comment_md = md.render(comment)
# mentions get dianmically added on MentionifyExtension
self.assertDictEqual(md.get_mentions(), {'nitely': self.user,
'esteban': self.user2})
'esteban': self.user2})
def test_markdown_emoji(self):
"""
@ -345,7 +345,7 @@ class UtilsMarkdownTests(TestCase):
"""
comment = "text\nnew line"
quote = quotify(comment, self.user)
self.assertListEqual(quote.splitlines(), (u"> @%s said:\n> text\n> new line\n\n" % self.user.username).splitlines())
self.assertListEqual(quote.splitlines(), ("> @%s said:\n> text\n> new line\n\n" % self.user.username).splitlines())
@override_settings(LANGUAGE_CODE='en')
def test_markdown_quote_header_language(self):
@ -357,7 +357,7 @@ class UtilsMarkdownTests(TestCase):
quote = quotify(comment, self.user)
with translation.override('es'):
self.assertListEqual(quote.splitlines(), (u"> @%s said:\n> \n\n" % self.user.username).splitlines())
self.assertListEqual(quote.splitlines(), ("> @%s said:\n> \n\n" % self.user.username).splitlines())
def test_markdown_image(self):
"""
@ -371,15 +371,15 @@ class UtilsMarkdownTests(TestCase):
md = Markdown(escape=True, hard_wrap=True)
comment_md = md.render(comment)
self.assertListEqual(comment_md.splitlines(), '<p><img src="http://foo.bar/image.png" alt="image" title="image"></p>\n'
'<p><img src="http://www.foo.bar.fb/path/image.png" alt="image" title="image"></p>\n'
'<p><img src="https://foo.bar/image.png" alt="image" title="image"></p>\n'
'<p>bad <a href="http://foo.bar/image.png">http://foo.bar/image.png</a><br>' # autolink
'<a href="http://foo.bar/image.png">http://foo.bar/image.png</a> bad<br>' # autolink
'<a href="http://bad.png">http://bad.png</a><br>' # autolink
'<a href="http://foo.bar/.png">http://foo.bar/.png</a><br>' # autolink
'<img src="http://foo.bar/not_imagified.png" alt="im"><br>'
'foo.bar/bad.png</p>\n'
'<p><img src="http://foo.bar/&lt;escaped&gt;.png" alt="&lt;escaped&gt;" title="&lt;escaped&gt;"></p>\n'.splitlines())
'<p><img src="http://www.foo.bar.fb/path/image.png" alt="image" title="image"></p>\n'
'<p><img src="https://foo.bar/image.png" alt="image" title="image"></p>\n'
'<p>bad <a href="http://foo.bar/image.png">http://foo.bar/image.png</a><br>' # autolink
'<a href="http://foo.bar/image.png">http://foo.bar/image.png</a> bad<br>' # autolink
'<a href="http://bad.png">http://bad.png</a><br>' # autolink
'<a href="http://foo.bar/.png">http://foo.bar/.png</a><br>' # autolink
'<img src="http://foo.bar/not_imagified.png" alt="im"><br>'
'foo.bar/bad.png</p>\n'
'<p><img src="http://foo.bar/&lt;escaped&gt;.png" alt="&lt;escaped&gt;" title="&lt;escaped&gt;"></p>\n'.splitlines())
def test_markdown_youtube(self):
"""
@ -395,12 +395,12 @@ class UtilsMarkdownTests(TestCase):
md = Markdown(escape=True, hard_wrap=True)
comment_md = md.render(comment)
self.assertListEqual(comment_md.splitlines(), '<span class="video"><iframe src="https://www.youtube.com/embed/Z0UISCEe52Y?feature=oembed" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://www.youtube.com/embed/afyK1HSFfgw?feature=oembed" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://www.youtube.com/embed/vsF0K3Ou1v0?feature=oembed" allowfullscreen></iframe></span>'
'\n<p><a href="https://www.youtube.com/watch?v=&lt;bad&amp;gt">https://www.youtube.com/watch?v=&lt;bad&amp;gt</a>;<br>' # smart_amp ain't smart
'<a href="https://www.noyoutube.com/watch?v=Z0UISCEe52Y">https://www.noyoutube.com/watch?v=Z0UISCEe52Y</a><br>'
'badbad <a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a><br>'
'<a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a> badbad</p>'.splitlines())
'\n<span class="video"><iframe src="https://www.youtube.com/embed/afyK1HSFfgw?feature=oembed" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://www.youtube.com/embed/vsF0K3Ou1v0?feature=oembed" allowfullscreen></iframe></span>'
'\n<p><a href="https://www.youtube.com/watch?v=&lt;bad&amp;gt">https://www.youtube.com/watch?v=&lt;bad&amp;gt</a>;<br>' # smart_amp ain't smart
'<a href="https://www.noyoutube.com/watch?v=Z0UISCEe52Y">https://www.noyoutube.com/watch?v=Z0UISCEe52Y</a><br>'
'badbad <a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a><br>'
'<a href="https://www.youtube.com/watch?v=Z0UISCEe52Y">https://www.youtube.com/watch?v=Z0UISCEe52Y</a> badbad</p>'.splitlines())
def test_markdown_vimeo(self):
"""
@ -419,15 +419,15 @@ class UtilsMarkdownTests(TestCase):
md = Markdown(escape=True, hard_wrap=True)
comment_md = md.render(comment)
self.assertListEqual(comment_md.splitlines(), '<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<p><a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
'bad <a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
'<a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a> bad</p>'.splitlines())
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<span class="video"><iframe src="https://player.vimeo.com/video/11111111" allowfullscreen></iframe></span>'
'\n<p><a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
'bad <a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a><br>'
'<a href="https://novimeo.com/11111111">https://novimeo.com/11111111</a> bad</p>'.splitlines())
def test_markdown_video(self):
"""
@ -450,7 +450,7 @@ class UtilsMarkdownTests(TestCase):
md = Markdown(escape=True, hard_wrap=True)
comment_md = md.render(comment)
self.assertListEqual(comment_md.splitlines(), '<audio controls><source src="http://foo.bar/audio.mp3"><a href="http://foo.bar/audio.mp3">http://foo.bar/audio.mp3</a></audio>'
'\n<audio controls><source src="http://foo.bar/&lt;escaped&gt;.mp3"><a href="http://foo.bar/&lt;escaped&gt;.mp3">http://foo.bar/&lt;escaped&gt;.mp3</a></audio>'.splitlines())
'\n<audio controls><source src="http://foo.bar/&lt;escaped&gt;.mp3"><a href="http://foo.bar/&lt;escaped&gt;.mp3">http://foo.bar/&lt;escaped&gt;.mp3</a></audio>'.splitlines())
class UtilsUserTests(TestCase):

Some files were not shown because too many files have changed in this diff Show More