Skip to content

Commit

Permalink
format code(pep8)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicalloy committed Feb 19, 2013
1 parent 9107611 commit 8a66fdc
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 206 deletions.
6 changes: 4 additions & 2 deletions lbforum/accountviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

from forms import SignatureForm


def profile(request, user_id=None, template_name="lbforum/account/profile.html"):
view_user = request.user
if user_id:
view_user = get_object_or_404(User, pk = user_id)
view_user = get_object_or_404(User, pk=user_id)
view_only = view_user != request.user
ext_ctx = {'view_user':view_user, 'view_only':view_only }
ext_ctx = {'view_user': view_user, 'view_only': view_only}
return render(request, template_name, ext_ctx)


@login_required
def signature(request, form_class=SignatureForm, template_name="lbforum/account/signature.html"):
profile = request.user.lbforum_profile
Expand Down
45 changes: 27 additions & 18 deletions lbforum/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,43 @@
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from models import Category, Forum, TopicType, Topic, \
Post, LBForumUserProfile, gen_last_post_info
from models import Category, Forum, TopicType, Topic
from models import Post, LBForumUserProfile

admin.site.register(Category)


def update_forum_state_info(modeladmin, request, queryset):
for forum in queryset:
forum.update_state_info()
update_forum_state_info.short_description = _("Update forum state info")


class ForumAdmin(admin.ModelAdmin):
list_display = ('name', 'slug', 'category', 'num_topics', \
'num_posts', )
list_filter = ('category',)
list_display = ('name', 'slug', 'category', 'num_topics', 'num_posts',)
list_filter = ('category',)
actions = [update_forum_state_info]

admin.site.register(Forum, ForumAdmin)


class TopicTypeAdmin(admin.ModelAdmin):
list_display = ('forum', 'name', 'slug', 'description', )
list_filter = ('forum',)
list_display = ('forum', 'name', 'slug', 'description', )
list_filter = ('forum',)

admin.site.register(TopicType, TopicTypeAdmin)


class PostInline(admin.TabularInline):
model = Post


def update_topic_state_info(modeladmin, request, queryset):
for topic in queryset:
topic.update_state_info()
update_topic_state_info.short_description = _("Update topic state info")


def update_topic_attr_as_not(modeladmin, request, queryset, attr):
for topic in queryset:
if attr == 'sticky':
Expand All @@ -45,39 +50,43 @@ def update_topic_attr_as_not(modeladmin, request, queryset, attr):
topic.hidden = not topic.hidden
topic.save()


def sticky_unsticky_topic(modeladmin, request, queryset):
update_topic_attr_as_not(modeladmin, request, queryset, 'sticky')
sticky_unsticky_topic.short_description = _("sticky/unsticky topics")


def close_unclose_topic(modeladmin, request, queryset):
update_topic_attr_as_not(modeladmin, request, queryset, 'close')
close_unclose_topic.short_description = _("close/unclose topics")


def hide_unhide_topic(modeladmin, request, queryset):
update_topic_attr_as_not(modeladmin, request, queryset, 'hide')
hide_unhide_topic.short_description = _("hide/unhide topics")


class TopicAdmin(admin.ModelAdmin):
list_display = ('subject', 'forum', 'topic_type', 'posted_by', 'sticky', 'closed',
list_display = ('subject', 'forum', 'topic_type', 'posted_by', 'sticky', 'closed',
'hidden', 'level', 'num_views', 'num_replies', 'created_on', 'updated_on', )
list_filter = ('forum', 'sticky', 'closed', 'hidden', 'level')
search_fields = ('subject', 'posted_by__username', )
#inlines = (PostInline, )
actions = [update_topic_state_info, sticky_unsticky_topic, close_unclose_topic,
hide_unhide_topic]
list_filter = ('forum', 'sticky', 'closed', 'hidden', 'level')
search_fields = ('subject', 'posted_by__username', )
#inlines = (PostInline, )
actions = [update_topic_state_info, sticky_unsticky_topic, close_unclose_topic, hide_unhide_topic]

admin.site.register(Topic, TopicAdmin)


class PostAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'topic', 'posted_by', 'poster_ip', \
list_display = ('__unicode__', 'topic', 'posted_by', 'poster_ip',
'created_on', 'updated_on', )
search_fields = ('topic__subject', 'posted_by__username', 'message', )
search_fields = ('topic__subject', 'posted_by__username', 'message', )

admin.site.register(Post, PostAdmin)


class LBForumUserProfileAdmin(admin.ModelAdmin):
list_display = ('user', 'userrank', 'last_activity', 'last_posttime', \
'signature', )
search_fields = ('user__username', 'userrank', )
list_display = ('user', 'userrank', 'last_activity', 'last_posttime', 'signature',)
search_fields = ('user__username', 'userrank', )

admin.site.register(LBForumUserProfile, LBForumUserProfileAdmin)
29 changes: 15 additions & 14 deletions lbforum/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@
from models import LBForumUserProfile

FORUM_ORDER_BY_CHOICES = (
('-last_reply_on', _('Last Reply')),
('-created_on', _('Last Topic')),
)
('-last_reply_on', _('Last Reply')),
('-created_on', _('Last Topic')),
)


