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

Upper version of django-haystack in requirements #60

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion djangobb_forum/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.conf import settings
from djangobb_forum.models import Category, Forum, Topic, Post, Profile, Reputation, \
Report, Ban, Attachment, Poll, PollChoice, PostTracking
Expand Down
2 changes: 1 addition & 1 deletion djangobb_forum/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class ForumConfig(AppConfig):
Expand Down
7 changes: 5 additions & 2 deletions djangobb_forum/feeds.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.contrib.syndication.views import Feed, FeedDoesNotExist
from django.utils.feedgenerator import Atom1Feed
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.db.models import Q
from django.http import Http404
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse

from djangobb_forum.models import Post, Topic, Forum, Category

Expand Down
4 changes: 2 additions & 2 deletions djangobb_forum/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
from hashlib import sha1
import json
import six

from django.db.models import OneToOneField
try:
Expand All @@ -13,8 +14,7 @@
from django.core.serializers.json import DjangoJSONEncoder
from django.conf import settings
from django.forms.utils import ValidationError
from django.utils import six
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class AutoReverseOneToOneDescriptor(ReverseOneToOneDescriptor):
Expand Down
2 changes: 1 addition & 1 deletion djangobb_forum/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from djangobb_forum.models import Topic, Post, Profile, Reputation, Report, \
Attachment, Poll, PollChoice
Expand Down
8 changes: 4 additions & 4 deletions djangobb_forum/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

class LastLoginMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
if request.user.is_authenticated:
cache.set('djangobb_user%d' % request.user.id, True, forum_settings.USER_ONLINE_TIMEOUT)


class ForumMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
if request.user.is_authenticated:
profile = request.user.forum_profile
language = translation.get_language_from_request(request)

Expand All @@ -37,7 +37,7 @@ def process_request(self, request):
users_online = cache.get('djangobb_users_online', {})
guests_online = cache.get('djangobb_guests_online', {})

if request.user.is_authenticated():
if request.user.is_authenticated:
users_online[request.user.id] = now
else:
guest_sid = request.COOKIES.get(global_settings.SESSION_COOKIE_NAME, '')
Expand All @@ -57,7 +57,7 @@ def process_request(self, request):

class TimezoneMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
if request.user.is_authenticated:
profile = request.user.forum_profile
try:
timezone.activate(profile.time_zone)
Expand Down
52 changes: 25 additions & 27 deletions djangobb_forum/migrations/0001_initial.py

Large diffs are not rendered by default.

54 changes: 29 additions & 25 deletions djangobb_forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

from hashlib import sha1
import os
from six import python_2_unicode_compatible

from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.auth.models import Group
from django.db import models
from django.db.models import aggregates
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from django.utils.translation import gettext_lazy as _
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse

import pytz

Expand Down Expand Up @@ -78,7 +80,7 @@ def has_access(self, user):
if user.is_superuser:
return True
if self.groups.exists():
if user.is_authenticated():
if user.is_authenticated:
if not self.groups.filter(user__pk=user.id).exists():
return False
else:
Expand All @@ -88,15 +90,15 @@ def has_access(self, user):

@python_2_unicode_compatible
class Forum(models.Model):
category = models.ForeignKey(Category, related_name='forums', verbose_name=_('Category'))
category = models.ForeignKey(Category, related_name='forums', verbose_name=_('Category'), on_delete=models.CASCADE)
name = models.CharField(_('Name'), max_length=80)
position = models.IntegerField(_('Position'), blank=True, default=0)
description = models.TextField(_('Description'), blank=True, default='')
moderators = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, verbose_name=_('Moderators'))
updated = models.DateTimeField(_('Updated'), auto_now=True)
post_count = models.IntegerField(_('Post count'), blank=True, default=0)
topic_count = models.IntegerField(_('Topic count'), blank=True, default=0)
last_post = models.ForeignKey('Post', related_name='last_forum_post', blank=True, null=True)
last_post = models.ForeignKey('Post', related_name='last_forum_post', blank=True, null=True, on_delete=models.SET_NULL)
forum_logo = ExtendedImageField(_('Forum Logo'), blank=True, default='',
upload_to=forum_settings.FORUM_LOGO_UPLOAD_TO,
width=forum_settings.FORUM_LOGO_WIDTH,
Expand All @@ -120,17 +122,17 @@ def posts(self):

@python_2_unicode_compatible
class Topic(models.Model):
forum = models.ForeignKey(Forum, related_name='topics', verbose_name=_('Forum'))
forum = models.ForeignKey(Forum, related_name='topics', verbose_name=_('Forum'), on_delete=models.CASCADE)
name = models.CharField(_('Subject'), max_length=255)
created = models.DateTimeField(_('Created'), auto_now_add=True)
updated = models.DateTimeField(_('Updated'), null=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('User'))
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('User'), on_delete=models.CASCADE)
views = models.IntegerField(_('Views count'), blank=True, default=0)
sticky = models.BooleanField(_('Sticky'), blank=True, default=False)
closed = models.BooleanField(_('Closed'), blank=True, default=False)
subscribers = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='subscriptions', verbose_name=_('Subscribers'), blank=True)
post_count = models.IntegerField(_('Post count'), blank=True, default=0)
last_post = models.ForeignKey('Post', related_name='last_topic_post', blank=True, null=True)
last_post = models.ForeignKey('Post', related_name='last_topic_post', blank=True, null=True, on_delete=models.SET_NULL)

