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

Commit

Permalink
merge with default
Browse files Browse the repository at this point in the history
--HG--
branch : stable
  • Loading branch information
slav0nic committed Aug 25, 2015
2 parents 5ec949d + 92a85d4 commit 1b1746d
Show file tree
Hide file tree
Showing 43 changed files with 985 additions and 634 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.py[co]
*.egg-info
*.egg
.idea/
.pydevproject
.project
.settings
Expand All @@ -10,4 +12,6 @@
local_settings.py
.env
build/
dist/
dist/
.tox/
venv/
2 changes: 2 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax: glob
*.pyo
*.orig
*.egg
.eggs
*.egg-info
.pydevproject
.project
Expand All @@ -21,3 +22,4 @@ local_settings.py
build/
dist/
.idea
.tox/
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
recursive-include djangobb_forum *
global-exclude *.pyc
include requirements.txt
31 changes: 14 additions & 17 deletions djangobb_forum/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# coding: utf-8

from django.contrib import admin
from django.contrib.auth import admin as auth_admin
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from djangobb_forum.models import Category, Forum, Topic, Post, Profile, Reputation, \
Report, Ban, Attachment, Poll, PollChoice, PostTracking
from djangobb_forum.user import User


class BaseModelAdmin(admin.ModelAdmin):
def get_actions(self, request):
Expand Down Expand Up @@ -51,22 +50,24 @@ class ReputationAdmin(BaseModelAdmin):
raw_id_fields = ['from_user', 'to_user', 'post']

class ReportAdmin(BaseModelAdmin):
list_display = ['reported_by', 'post', 'zapped', 'zapped_by', 'created', 'reason']
raw_id_fields = ['reported_by', 'post']
list_display = ['reported_by', 'post', 'zapped', 'zapped_by', 'created', 'reason', 'link_to_post']
raw_id_fields = ['reported_by', 'post', 'zapped_by']
list_filter = ('zapped', 'created')

def link_to_post(self, instance):
return '<a href="%(link)s">#%(pk)s</a>' % {'link': instance.post.get_absolute_url(), 'pk': instance.post.pk}
link_to_post.short_description = _("Link to post")
link_to_post.allow_tags = True

def save_model(self, request, obj, form, change):
if change and obj.zapped:
obj.zapped_by = request.user
obj.save()

class BanAdmin(BaseModelAdmin):
list_display = ['user', 'ban_start', 'ban_end', 'reason']
raw_id_fields = ['user']

class UserAdmin(auth_admin.UserAdmin):
list_display = ['username', 'email', 'first_name', 'last_name', 'is_staff', 'is_active']

def get_urls(self):
from django.conf.urls import patterns, url
return patterns('',
url(r'^(\d+)/password/$', self.admin_site.admin_view(self.user_change_password), name='user_change_password'),
) + super(auth_admin.UserAdmin, self).get_urls()

class AttachmentAdmin(BaseModelAdmin):
list_display = ['id', 'name', 'size', 'path', 'hash', ]
search_fields = ['name']
Expand All @@ -86,10 +87,6 @@ class PollAdmin(admin.ModelAdmin):
inlines = [PollChoiceInline]


if settings.AUTH_USER_MODEL == 'auth.User':
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

admin.site.register(Category, CategoryAdmin)
admin.site.register(Forum, ForumAdmin)
admin.site.register(Topic, TopicAdmin)
Expand Down
13 changes: 6 additions & 7 deletions djangobb_forum/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

class AutoSingleRelatedObjectDescriptor(SingleRelatedObjectDescriptor):
def __get__(self, instance, instance_type=None):
# TODO: Rewrite after drop django 1.6 support
model = getattr(self.related, 'related_model', self.related.model)

try:
return super(AutoSingleRelatedObjectDescriptor, self).__get__(instance, instance_type)
except self.related.model.DoesNotExist:
obj = self.related.model(**{self.related.field.name: instance})
except model.DoesNotExist:
obj = model(**{self.related.field.name: instance})
obj.save()
return obj
return (super(AutoSingleRelatedObjectDescriptor, self).__get__(instance, instance_type))


class AutoOneToOneField(OneToOneField):
Expand All @@ -37,8 +40,6 @@ class AutoOneToOneField(OneToOneField):

def contribute_to_related_class(self, cls, related):
setattr(cls, related.get_accessor_name(), AutoSingleRelatedObjectDescriptor(related))
#if not cls._meta.one_to_one_field:
# cls._meta.one_to_one_field = self