class ForumForm(forms.Form):
order_by = forms.ChoiceField(label=_('Order By'), choices=FORUM_ORDER_BY_CHOICES,
required=False)
order_by = forms.ChoiceField(label=_('Order By'), choices=FORUM_ORDER_BY_CHOICES, required=False)


class PostForm(forms.ModelForm):
topic_type = forms.ChoiceField(label=_('Topic Type'), required=False)
subject = forms.CharField(label=_('Subject'), \
widget=forms.TextInput(attrs={'size':'80'}))
message = forms.CharField(label=_('Message'), \
widget=forms.Textarea(attrs={'cols':'95', 'rows':'14'}))
attachments = forms.Field(label=_('Attachments'), required=False,\
widget=forms.SelectMultiple())
subject = forms.CharField(label=_('Subject'), widget=forms.TextInput(attrs={'size': '80'}))
message = forms.CharField(label=_('Message'), widget=forms.Textarea(attrs={'cols': '95', 'rows': '14'}))
attachments = forms.Field(label=_('Attachments'), required=False, widget=forms.SelectMultiple())
need_replay = forms.BooleanField(label=_('Need Reply'), required=False)
need_reply_attachments = forms.BooleanField(label=_('Attachments Need Reply'), required=False)

Expand All @@ -43,9 +41,10 @@ def __init__(self, *args, **kwargs):
topic_types = self.forum.topictype_set.all()
self.fields['topic_type'].choices = [(tp.id, tp.name) for tp in topic_types]
self.fields['topic_type'].choices.insert(0, (('', '--------')))
self.fields.keyOrder = ['topic_type', 'subject', 'message', 'attachments', 'need_replay',
self.fields.keyOrder = ['topic_type', 'subject', 'message', 'attachments', 'need_replay',
'need_reply_attachments']


class EditPostForm(PostForm):
def __init__(self, *args, **kwargs):
super(EditPostForm, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -78,6 +77,7 @@ def save(self):
post.topic.save()
return post


class NewPostForm(PostForm):
def __init__(self, *args, **kwargs):
super(NewPostForm, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -113,9 +113,10 @@ def save(self):
post.update_attachments(attachments)
return post


class SignatureForm(forms.ModelForm):
signature = forms.CharField(label=_('Message'), required=False,\
widget=forms.Textarea(attrs={'cols':'65', 'rows':'4'}))
signature = forms.CharField(label=_('Message'), required=False,
widget=forms.Textarea(attrs={'cols': '65', 'rows': '4'}))

class Meta:
model = LBForumUserProfile
Expand Down
7 changes: 3 additions & 4 deletions lbforum/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

# Common framework for syncdb actions

import copy

from django.core import management
Expand All @@ -11,6 +8,7 @@

from south.management.commands.syncdb import Command as SyncCommand


class MigrateAndSyncCommand(SyncCommand):
"""Used for situations where "syncdb" is called by test frameworks."""

Expand All @@ -21,6 +19,7 @@ class MigrateAndSyncCommand(SyncCommand):
opt.default = True
break


def patch_for_test_db_setup():
# Load the commands cache
management.get_commands()
Expand All @@ -30,4 +29,4 @@ def patch_for_test_db_setup():
# tests should always be up to date with the most recent model structure
management._commands['syncdb'] = 'django.core'
else:
management._commands['syncdb'] = MigrateAndSyncCommand()
management._commands['syncdb'] = MigrateAndSyncCommand()
27 changes: 14 additions & 13 deletions lbforum/management/commands/lbforum_set_topic_post.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from django.core.management.base import BaseCommand

from lbforum.models import Topic

class Command(BaseCommand):
help = "update topic/post's base info."

def handle(self, **options):
topics = Topic.objects.all()
for t in topics:
post = t.posts.order_by('created_on').all()[0]
t.post = post
t.save()
from django.core.management.base import BaseCommand

from lbforum.models import Topic


class Command(BaseCommand):
help = "update topic/post's base info."

def handle(self, **options):
topics = Topic.objects.all()
for t in topics:
post = t.posts.order_by('created_on').all()[0]
t.post = post
t.save()
5 changes: 3 additions & 2 deletions lbforum/management/commands/update_posts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.core.management.base import BaseCommand

from lbforum.models import Topic, Post
from lbforum.models import Post


class Command(BaseCommand):
help = "update topic/post's base info."

def handle(self, **options):
posts = Post.objects.all()
for o in posts:
Expand Down
Loading

0 comments on commit 8a66fdc

Please sign in to comment.