class Meta:
ordering = ['-updated']
Expand Down Expand Up @@ -196,11 +198,12 @@ def update_read(self, user):

@python_2_unicode_compatible
class Post(models.Model):
topic = models.ForeignKey(Topic, related_name='posts', verbose_name=_('Topic'))
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='posts', verbose_name=_('User'))
topic = models.ForeignKey(Topic, related_name='posts', verbose_name=_('Topic'), on_delete=models.CASCADE)
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='posts', verbose_name=_('User'), on_delete=models.CASCADE)
created = models.DateTimeField(_('Created'), auto_now_add=True)
updated = models.DateTimeField(_('Updated'), blank=True, null=True)
updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('Updated by'), blank=True, null=True)
updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('Updated by'), blank=True, null=True,
on_delete=models.SET_NULL)
markup = models.CharField(_('Markup'), max_length=15, default=forum_settings.DEFAULT_MARKUP, choices=MARKUP_CHOICES)
body = models.TextField(_('Message'))
body_html = models.TextField(_('HTML version'))
Expand Down Expand Up @@ -263,9 +266,9 @@ def summary(self):

@python_2_unicode_compatible
class Reputation(models.Model):
from_user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='reputations_from', verbose_name=_('From'))
to_user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='reputations_to', verbose_name=_('To'))
post = models.ForeignKey(Post, related_name='post', verbose_name=_('Post'))
from_user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='reputations_from', verbose_name=_('From'), on_delete=models.CASCADE)
to_user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='reputations_to', verbose_name=_('To'), on_delete=models.CASCADE)
post = models.ForeignKey(Post, related_name='post', verbose_name=_('Post'), on_delete=models.CASCADE)
time = models.DateTimeField(_('Time'), auto_now_add=True)
sign = models.IntegerField(_('Sign'), choices=SIGN_CHOICES, default=0)
reason = models.TextField(_('Reason'), max_length=1000)
Expand Down Expand Up @@ -294,7 +297,7 @@ def get_queryset(self):


