Commits

Gregory Petukhov  committed bdaa9db

Initial commit

  • Participants
  • Parent commits 87c06a6

Comments (0)

Files changed (15)

File pybb/__init__.py

Empty file added.

File pybb/admin.py

+# -*- coding: utf-8
+from django.contrib import admin
+
+from pybb.models import Category, Forum, Topic, Post
+
+class CategoryAdmin(admin.ModelAdmin):
+    list_display = ['name', 'position']
+
+
+class ForumAdmin(admin.ModelAdmin):
+    list_display = ['name', 'position']
+
+
+class TopicAdmin(admin.ModelAdmin):
+    list_display = ['name', 'forum', 'created']
+
+
+class PostAdmin(admin.ModelAdmin):
+    list_display = ['topic', 'created']
+
+
+admin.site.register(Category, CategoryAdmin)
+admin.site.register(Forum, ForumAdmin)
+admin.site.register(Topic, TopicAdmin)
+admin.site.register(Post, PostAdmin)

File pybb/forms.py

+# coding: utf-8
+from django import forms
+
+from pybb.models import Post
+
+class PostForm(forms.ModelForm):
+    class Meta:
+        model = Post
+        fields = ['content']
+
+
+class TopicForm(forms.Form):
+    name = forms.CharField(label=u'Название темы')
+    content = forms.CharField(label=u'Сообщение', widget=forms.Textarea)