class ExtendedImageField(models.ImageField):
Expand Down Expand Up @@ -90,8 +91,6 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.TextField)):
Django snippet #1478
"""

__metaclass__ = models.SubfieldBase

def to_python(self, value):
if value == "":
return None
Expand Down
42 changes: 23 additions & 19 deletions djangobb_forum/forms.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
# coding: utf-8
from __future__ import unicode_literals

import os.path
from datetime import timedelta

from django import forms
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 djangobb_forum.models import Topic, Post, Profile, Reputation, Report, \
Attachment, Poll, PollChoice
from djangobb_forum import settings as forum_settings
from djangobb_forum.util import convert_text_to_html, set_language
from djangobb_forum.user import User


User = get_user_model()


SORT_USER_BY_CHOICES = (
('username', _(u'Username')),
('registered', _(u'Registered')),
('num_posts', _(u'No. of posts')),
('username', _('Username')),
('registered', _('Registered')),
('num_posts', _('No. of posts')),
)

SORT_POST_BY_CHOICES = (
('0', _(u'Post time')),
('1', _(u'Author')),
('2', _(u'Subject')),
('3', _(u'Forum')),
('0', _('Post time')),
('1', _('Author')),
('2', _('Subject')),
('3', _('Forum')),
)

SORT_DIR_CHOICES = (
('ASC', _(u'Ascending')),
('DESC', _(u'Descending')),
('ASC', _('Ascending')),
('DESC', _('Descending')),
)

SHOW_AS_CHOICES = (
('topics', _(u'Topics')),
('posts', _(u'Posts')),
('topics', _('Topics')),
('posts', _('Posts')),
)

SEARCH_IN_CHOICES = (
('all', _(u'Message text and topic subject')),
('message', _(u'Message text only')),
('topic', _(u'Topic subject only')),
('all', _('Message text and topic subject')),
('message', _('Message text only')),
('topic', _('Topic subject only')),
)


Expand Down Expand Up @@ -129,7 +133,7 @@ def save_attachment(self, post, memfile):
dir = os.path.join(settings.MEDIA_ROOT, forum_settings.ATTACHMENT_UPLOAD_TO)
fname = '%d.0' % post.id
path = os.path.join(dir, fname)
file(path, 'wb').write(memfile.read())
open(path, 'wb').write(memfile.read())
obj.path = fname
obj.save()

Expand Down Expand Up @@ -435,7 +439,7 @@ def clean_choice(self):
count = len(ids)
if count > self.poll.choice_count:
raise forms.ValidationError(
_(u'You have selected too many choices! (Only %i allowed.)') % self.poll.choice_count
_('You have selected too many choices! (Only %i allowed.)') % self.poll.choice_count
)
return ids

Expand Down Expand Up @@ -467,13 +471,13 @@ def clean_answers(self):
raw_answers = self.cleaned_data["answers"]
answers = [answer.strip() for answer in raw_answers.splitlines() if answer.strip()]
if len(answers) == 0:
raise forms.ValidationError(_(u"There is no valid answer!"))
raise forms.ValidationError(_("There is no valid answer!"))

# validate length of all answers
is_max_length = max([len(answer) for answer in answers])
should_max_length = PollChoice._meta.get_field("choice").max_length
if is_max_length > should_max_length:
raise forms.ValidationError(_(u"One of this answers are too long!"))
raise forms.ValidationError(_("One of this answers are too long!"))

return answers

Expand Down
12 changes: 7 additions & 5 deletions djangobb_forum/management/commands/djangobb_unban.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals

from optparse import make_option
from datetime import datetime

Expand All @@ -9,12 +11,12 @@
class Command(BaseCommand):

option_list = BaseCommand.option_list + (
make_option('--all', action='store_true', dest='all', default=False,
help=u'Unban all users'),
make_option('--by-time', action='store_true', dest='by-time', default=False,
help=u'Unban users by time'),
make_option('--all', action='store_true', dest='all', default=False,
help='Unban all users'),
make_option('--by-time', action='store_true', dest='by-time', default=False,
help='Unban users by time'),
)
help = u'Unban users'
help = 'Unban users'

def handle(self, *args, **options):
if options['all']:
Expand Down
4 changes: 2 additions & 2 deletions djangobb_forum/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def process_request(self, request):
guest_sid = request.COOKIES.get(global_settings.SESSION_COOKIE_NAME, '')
guests_online[guest_sid] = now

for user_id in users_online.keys():
for user_id in list(users_online.keys()):
if users_online[user_id] < delta:
del users_online[user_id]

for guest_id in guests_online.keys():
for guest_id in list(guests_online.keys()):
if guests_online[guest_id] < delta:
del guests_online[guest_id]

Expand Down
Loading

0 comments on commit 1b1746d

Please sign in to comment.