aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/forum/__init__.py0
-rw-r--r--apps/forum/admin.py18
-rw-r--r--apps/forum/migrations/0001_initial.py109
-rw-r--r--apps/forum/migrations/__init__.py0
-rw-r--r--apps/forum/models.py145
-rw-r--r--apps/forum/urls.py12
-rw-r--r--apps/forum/views.py19
7 files changed, 303 insertions, 0 deletions
diff --git a/apps/forum/__init__.py b/apps/forum/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/forum/__init__.py
diff --git a/apps/forum/admin.py b/apps/forum/admin.py
new file mode 100644
index 0000000..9fddd4e
--- /dev/null
+++ b/apps/forum/admin.py
@@ -0,0 +1,18 @@
+from django.contrib import admin
+
+from .models import Topic, Category, Post
+
+
+@admin.register(Topic)
+class TopicAdmin(admin.ModelAdmin):
+ pass
+
+
+@admin.register(Category)
+class CategoryAdmin(admin.ModelAdmin):
+ pass
+
+
+@admin.register(Post)
+class PostAdmin(admin.ModelAdmin):
+ pass
diff --git a/apps/forum/migrations/0001_initial.py b/apps/forum/migrations/0001_initial.py
new file mode 100644
index 0000000..0785014
--- /dev/null
+++ b/apps/forum/migrations/0001_initial.py
@@ -0,0 +1,109 @@
+# Generated by Django 2.1.2 on 2018-12-02 16:38
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Category',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('title', models.CharField(max_length=120)),
+ ('slug', models.SlugField()),
+ ('date_created', models.DateTimeField(auto_now_add=True)),
+ ('date_updated', models.DateTimeField(auto_now=True)),
+ ('topic_count', models.PositiveIntegerField(default=0)),
+ ('topics_year', models.PositiveIntegerField(default=0)),
+ ('topics_month', models.PositiveIntegerField(default=0)),
+ ('topics_week', models.PositiveIntegerField(default=0)),
+ ],
+ options={
+ 'verbose_name_plural': 'Categories',
+ },
+ ),
+ migrations.CreateModel(
+ name='Post',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('post_type', models.CharField(choices=[('post', 'post'), ('reply', 'reply')], max_length=60)),
+ ('post_body_text', models.TextField(blank=True)),
+ ('post_body_html', models.TextField(blank=True, null=True)),
+ ('post_body_json', models.TextField(blank=True, null=True)),
+ ('date_created', models.DateTimeField(auto_now_add=True)),
+ ('date_updated', models.DateTimeField(auto_now=True)),
+ ('date_delete', models.DateTimeField(blank=True, null=True)),
+ ('reply_count', models.PositiveIntegerField(default=0)),
+ ('quote_count', models.PositiveIntegerField(default=0)),
+ ('like_count', models.PositiveIntegerField(default=0)),
+ ('bookmark_count', models.PositiveIntegerField(default=0)),
+ ('spam_count', models.PositiveIntegerField(default=0)),
+ ('reads', models.PositiveIntegerField(default=0)),
+ ('inappropriate_count', models.PositiveIntegerField(default=0)),
+ ('score', models.IntegerField(default=0)),
+ ('vote_count', models.IntegerField(default=0)),
+ ('last_editor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='post_last_editor', to=settings.AUTH_USER_MODEL)),
+ ('reply_below_post', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='post_reply_below', to='forum.Post')),
+ ('reply_to_post', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='post_reply_to', to='forum.Post')),
+ ('reply_to_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='post_reply_to_user', to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'verbose_name_plural': 'Posts',
+ },
+ ),
+ migrations.CreateModel(
+ name='Topic',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('title', models.CharField(max_length=255)),
+ ('slug', models.SlugField()),
+ ('date_last_posted', models.DateTimeField(auto_now=True)),
+ ('date_created', models.DateTimeField(auto_now_add=True)),
+ ('date_updated', models.DateTimeField(auto_now=True)),
+ ('date_deleted', models.DateTimeField(blank=True, null=True)),
+ ('date_bumped', models.DateTimeField(blank=True, null=True)),
+ ('views', models.PositiveIntegerField(default=0)),
+ ('posts_count', models.PositiveIntegerField(default=0)),
+ ('reply_count', models.PositiveIntegerField(default=0)),
+ ('like_count', models.PositiveIntegerField(default=0)),
+ ('bookmark_count', models.PositiveIntegerField(default=0)),
+ ('star_count', models.PositiveIntegerField(default=0)),
+ ('moderator_posts_count', models.PositiveIntegerField(default=0)),
+ ('vote_count', models.PositiveIntegerField(default=0)),
+ ('spam_count', models.PositiveIntegerField(default=0)),
+ ('illegal_count', models.PositiveIntegerField(default=0)),
+ ('inappropriate_count', models.PositiveIntegerField(default=0)),
+ ('visible', models.BooleanField(default=True)),
+ ('closed', models.BooleanField(default=False)),
+ ('pinned', models.BooleanField(default=False)),
+ ('archived', models.BooleanField(default=False)),
+ ('has_best_of', models.BooleanField(default=False)),
+ ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='forum.Category')),
+ ('highest_post', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='topic_highest_post', to='forum.Post')),
+ ('last_post_userj', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='topic_last_post_user', to=settings.AUTH_USER_MODEL)),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='topic_user', to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'verbose_name_plural': 'Topics',
+ },
+ ),
+ migrations.AddField(
+ model_name='post',
+ name='topic',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='forum.Topic'),
+ ),
+ migrations.AddField(
+ model_name='post',
+ name='user',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='post_user', to=settings.AUTH_USER_MODEL),
+ ),
+ ]
diff --git a/apps/forum/migrations/__init__.py b/apps/forum/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/forum/migrations/__init__.py
diff --git a/apps/forum/models.py b/apps/forum/models.py
new file mode 100644
index 0000000..d0f6b6f
--- /dev/null
+++ b/apps/forum/models.py
@@ -0,0 +1,145 @@
+from django.db import models
+from django.contrib import auth
+from django.urls import reverse
+from django.conf import settings
+
+
+class CategoryManager(models.Manager):
+
+ # create category
+ def create_category(self, title, slug=''):
+
+ if slug == '':
+ slug = title.lower().replace(' ', '-')
+
+ category = self.create(title=title, slug=slug)
+
+ return category
+
+ # get or create
+ def get_or_create(self, title):
+ try:
+ category = Category.objects.get(title=title)
+ except Category.DoesNotExist:
+ return (self.create_category(title), True)
+
+ return (category, False)
+
+
+class Category(models.Model):
+
+ title = models.CharField(max_length=120)
+ slug = models.SlugField()
+
+ date_created = models.DateTimeField(auto_now=False, auto_now_add=True)
+ date_updated = models.DateTimeField(auto_now=True, auto_now_add=False)
+
+ topic_count = models.PositiveIntegerField(default=0)
+ topics_year = models.PositiveIntegerField(default=0)
+ topics_month = models.PositiveIntegerField(default=0)
+ topics_week = models.PositiveIntegerField(default=0)
+
+ class Meta:
+ verbose_name_plural = "Categories"
+
+ objects = CategoryManager()
+
+ def __unicode__(self):
+ return self.title
+
+
+class TopicManager(models.Manager):
+
+ # create category
+ def create_topic(self, title, category, user, slug=''):
+
+ if slug == '':
+ slug = title.lower().replace(' ', '-')
+
+ topic = self.create(title=title, slug=slug, category=category, user=user)
+
+ return topic
+
+
+class Topic(models.Model):
+
+ category = models.ForeignKey(Category, on_delete=models.CASCADE)
+ user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='topic_user')
+ last_post_userj= models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='topic_last_post_user', blank=True, null=True)
+ highest_post = models.ForeignKey('Post', on_delete=models.CASCADE, related_name='topic_highest_post', blank=True, null=True)
+
+ title = models.CharField(max_length=255)
+ slug = models.SlugField()
+
+ date_last_posted = models.DateTimeField(auto_now=True, auto_now_add=False, blank=True)
+ date_created = models.DateTimeField(auto_now=False, auto_now_add=True, blank=True)
+ date_updated = models.DateTimeField(auto_now=True, auto_now_add=False, blank=True)
+ date_deleted = models.DateTimeField(blank=True, null=True)
+ date_bumped = models.DateTimeField(blank=True, null=True)
+
+ views = models.PositiveIntegerField(default=0)
+ posts_count = models.PositiveIntegerField(default=0)
+ reply_count = models.PositiveIntegerField(default=0)
+ like_count = models.PositiveIntegerField(default=0)
+ bookmark_count = models.PositiveIntegerField(default=0)
+ star_count = models.PositiveIntegerField(default=0)
+ moderator_posts_count = models.PositiveIntegerField(default=0)
+ vote_count = models.PositiveIntegerField(default=0)
+ spam_count = models.PositiveIntegerField(default=0)
+ illegal_count = models.PositiveIntegerField(default=0)
+ inappropriate_count = models.PositiveIntegerField(default=0)
+
+ visible = models.BooleanField(default=True)
+ closed = models.BooleanField(default=False)
+ pinned = models.BooleanField(default=False)
+ archived = models.BooleanField(default=False)
+ has_best_of = models.BooleanField(default=False)
+
+ objects = TopicManager()
+
+ class Meta:
+ verbose_name_plural = "Topics"
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ return reverse('forum:topic-detail', kwargs={"slug": self.slug, "pk": self.pk})
+
+
+class Post(models.Model):
+ topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
+ user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='post_user')
+ reply_to_post = models.ForeignKey('self', on_delete=models.CASCADE, related_name='post_reply_to', blank=True, null=True)
+ reply_to_user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='post_reply_to_user', blank=True, null=True)
+ reply_below_post = models.ForeignKey('self', on_delete=models.CASCADE, related_name='post_reply_below', blank=True, null=True)
+ last_editor = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='post_last_editor', blank=True, null=True)
+ POST_TYPE_CHOICES = (
+ ('post', 'post'),
+ ('reply', 'reply'),
+ )
+ post_type = models.CharField(max_length=60, choices=POST_TYPE_CHOICES)
+ post_body_text = models.TextField(blank=True, null=False)
+ post_body_html = models.TextField(blank=True, null=True)
+ post_body_json = models.TextField(blank=True, null=True)
+
+ date_created = models.DateTimeField(auto_now=False, auto_now_add=True, blank=True)
+ date_updated = models.DateTimeField(auto_now=True, auto_now_add=False, blank=True)
+ date_delete = models.DateTimeField(blank=True, null=True)
+
+ reply_count = models.PositiveIntegerField(default=0)
+ quote_count = models.PositiveIntegerField(default=0)
+ like_count = models.PositiveIntegerField(default=0)
+ bookmark_count = models.PositiveIntegerField(default=0)
+ spam_count = models.PositiveIntegerField(default=0)
+ reads = models.PositiveIntegerField(default=0)
+ inappropriate_count = models.PositiveIntegerField(default=0)
+
+ score = models.IntegerField(default=0)
+ vote_count = models.IntegerField(default=0)
+
+ class Meta:
+ verbose_name_plural = "Posts"
+
+ def __str__(self):
+ return '%s - %s' % (self.raw, self.topic.title)
diff --git a/apps/forum/urls.py b/apps/forum/urls.py
new file mode 100644
index 0000000..79e2e0d
--- /dev/null
+++ b/apps/forum/urls.py
@@ -0,0 +1,12 @@
+from django.urls import path
+
+from .views import (
+ TopicListView,
+)
+
+app_name = "forum"
+
+urlpatterns = [
+ path(r't/', TopicListView.as_view(), name='topic-list',),
+ path(r'', TopicListView.as_view(), name='topic-redirect',),
+]
diff --git a/apps/forum/views.py b/apps/forum/views.py
new file mode 100644
index 0000000..bc7cc74
--- /dev/null
+++ b/apps/forum/views.py
@@ -0,0 +1,19 @@
+from django.views.generic import CreateView, ListView, UpdateView, DeleteView
+from django.views.generic.detail import DetailView
+from django.views.generic.base import View, RedirectView
+from django.shortcuts import get_object_or_404, render, redirect
+from django.urls import reverse, reverse_lazy
+
+from rest_framework import viewsets
+from rest_framework.response import Response
+from rest_framework.decorators import list_route
+from rest_framework import permissions
+
+#from .serializers import NoteSerializer, NotebookSerializer
+from .models import Topic, Category, Post
+#from .forms import NoteForm, NotebookForm
+from utils.views import LoggedInViewWithUser
+
+
+class TopicListView(LoggedInViewWithUser, ListView):
+ model = Topic