class Profile(models.Model):
user = AutoOneToOneField(settings.AUTH_USER_MODEL, related_name='forum_profile', verbose_name=_('User'))
user = AutoOneToOneField(settings.AUTH_USER_MODEL, related_name='forum_profile', verbose_name=_('User'), on_delete=models.CASCADE)
status = models.CharField(_('Status'), max_length=30, blank=True)
site = models.URLField(_('Site'), blank=True)
jabber = models.CharField(_('Jabber'), max_length=80, blank=True)
Expand Down Expand Up @@ -338,7 +341,7 @@ class PostTracking(models.Model):
In topics stored ids of topics and last_posts as dict.
"""

user = AutoOneToOneField(settings.AUTH_USER_MODEL)
user = AutoOneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
topics = JSONField(null=True, blank=True)
last_read = models.DateTimeField(null=True, blank=True)

Expand All @@ -352,10 +355,11 @@ def __str__(self):

@python_2_unicode_compatible
class Report(models.Model):
reported_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='reported_by', verbose_name=_('Reported by'))
post = models.ForeignKey(Post, verbose_name=_('Post'))
reported_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='reported_by', verbose_name=_('Reported by'), on_delete=models.CASCADE)
post = models.ForeignKey(Post, verbose_name=_('Post'), on_delete=models.CASCADE)
zapped = models.BooleanField(_('Zapped'), blank=True, default=False)
zapped_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='zapped_by', blank=True, null=True, verbose_name=_('Zapped by'))
zapped_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='zapped_by', blank=True, null=True,
verbose_name=_('Zapped by'), on_delete=models.SET_NULL)
created = models.DateTimeField(_('Created'), blank=True)
reason = models.TextField(_('Reason'), blank=True, default='', max_length='1000')

Expand All @@ -369,7 +373,7 @@ def __str__(self):

@python_2_unicode_compatible
class Ban(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, verbose_name=_('Banned user'), related_name='ban_users')
user = models.OneToOneField(settings.AUTH_USER_MODEL, verbose_name=_('Banned user'), related_name='ban_users', on_delete=models.CASCADE)
ban_start = models.DateTimeField(_('Ban start'), default=timezone.now)
ban_end = models.DateTimeField(_('Ban end'), blank=True, null=True)
reason = models.TextField(_('Reason'))
Expand All @@ -394,7 +398,7 @@ def delete(self, *args, **kwargs):

@python_2_unicode_compatible
class Attachment(models.Model):
post = models.ForeignKey(Post, verbose_name=_('Post'), related_name='attachments')
post = models.ForeignKey(Post, verbose_name=_('Post'), related_name='attachments', on_delete=models.CASCADE)
size = models.IntegerField(_('Size'))
content_type = models.CharField(_('Content type'), max_length=255)
path = models.CharField(_('Path'), max_length=255)
Expand All @@ -420,7 +424,7 @@ def get_absolute_path(self):

@python_2_unicode_compatible
class Poll(models.Model):
topic = models.ForeignKey(Topic)
topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
question = models.CharField(max_length=200)
choice_count = models.PositiveSmallIntegerField(default=1,
help_text=_("How many choices are allowed simultaneously."),
Expand Down Expand Up @@ -450,7 +454,7 @@ def __str__(self):

@python_2_unicode_compatible
class PollChoice(models.Model):
poll = models.ForeignKey(Poll, related_name="choices")
poll = models.ForeignKey(Poll, related_name="choices", on_delete=models.CASCADE)
choice = models.CharField(max_length=200)
votes = models.IntegerField(default=0, editable=False)

Expand Down
5 changes: 4 additions & 1 deletion djangobb_forum/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils.html import strip_tags
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse

from djangobb_forum import settings as forum_settings
from djangobb_forum.util import absolute_url
Expand Down
19 changes: 11 additions & 8 deletions djangobb_forum/templatetags/forum_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
from __future__ import unicode_literals

import hashlib
from six.moves.urllib.parse import urlencode

from django import template
from django.core.urlresolvers import reverse
from django.core.cache import cache
from django.utils.safestring import mark_safe
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.conf import settings
from django.utils.html import escape
from django.utils import timezone
from django.contrib.humanize.templatetags.humanize import naturalday
from django.utils.six.moves.urllib.parse import urlencode
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse

from djangobb_forum.models import Report
from djangobb_forum import settings as forum_settings
Expand Down Expand Up @@ -58,7 +61,7 @@ def link(object, anchor=''):
"""

url = hasattr(object, 'get_absolute_url') and object.get_absolute_url() or None
anchor = anchor or smart_text(object)
anchor = anchor or smart_str(object)
return mark_safe('<a href="%s">%s</a>' % (url, escape(anchor)))


Expand All @@ -69,7 +72,7 @@ def lofi_link(object, anchor=''):
"""

url = hasattr(object, 'get_absolute_url') and object.get_absolute_url() or None
anchor = anchor or smart_text(object)
anchor = anchor or smart_str(object)
return mark_safe('<a href="%slofi/">%s</a>' % (url, escape(anchor)))


Expand All @@ -78,7 +81,7 @@ def has_unreads(topic, user):
"""
Check if topic has messages which user didn't read.
"""
if not user.is_authenticated() or\
if not user.is_authenticated or\
(user.posttracking.last_read is not None and\
user.posttracking.last_read > topic.updated):
return False
Expand All @@ -95,7 +98,7 @@ def forum_unreads(forum, user):
"""
Check if forum has topic which user didn't read.
"""
if not user.is_authenticated():
if not user.is_authenticated:
return False
else:
if isinstance(user.posttracking.topics, dict):
Expand Down Expand Up @@ -226,7 +229,7 @@ def gravatar(context, email):
def set_theme_style(user):
theme_style = ''
selected_theme = ''
if user.is_authenticated():
if user.is_authenticated:
selected_theme = user.forum_profile.theme
theme_style = '<link rel="stylesheet" type="text/css" href="%(static_url)sdjangobb_forum/themes/%(theme)s/style.css" />'
else:
Expand Down
Loading