Commits

Anonymous committed 5c34395

Initial checkin

Comments (0)

Files changed (8)

+~$
+pyc$

Empty file added.

Empty file added.

gnocchi_forum/models.py

+from django.db import models
+from datetime import datetime
+from gnocchi_forum import settings
+
+THREAD_STATE_CHOICES = (
+    ('open', 'Open to General postings.'),
+    ('frozen', 'No new posts allowed.'),
+)
+
+MARKUP_CHOCIES = (
+    ('markdown', 'Markdown',),
+)
+
+class Category(models.Model):
+    '''Top level grouping of posts'''
+    name = models.CharField(max_length=256)
+    slug = models.SlugField(unique=True)
+    order = models.IntegerField(default=0, help_text='Highest number first')
+
+    class Meta:
+        ordering = ('-order')
+
+    @models.permalink
+    def get_absolute_url(self):
+        return 'gnocchi_forum:category-details', (), {'category': self.slug}
+
+class Forum(models.Model):
+    '''Topic within a Category'''
+    title = models.CharField(max_lengtu=256)
+    slug = models.SlugField(unique=True)
+    category = models.ForeignKey(Category)
+    description = models.TextArea(blank=True)
+
+    class Meta:
+        unique_together = (
+            ('category', 'slug',),
+        )
+
+    @models.permalink
+    def get_absolute_url(self):
+        return 'gnocchi_forum:forum-details', (), {
+            'forum': self.slug
+        }
+
+class Thread(models.Model):
+    '''List of posts within a Topic'''
+    title = models.CharField(max_lengtu=256)
+    slug = models.SlugField(unique=True)
+    forum = models.ForeignKey(Forum)
+    pinned = models.BooleanField(default=False)
+    state = models.CharField(max_length=16, choices=THREAD_STATE_CHOICES)
+
+    class Meta:
+        ordering = ('-pinned',)
+        unique_together = (
+            ('forum', 'slug',),
+        )
+
+    @models.permalink
+    def get_absolute_url(self):
+        return 'gnocchi_forum:forum-details', (), {
+            'forum': self.forum.slug,
+            'thread': self.slug,
+        }
+
+
+class Post(models.Model):
+    thread = models.ForeignKey(Thread)
+    posted_by = models.ForeignKey('auth.User')
+    created = models.DateTimeField(default=datetime.now)
+    reply_to = models.ForeignKey('self', blank=True, null=True)
+    content = models.TextArea(blank=True)
+    markup = models.CharField(max_length=16, default=settings.DEFAULT_MARKUP,
+        choices=MARKUP_CHOICES)
+
+    # XXX Moderation
+
+    @models.permalink
+    def get_absolute_url(self):
+        return 'gnocchi_forum:post-details', (), {
+            'forum_id': self.thread.forum.pk,
+            'thread_id': self.thread.pk,
+            'object_id': self.pk,
+        }
+
+class Profile(models.Model):
+    user = models.ForeignKey('auth.User')

gnocchi_forum/settings.py

+from django.conf import settings
+
+DEFAULT_MARKUP = getattr(settings, 'FORUM_DEFAULT_MARKUP', 'markdown')

gnocchi_forum/urls.py

+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('gnocchi_forum.views',
+    url(r'^$', 'forum_index', name='gnocchi_forum:forum-index'),
+    url(r'^forum/(?P<forum>[-\w]+)/$', 'forum_detail', name='gnocchi_forum:forum-details'),
+    url(r'^forum/(?P<forum>[-\w]+)/(?P<thread>[-\w]+/$', 'thread_detail', name='gnocchi_forum:forum-details'),
+)

gnocchi_forum/views.py

+from django.views.generic import direct_to_template
+from django.views.list_detail import object_list
+from gnocchi_forum import models
+
+# Need:
+#   Front page [Categories + Forums]
+def forum_index(request):
+    return direct_to_template(request, 'forum/index.html',
+        extra_context = {
+            # XXX Any reason to filter these?
+            'category_list': models.Category.objects.all()
+        }
+    )
+
+#   Forum detail [ thread list ]
+def forum_detail(request, forum):
+    forum = get_object_or_404(models.Forum, slug=forum)
+    # permssion check?
+    return object_list(request,
+        queryset = forum.thread_set.all(),
+        extra_context = {
+            'forum': forum,
+        }
+    )
+
+#   Thread detail [ post list ]
+def thread_detail(request, forum, thread):
+    thread = get_object_or_404(models.Thread, slug=thread, forum__slug=forum)
+    return object_list(request,
+        queryset = thread.post_set.all(),
+        extra_context = {
+            'thread': thread,
+        }
+    )
+
+#   Post [ajax?]
+#   Edit Profile
+from setuptools import setup, find_packages
+
+setup( name='gnocchi-forum',
+    version = '0.0.1',
+    description = 'A simple Forum',
+    author = 'Curtis Maloney',
+    author_email = 'curtis@tinbrain.net',
+    url = 'http://bitbucket.org/funkybob/gnocchi-forum/',
+    keywords = ['django', 'forum',],
+    packages = find_packages(),
+    zip_safe = False,
+    classifiers = [
+        'Environment :: Web Environment',
+        'Framework :: Django',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+    ],
+    install_requires = [
+        'Django>=1.2',
+        'gnocchi-tools>=1.0',
+        'pytz>=2010o',
+        'markdown',
+        'django-guardian',
+    ]
+)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.