File pybb/migrations/0001_initial.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'Category'
+        db.create_table('pybb_category', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('position', self.gf('django.db.models.fields.IntegerField')(default=0, db_index=True, blank=True)),
+        ))
+        db.send_create_signal('pybb', ['Category'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'Category'
+        db.delete_table('pybb_category')
+
+
+    models = {
+        'pybb.category': {
+            'Meta': {'object_name': 'Category'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['pybb']

File pybb/migrations/0002_auto__add_forum__add_topic__add_field_category_created.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'Forum'
+        db.create_table('pybb_forum', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('created', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, blank=True)),
+            ('category', self.gf('django.db.models.fields.related.ForeignKey')(related_name='forums', to=orm['pybb.Category'])),
+        ))
+        db.send_create_signal('pybb', ['Forum'])
+
+        # Adding model 'Topic'
+        db.create_table('pybb_topic', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('created', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, blank=True)),
+            ('forum', self.gf('django.db.models.fields.related.ForeignKey')(related_name='topics', to=orm['pybb.Forum'])),
+        ))
+        db.send_create_signal('pybb', ['Topic'])
+
+        # Adding field 'Category.created'
+        db.add_column('pybb_category', 'created',
+                      self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, blank=True),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting model 'Forum'
+        db.delete_table('pybb_forum')
+
+        # Deleting model 'Topic'
+        db.delete_table('pybb_topic')
+
+        # Deleting field 'Category.created'
+        db.delete_column('pybb_category', 'created')
+
+
+    models = {
+        'pybb.category': {
+            'Meta': {'object_name': 'Category'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        },
+        'pybb.forum': {
+            'Meta': {'object_name': 'Forum'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'forums'", 'to': "orm['pybb.Category']"}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'pybb.topic': {
+            'Meta': {'object_name': 'Topic'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'topics'", 'to': "orm['pybb.Forum']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        }
+    }
+
+    complete_apps = ['pybb']

File pybb/migrations/0003_auto__add_field_forum_position.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Forum.position'
+        db.add_column('pybb_forum', 'position',
+                      self.gf('django.db.models.fields.IntegerField')(default=0, db_index=True, blank=True),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'Forum.position'
+        db.delete_column('pybb_forum', 'position')
+
+
+    models = {
+        'pybb.category': {
+            'Meta': {'object_name': 'Category'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        },
+        'pybb.forum': {
+            'Meta': {'object_name': 'Forum'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'forums'", 'to': "orm['pybb.Category']"}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        },
+        'pybb.topic': {
+            'Meta': {'object_name': 'Topic'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'topics'", 'to': "orm['pybb.Forum']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        }
+    }
+
+    complete_apps = ['pybb']

File pybb/migrations/0004_auto__add_field_forum_topic_count__add_field_forum_post_count.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Forum.topic_count'
+        db.add_column('pybb_forum', 'topic_count',
+                      self.gf('django.db.models.fields.IntegerField')(default=0, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Forum.post_count'
+        db.add_column('pybb_forum', 'post_count',
+                      self.gf('django.db.models.fields.IntegerField')(default=0, blank=True),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'Forum.topic_count'
+        db.delete_column('pybb_forum', 'topic_count')
+
+        # Deleting field 'Forum.post_count'
+        db.delete_column('pybb_forum', 'post_count')
+
+
+    models = {
+        'pybb.category': {
+            'Meta': {'object_name': 'Category'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        },
+        'pybb.forum': {
+            'Meta': {'object_name': 'Forum'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'forums'", 'to': "orm['pybb.Category']"}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'topic_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        },
+        'pybb.topic': {
+            'Meta': {'object_name': 'Topic'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'topics'", 'to': "orm['pybb.Forum']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        }
+    }
+
+    complete_apps = ['pybb']

File pybb/migrations/0005_auto__add_post.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'Post'
+        db.create_table('pybb_post', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('created', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, blank=True)),
+            ('topic', self.gf('django.db.models.fields.related.ForeignKey')(related_name='posts', to=orm['pybb.Topic'])),
+            ('content', self.gf('django.db.models.fields.TextField')()),
+            ('content_html', self.gf('django.db.models.fields.TextField')(blank=True)),
+        ))
+        db.send_create_signal('pybb', ['Post'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'Post'
+        db.delete_table('pybb_post')
+
+
+    models = {
+        'pybb.category': {
+            'Meta': {'object_name': 'Category'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        },
+        'pybb.forum': {
+            'Meta': {'object_name': 'Forum'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'forums'", 'to': "orm['pybb.Category']"}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'topic_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        },
+        'pybb.post': {
+            'Meta': {'object_name': 'Post'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'content_html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'topic': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['pybb.Topic']"})
+        },
+        'pybb.topic': {
+            'Meta': {'object_name': 'Topic'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'topics'", 'to': "orm['pybb.Forum']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        }
+    }
+
+    complete_apps = ['pybb']

File pybb/migrations/0006_auto__add_field_topic_post_count.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Topic.post_count'
+        db.add_column('pybb_topic', 'post_count',
+                      self.gf('django.db.models.fields.IntegerField')(default=0, blank=True),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'Topic.post_count'
+        db.delete_column('pybb_topic', 'post_count')
+
+
+    models = {
+        'pybb.category': {
+            'Meta': {'object_name': 'Category'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        },
+        'pybb.forum': {
+            'Meta': {'object_name': 'Forum'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'forums'", 'to': "orm['pybb.Category']"}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'topic_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        },
+        'pybb.post': {
+            'Meta': {'object_name': 'Post'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'content_html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'topic': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['pybb.Topic']"})
+        },
+        'pybb.topic': {
+            'Meta': {'object_name': 'Topic'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'topics'", 'to': "orm['pybb.Forum']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['pybb']

File pybb/migrations/0007_auto__add_field_post_user.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Post.user'
+        db.add_column('pybb_post', 'user',
+                      self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['auth.User']),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'Post.user'
+        db.delete_column('pybb_post', 'user_id')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'pybb.category': {
+            'Meta': {'object_name': 'Category'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'})
+        },
+        'pybb.forum': {
+            'Meta': {'object_name': 'Forum'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'forums'", 'to': "orm['pybb.Category']"}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'topic_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        },
+        'pybb.post': {
+            'Meta': {'object_name': 'Post'},
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'content_html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'topic': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['pybb.Topic']"}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+        },
+        'pybb.topic': {
+            'Meta': {'object_name': 'Topic'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'blank': 'True'}),
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'topics'", 'to': "orm['pybb.Forum']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['pybb']

File pybb/migrations/__init__.py

Empty file added.

File pybb/models.py

+# -*- coding: utf-8 -*-
+from datetime import datetime
+
+from django.db import models
+from django.core.urlresolvers import reverse
+
+class Category(models.Model):
+    name = models.CharField(max_length=100)
+    created = models.DateTimeField(blank=True, default=datetime.now)
+    position = models.IntegerField(blank=True, default=0, db_index=True)
+
+    class Meta:
+        verbose_name_plural = 'Categories'
+
+    def __unicode__(self):
+        return self.name
+
+
+class Forum(models.Model):
+    name = models.CharField(max_length=100)
+    created = models.DateTimeField(blank=True, default=datetime.now)
+    category = models.ForeignKey('pybb.Category', related_name='forums')
+    position = models.IntegerField(blank=True, default=0, db_index=True)
+    topic_count = models.IntegerField(blank=True, default=0)
+    post_count = models.IntegerField(blank=True, default=0)
+
+    def __unicode__(self):
+        return self.name
+
+    def get_absolute_url(self):
+        return reverse('pybb:forum_page', args=[self.pk])
+
+
+class Topic(models.Model):
+    name = models.CharField(max_length=100)
+    created = models.DateTimeField(blank=True, default=datetime.now)
+    forum = models.ForeignKey('pybb.Forum', related_name='topics')
+    post_count = models.IntegerField(blank=True, default=0)
+
+    def __unicode__(self):
+        return self.name
+
+    def get_absolute_url(self):
+        return reverse('pybb:topic_page', args=[self.pk])
+
+
+class Post(models.Model):
+    created = models.DateTimeField(blank=True, default=datetime.now)
+    topic = models.ForeignKey('pybb.Topic', related_name='posts')
+    content = models.TextField()
+    content_html = models.TextField(blank=True)
+    user = models.ForeignKey('auth.User')
+
+    def __unicode__(self):
+        return self.topic.name
+
+
+import pybb.signals

File pybb/signals.py

+from django.db.models.signals import post_save
+from django.dispatch import receiver
+from django.db.models import F
+
+from pybb.models import Forum, Topic, Post
+
+@receiver(post_save, sender=Topic)
+def topic_post_save(instance, **kwargs):
+    topic = instance
+    Forum.objects.filter(pk=topic.forum_id)\
+         .update(topic_count=F('topic_count') + 1)
+
+
+@receiver(post_save, sender=Post)
+def post_post_save(instance, **kwargs):
+    post = instance
+    topic = post.topic
+    Topic.objects.filter(pk=post.topic_id)\
+         .update(post_count=F('post_count') + 1)
+    Forum.objects.filter(pk=topic.forum_id)\
+         .update(post_count=F('post_count') + 1)

File pybb/urls.py

+# -*- coding: utf-8 -*-
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('pybb.views',
+    url(r'^$', 'home_page', name='home_page'),
+    url(r'^forum/(\d+)$', 'forum_page', name='forum_page'),
+    url(r'^topic/(\d+)$', 'topic_page', name='topic_page'),
+    url(r'^post/add$', 'post_add', name='post_add'),
+    url(r'^topic/add$', 'topic_add', name='topic_add'),
+)

File pybb/views.py

+# -*- coding: utf-8 -*-
+import logging
+
+from django.shortcuts import redirect, get_object_or_404, render
+from django.core.urlresolvers import reverse
+from django.template.loader import render_to_string
+from django.conf import settings
+from django.contrib.auth.decorators import login_required
+
+from common.pagination import paginate
+
+from pybb.models import Category, Forum, Topic, Post
+from pybb.forms import PostForm, TopicForm
+
+def home_page(request):
+    cats = Category.objects.order_by('position')
+    context = {'cats': cats,
+            }
+    return render(request, 'pybb/home_page.html', context)
+
+
+def forum_page(request, pk):
+    forum = get_object_or_404(Forum, pk=pk)
+    context = {'forum': forum,
+            }
+    return render(request, 'pybb/forum_page.html', context)
+
+
+def topic_page(request, pk):
+    topic = get_object_or_404(Topic, pk=pk)
+    posts = Post.objects.filter(topic=topic).order_by('created')
+    context = {'topic': topic,
+               'posts': posts,
+            }
+    return render(request, 'pybb/topic_page.html', context)
+
+
+@login_required
+def post_add(request):
+    topic_id = request.GET.get('topic')
+    topic = get_object_or_404(Topic, pk=topic_id)
+    instance = Post(topic=topic, user=request.user)
+    form = PostForm(request.POST or None, instance=instance)
+    if form.is_valid():
+        form.save()
+        return redirect(topic)
+    context = {'form': form,
+               'topic': topic,
+            }
+    return render(request, 'pybb/post_add.html', context)
+
+
+@login_required
+def topic_add(request):
+    forum_id = request.GET.get('forum')
+    forum = get_object_or_404(Forum, pk=forum_id)
+    form = TopicForm(request.POST or None)
+    if form.is_valid():
+        topic = Topic.objects.create(
+            name=form.cleaned_data['name'],
+            forum=forum)
+        post = Post.objects.create(
+            topic=topic,
+            user=request.user,
+            content=form.cleaned_data['content'],
+        )
+        return redirect(topic)
+    context = {'form': form,
+               'forum': forum,
+            }
+    return render(request, 'pybb/topic_add.html', context)