diff --git a/.gitignore b/.gitignore index d75786a..9d94599 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,10 @@ coverage.xml *.log migrations/ +# node.js / npm +node_modules/ +npm-debug.log + # Sphinx documentation docs/_build/ @@ -62,3 +66,6 @@ target/ # SQLITE3 Test database db.* + +# Mac OS Env +.DS_Store diff --git a/apps/board/admin.py b/apps/board/admin.py index b6a7ab5..9b63b23 100644 --- a/apps/board/admin.py +++ b/apps/board/admin.py @@ -9,6 +9,3 @@ admin.site.register(Board) admin.site.register(BoardReport) admin.site.register(BoardCategory) -admin.site.register(BoardPostIs_read) -admin.site.register(BoardContentVoteAdult) -admin.site.register(BoardContentVotePolitical) diff --git a/apps/board/backend.py b/apps/board/backend.py deleted file mode 100644 index e1129df..0000000 --- a/apps/board/backend.py +++ /dev/null @@ -1,413 +0,0 @@ -# -*- coding: utf-8 -from apps.board.models import * -from django.core.exceptions import ObjectDoesNotExist -from django.utils import timezone - - -def _get_post_list(request, board_url='', item_per_page=15): - adult_filter = request.GET.get('adult_filter') - try: - page = int(request.GET['page']) - except: - page = 1 - if board_url != 'all': - try: - board = Board.objects.get(name=board_url) - except: - return ([], []) - post_count = 0 - if board_url == 'all': - board_post_notice = BoardPost.objects.filter( - is_notice=True).order_by('-id') - board_post = BoardPost.objects.all().order_by('-id') - post_count = BoardPost.objects.count() - else: - board_post_notice = BoardPost.objects.filter( - is_notice=True, board=board).order_by('-id') - board_post = BoardPost.objects.filter( - board=board).order_by('-id') - post_count = board_post.count() - if post_count == 0: - post_count = 1 - last_page = (post_count-1)/item_per_page+1 - if page < 1: - page = 1 - elif page > last_page: - page = last_page - board_post_notice = board_post_notice[:5] - board_post_all = board_post[ - (page*item_per_page-item_per_page):(page*item_per_page)] - post_list = [] - for board_post in board_post_notice: - post = {} - if board_post.is_notice: - if board_post.board_content.is_deleted: - continue - post['is_notice'] = True - if board_post.board_content.is_anonymous: - post['username'] = 'anonymous' - else: - post['username'] = board_post.author.user.username - post_board = {} - post_board['board_name'] = board_post.board.name - post_board['board_url'] = board_post.board.name - post['board'] = post_board - post['title'] = board_post.title - post['created_time'] = board_post.board_content.created_time - post['post_id'] = board_post.id - post['vote'] = board_post.board_content.get_vote() - post['comment_count'] = board_post.board_comment.count() - if adult_filter == 'true' and board_post.board_content.is_adult: - post['title'] = 'filtered' - try: - is_read = BoardPostIs_read.objects.get(board_post=board_post, - userprofile=request.user.userprofile) - if is_read.last_read > board_post.board_content.modified_time: - post['is_read'] = ' ' - else: - post['is_read'] = 'U' - except ObjectDoesNotExist: - post['is_read'] = 'N' - post_list.append(post) - for board_post in board_post_all: - post = {} - post['is_notice'] = False - if board_post.board_content.is_anonymous: - post['username'] = 'anonymous' - else: - post['username'] = board_post.author.user.username - post_board = {} - post_board['board_name'] = board_post.board.name - post_board['board_url'] = board_post.board.name - post['board'] = post_board - post['title'] = board_post.title - post['created_time'] = board_post.board_content.created_time - post['post_id'] = board_post.id - post['vote'] = board_post.board_content.get_vote() - post['comment_count'] = board_post.board_comment.count() - if adult_filter == 'true' and board_post.board_content.is_adult: - post['title'] = 'filtered' - if board_post.board_content.is_deleted: - post['title'] = '--Deleted--' - try: - is_read = BoardPostIs_read.objects.get(board_post=board_post, - userprofile=request.user.userprofile) - if is_read.last_read > board_post.board_content.modified_time: - post['is_read'] = ' ' - else: - post['is_read'] = 'U' - except ObjectDoesNotExist: - post['is_read'] = 'N' - post_list.append(post) - paginator = [] - if page > 10: - paging = {} - paging['page'] = 'prev' - paging['url'] = str((page-page % 10)) - paginator.append(paging) - for i in range(page-(page-1) % 10, page-(page-1) % 10+10): - if i > last_page: - break - paging = {} - paging['page'] = str(i) - paging['url'] = str(i) - paginator.append(paging) - if page < last_page-(last_page-1) % 10: - paging = {} - paging['page'] = 'next' - paging['url'] = str((page-(page-1) % 10+10)) - paginator.append(paging) - return (post_list, paginator) - - -def _get_board_list(): - board_model_list = Board.objects.all() - board_list = [] - for board_model in board_model_list: - board = {} - board['board_name'] = board_model.name - board['board_url'] = board_model.name - board['board_id'] = board_model.id - board_list.append(board) - return board_list - - -def _get_current_board(request, board_url): - board = {} - try: - board_model = Board.objects.get(name=board_url) - board['board_id'] = board_model.id - board['board_name'] = board_model.name - board['board_url'] = board_model.name - except: - board['board_id'] = 0 - board['board_name'] = 'All' - board['board_url'] = 'all' - return board - - -def _get_querystring(request): - querystring = '' - page = request.GET.get('page', '') - if page: - querystring += '?page='+page - return querystring - - -def _get_content(request, post_id): - try: - board_post = BoardPost.objects.get(id=post_id) - except ObjectDoesNotExist: - return ({}, []) - try: - board_post_is_read = BoardPostIs_read.objects.get( - board_post=board_post, - userprofile=request.user.userprofile) - except ObjectDoesNotExist: - board_post_is_read = BoardPostIs_read() - board_post_is_read.board_post = board_post - board_post_is_read.userprofile = request.user.userprofile - board_post_is_read.last_read = timezone.now() - board_post_is_read.save() - post = _get_post(request, board_post, 'Post') - comment_list = [] - for board_comment in board_post.board_comment.all(): - if not board_comment.original_comment == None: - continue - comment = _get_post(request, board_comment, 'Comment') - re_comment_list = [] - for board_re_comment in board_comment.re_comment.all(): - re_comment = _get_post(request, board_re_comment, 'Re-Comment') - re_comment_list.append(re_comment) - comment['re_comment_list'] = re_comment_list - comment_list.append(comment) - best_comment = {} - best_vote = 0 - for comment in comment_list: - if comment['vote']['up'] > 5 and comment['vote']['up'] > best_vote: - best_vote = comment['vote']['up'] - best_comment = comment - if best_comment: - best_comment['best_comment'] = True - comment_list.insert(0, best_comment) - return (post, comment_list) - - -def _get_post(request, board_post, type): - post = {} - if type == 'Comment' or type == 'Re-Comment': - pass - elif type == 'Post': - post['title'] = board_post.title - post['board'] = board_post.board.name - post['board_id'] = board_post.board.id - try: - post['category'] = board_post.board_category.name - except: - post['category'] = '' - else: - return post - userprofile = board_post.author - user = userprofile.user - board_content = board_post.board_content - if board_content.is_deleted: - post['title'] = '--Deleted--' - post['content'] = '--Deleted--' - else: - post['content'] = board_content.content - post['id'] = board_post.id - post['deleted'] = board_content.is_deleted - post['content_id'] = board_content.id - post['created_time'] = board_content.created_time - post['username'] = user.username - if board_content.is_anonymous: - post['username'] = 'anonymous' - post['return'] = (user.id == request.user.id) - post['vote'] = board_content.get_vote() - post['adult'] = board_content.is_adult - return post - - -def _write_post(request, is_post_or_comment, check=0, modify=False): - user_profile = request.user.userprofile - content = request.POST.get('content', '') - is_anonymous = request.POST.get('anonymous', False) - is_adult = request.POST.get('adult', False) - if modify: - try: - if is_post_or_comment == 'Post': - board_post_id = int(request.POST.get('board_post_id', 0)) - board_post = BoardPost.objects.get(id=board_post_id) - board_content = board_post.board_content - author = board_post.author - elif (is_post_or_comment == 'Comment' - or is_post_or_comment == 'Re-Comment'): - board_comment_id = int(request.POST.get('board_comment_id', 0)) - board_comment = BoardComment.objects.get(id=board_comment_id) - board_content = board_comment.board_content - author = board_comment.author - else: - return - except: - return - if author != user_profile: - return - if board_content.is_deleted: - return - else: - board_content = BoardContent() - if not content: - return - board_content.content = content - board_content.is_adult = bool(is_adult) - if not modify: - board_content.is_anonymous = bool(is_anonymous) - if is_post_or_comment == 'Post': - board = request.POST.get('board', 0) - is_notice = request.POST.get('notice', False) - category = request.POST.get('category', 0) - title = request.POST.get('title', '') - if modify: - board_post = board_content.board_post - else: - board_post = BoardPost() - try: - board_post.board = Board.objects.get(id=board) - except ObjectDoesNotExist: - return - try: - board_post.board_category = BoardCategory.objects.get( - name=category, - board=board_post.board) - except ObjectDoesNotExist: - pass - board_content.save() - board_post.board_content = board_content - board_post.is_notice = bool(is_notice) - board_post.author = user_profile - board_post.title = title - board_post.save() - return board_post.id - elif is_post_or_comment == 'Comment' or is_post_or_comment == 'Re-Comment': - if is_post_or_comment == 'Comment': - board_post_id = request.POST.get('board_post_id', 0) - if not check == board_post_id: - print 'not allowed' - return - else: - board_comment_id = request.POST.get('board_comment_id', 0) - board_post_id = request.POST.get('board_post_id', 0) - if modify: - try: - board_comment_id = request.POST.get('board_comment_id', 0) - board_comment = BoardComment.objects.get(id=board_comment_id) - except ObjectDoesNotExist: - return - else: - try: - if is_post_or_comment == 'Re-Comment': - original_comment = BoardComment.objects.get(id=board_comment_id) - if original_comment.board_content.is_deleted: - return - board_post = BoardPost.objects.get(id=board_post_id) - if board_post.board_content.is_deleted: - return - except ObjectDoesNotExist: - return - board_comment = BoardComment() - if is_post_or_comment == 'Re-Comment': - board_comment.original_comment = original_comment - board_comment.board_post = board_post - board_comment.author = user_profile - board_content.save() - board_comment.board_content = board_content - board_comment.save() - board_post.board_content.save() - return - else: - return - - -def _delete_post(request): - message = '' - board_content_id = request.POST.get('id', 0) - try: - board_content = BoardContent.objects.get(id=board_content_id) - except ObjectDoesNotExist: - return 'no post or comment' - if hasattr(board_content, 'board_post'): - author = board_content.board_post.author - elif hasattr(board_content, 'board_comment'): - author = board_content.board_comment.author - else: - return 'invalid content' - if author != request.user.userprofile: - return 'not allowed' - board_content.is_deleted = True - board_content.save() - return 'success' - - -def _report(request): - content_id = request.POST.get('id', 0) - report_reason = request.POST.get('report_reason', '') - report_content = request.POST.get('report_content', '') - if report_reason == '' or report_reason == '0': - return 'no reason' - try: - board_content = BoardContent.objects.get(id=content_id) - except ObjectDoesNotExist: - return 'no content' - board_report = BoardReport() - board_report.reason = report_reason - board_report.content = report_content - board_report.board_content = board_content - board_report.userprofile = request.user.userprofile - board_report.save() - return 'success' - - -def _vote(request): - user_profile = request.user.userprofile - vote_type = request.POST.get('vote_type', '') - content_id = request.POST.get('vote_id', '') - try: - board_content = BoardContent.objects.get(id=content_id) - if vote_type == 'up' or vote_type == 'down': - is_up_or_down = (False, True)[vote_type == 'up'] - try: - content_vote = BoardContentVote.objects.get( - board_content=board_content, - userprofile=user_profile) - if content_vote.is_up == is_up_or_down: - content_vote.delete() - return {'success': vote_type + ' canceled', 'vote': board_content.get_vote()} - else: - content_vote.is_up = is_up_or_down - content_vote.save() - return {'success': 'changed to ' + vote_type, 'vote': board_content.get_vote()} - except: - vote = BoardContentVote() - vote.is_up = is_up_or_down - elif vote_type == 'adult': - if BoardContentVoteAdult.objects.filter( - board_content=board_content, - userprofile=user_profile): - return {'success': 'Already voted' + vote_type, 'vote': board_content.get_vote()} - else: - vote = BoardContentVoteAdult() - elif vote_type == 'political': - if BoardContentVotePolitical.objects.filter( - board_content=board_content, - userprofile=user_profile): - return {'success': 'Already voted ' + vote_type, 'vote': board_content.get_vote()} - else: - vote = BoardContentVotePolitical() - else: - return {'fail': 'Wrong request'} - vote.board_content = board_content - vote.userprofile = user_profile - vote.save() - return {'success': 'vote ' + vote_type, 'vote': board_content.get_vote()} - except ObjectDoesNotExist: - return {'fail': 'Unvalid ontent id'} diff --git a/apps/board/models.py b/apps/board/models.py index 9403350..2ccbf35 100644 --- a/apps/board/models.py +++ b/apps/board/models.py @@ -4,8 +4,7 @@ class BoardContent(models.Model): content = models.TextField(null=False) - created_time = models.DateTimeField(auto_now_add=True) - modified_time = models.DateTimeField(auto_now=True) + created_time = models.DateTimeField(null=False) is_deleted = models.BooleanField(default=False, null=False) is_anonymous = models.BooleanField(default=False, null=False) is_adult = models.BooleanField(default=False, null=False) @@ -23,7 +22,7 @@ def __str__(self): def get_vote(self): up = 0 down = 0 - for content_vote in self.board_content_vote.all(): + for content_vote in self.content_vote.all(): if content_vote.is_up: up = up+1 else: @@ -43,17 +42,13 @@ class Attachment(models.Model): class BoardComment(models.Model): board_content = models.OneToOneField('BoardContent', - related_name="board_comment", + related_name="comment", null=False) board_post = models.ForeignKey('BoardPost', - related_name="board_comment", - null=True) + related_name="comment", + null=False) author = models.ForeignKey('session.UserProfile', related_name="board_comment") - original_comment = models.ForeignKey('BoardComment', - related_name='re_comment', - null=True, - blank=True) def __str__(self): created_time = self.board_content.created_time @@ -63,35 +58,35 @@ def __str__(self): class BoardContentVote(models.Model): board_content = models.ForeignKey('BoardContent', - related_name="board_content_vote", + related_name="content_vote", null=False) userprofile = models.ForeignKey('session.UserProfile', - related_name="board_content_vote") + related_name="board_comment_vote") is_up = models.BooleanField(null=False) class BoardContentVoteAdult(models.Model): board_content = models.ForeignKey('BoardContent', - related_name="board_content_vote_adult", + related_name="content_vote_adult", null=False) userprofile = models.ForeignKey('session.UserProfile', - related_name="board_content_vote_adult") + related_name="board_comment_vote_adult") class BoardContentVotePolitical(models.Model): board_content = models.ForeignKey('BoardContent', - related_name="board_content_vote_political", + related_name="content_vote_political", null=False) userprofile = models.ForeignKey('session.UserProfile', - related_name="board_content_vote_political") + related_name="board_comment_vote_political") class BoardReport(models.Model): reason = models.TextField(null=False) - content = models.TextField(default='Write something') - created_time = models.DateTimeField(auto_now_add=True) + content = models.TextField() + created_time = models.DateTimeField(null=False) board_content = models.ForeignKey('BoardContent', - related_name="board_report", + related_name="report", null=False) userprofile = models.ForeignKey('session.UserProfile', related_name="board_report") @@ -100,6 +95,7 @@ class BoardReport(models.Model): class Board(models.Model): name = models.CharField(max_length=45, null=False) description = models.CharField(max_length=100, null=False) + post_count = models.IntegerField(default=0) def __str__(self): return "board %s" % self.name @@ -107,43 +103,24 @@ def __str__(self): class BoardCategory(models.Model): name = models.CharField(max_length=10, null=False) - board = models.ForeignKey('Board', - related_name='board_category', - null=False) + board = models.ForeignKey('Board', related_name='category', null=False) class BoardPost(models.Model): title = models.CharField(max_length=45, null=False) is_notice = models.BooleanField(default=False, null=False, db_index=True) - board = models.ForeignKey('Board', - related_name='board', - null=False, - db_index=True) + board = models.ForeignKey('Board', related_name='board', null=False, db_index=True) author = models.ForeignKey('session.UserProfile', related_name='board_post') - board_content = models.OneToOneField('BoardContent', null=False, - related_name='board_post') + board_content = models.OneToOneField('BoardContent', null=False) board_category = models.ForeignKey('BoardCategory', - related_name='board_post', - null=True, - blank=True) + related_name='category', + null=False) - - def __unicode__(self): + def __str__(self): title = self.title created_time = self.board_content.created_time author = self.author.user return "title: %s created in %s, authored by %s" % (title, created_time, author) - - -class BoardPostIs_read(models.Model): - userprofile = models.ForeignKey('session.UserProfile', - related_name='board_post_is_read') - board_post = models.ForeignKey('BoardPost', - related_name='board_post_is_read') - last_read = models.DateTimeField(auto_now=True) - - class Meta: - unique_together = ('userprofile', 'board_post',) diff --git a/apps/board/urls.py b/apps/board/urls.py index 0845e22..d324d49 100644 --- a/apps/board/urls.py +++ b/apps/board/urls.py @@ -16,15 +16,16 @@ from django.conf.urls import include, url urlpatterns = [ - url(r'^$', 'apps.board.views.home'), - url(r'^([A-z]*)/$', 'apps.board.views.post_list', name='post_list'), - url(r'^([A-z]*)/post/$', 'apps.board.views.post_write'), - url(r'^([A-z]*)/([1-9][0-9]*)/$', 'apps.board.views.post_read'), - url(r'^([A-z]*)/([1-9][0-9]*)/modify/$', 'apps.board.views.post_modify'), - url(r'^[A-z]*/([1-9][0-9]*)/comment/$', 'apps.board.views.comment_write'), - url(r'^[A-z]*/([1-9][0-9]*)/comment_mod/$', 'apps.board.views.comment_modify'), - url(r'^[A-z]*/[1-9][0-9]*/re_comment/$', 'apps.board.views.re_comment_write'), - url(r'^[A-z]*/[1-9][0-9]*/delete/$','apps.board.views.delete'), - url(r'^[A-z]*/[1-9][0-9]*/vote/$', 'apps.board.views.content_vote'), - url(r'^[A-z]*/[1-9][0-9]*/report/$', 'apps.board.views.report'), + url(r'^$', 'apps.board.views.post_list'), + url(r'^post/$', 'apps.board.views.post_write'), + url(r'^([1-9][0-9]*)/$', 'apps.board.views.post_read'), + url(r'^([1-9][0-9]*)/modify/$', 'apps.board.views.post_modify'), + url(r'^([1-9][0-9]*)/comment/$', 'apps.board.views.comment_write'), + url(r'^[1-9][0-9]*/comment_mod/$', 'apps.board.views.comment_modify'), + url(r'^up/$', 'apps.board.views.up'), + url(r'^down/$', 'apps.board.views.down'), + url(r'^delete/$','apps.board.views.delete'), + url(r'^vote_adult/$', 'apps.board.views.vote_adult'), + url(r'^vote_political/$', 'apps.board.views.vote_political'), + url(r'^report/$', 'apps.board.views.report'), ] diff --git a/apps/board/views.py b/apps/board/views.py index 7dc4c1c..2f8a676 100644 --- a/apps/board/views.py +++ b/apps/board/views.py @@ -1,166 +1,678 @@ # -*- coding: utf-8 from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required +from django.contrib.auth import authenticate +from django.contrib.auth.models import User +from django.core.paginator import Paginator from django.http import HttpResponse from apps.board.models import * -from apps.board.backend import _get_post_list, _get_board_list -from apps.board.backend import _get_querystring, _get_content -from apps.board.backend import _write_post, _get_current_board -from apps.board.backend import _delete_post, _report, _vote -from django.utils import timezone +import datetime import json - -def home(request): - return redirect('all/') - +ItemPerPage=15 @login_required(login_url='/session/login') -def post_write(request, board_url): +def post_write(request): post = {} - post['new'] = True + post["new"] = True + error = "" if request.method == 'POST': - post_id = _write_post(request, 'Post') - if post_id: - # board_id = BoardPost.objects.filter(id=post_id)[0].board.id - return redirect('../' + str(post_id)) + _User = request.user + _UserProfile = _User.userprofile + board = request.POST.get('board', '') + post["title"] = request.POST.get('title', '') + post["content"] = request.POST.get('content', '') + category = request.POST.get('category', '') + anonymous = request.POST.get('anonymous', '') + adult = request.POST.get('adult', '') + notice = request.POST.get('notice', '') + if post["title"] == '': + error = 'title missing!' + if post["content"] == '': + error = 'content missing!' + if error: + Cur_board = Board.objects.filter(id=board)[0] + _Board = Board.objects.all() + # official=request.user.userprofile.is_official + boards = [] + for bd in _Board: + board = {} + board['name'] = bd.name + board['id'] = bd.id + board['description'] = bd.description + boards.append(board) + categories = BoardCategory.objects.all() + return render(request, + 'board/board_write.html', + {"post": post, "Boards": boards, + "Cur_board": Cur_board, "error": error, + "Categories": categories}) + _BoardContent = BoardContent() + _BoardContent.content = post["content"] + _BoardContent.created_time = datetime.datetime.today() + if anonymous == 'on': + _BoardContent.is_anonymous = True + if adult == 'on': + _BoardContent.is_adult = True + _BoardContent.save() + _BoardPost = BoardPost() + _BoardPost.title = post["title"] + if notice == 'on': + _BoardPost.is_notice = True + _BoardPost.board_content = _BoardContent + _BoardPost.board_content_id = _BoardContent.id + _BoardPost.author = _UserProfile + _BoardPost.author_id = _UserProfile.id + _Board = Board.objects.filter(id=board) + if _Board: + _BoardPost.board = _Board[0] else: return redirect('../') - current_board = _get_current_board(request, board_url) + _Category = BoardCategory.objects.filter(name=category) + if _Category: + _BoardPost.board_category = _Category[0] + else: + return redirect('../') + _BoardPost.save() + _Board[0].post_count += 1 + _Board[0].save() + postID = str(_BoardPost.id) + return redirect('../'+postID+'/?board='+board) + cur_board = request.GET.get("board") + if cur_board: + Cur_board = Board.objects.filter(id=cur_board)[0] + else: + Cur_board = Board.objects.filter(id=1)[0] + _Board = Board.objects.all() # official=request.user.userprofile.is_official - board_list = _get_board_list() + boards = [] + for bd in _Board: + board = {} + board['name'] = bd.name + board['id'] = bd.id + board['description'] = bd.description + boards.append(board) categories = BoardCategory.objects.all() return render(request, 'board/board_write.html', - {"post": post, "board_list": board_list, - "current_board": current_board, + {"post": post, "Boards": boards, + "Cur_board": Cur_board, "Categories": categories}) - + @login_required(login_url='/session/login') -def post_read(request, board_url, post_id): - get_content = _get_content(request, post_id) - post = get_content[0] - comment_list = get_content[1] - get_post_list = _get_post_list(request, board_url) - post_list = get_post_list[0] - paginator = get_post_list[1] - board_list = _get_board_list() - querystring = _get_querystring(request) - current_board = _get_current_board(request, board_url) +def post_read(request, pid, error=''): + _BoardPost = BoardPost.objects.filter(id=pid) + if _BoardPost: + _BoardPost = _BoardPost[0] + else: + error = "No post" + return render(request, 'board/board_read.html', {'error': error}) + _BoardContent = _BoardPost.board_content + _UserProfile = _BoardPost.author + _User = _UserProfile.user + post = {} + if _BoardContent.is_deleted: + post["title"] = "--Deleted--" + post["content"] = "--Deleted--" + post["deleted"] = True + else: + post["title"] = _BoardPost.title + content = _BoardContent.content + content = content.replace('<', '<') + content = content.replace('>', '>') + content = content.replace('\n', '
') + post["content"] = content + post["deleted"] = False + post["content_id"] = _BoardContent.id + post["created_time"] = _BoardContent.created_time + post["username"] = _User.username + post["board"] = _BoardPost.board.name + post["board_id"] = _BoardPost.board.id + post["category"] = _BoardPost.board_category.name + if _BoardContent.is_anonymous: + post["username"] = 'anonymous' + writing_id = _UserProfile.id + reading_id = request.user.userprofile.id + post["return"] = (writing_id == reading_id) + post["vote"] = _BoardContent.get_vote() + post["adult"] = _BoardContent.is_adult + comments = [] + for cm in _BoardPost.comment.all(): + _BoardContent = cm.board_content + _UserProfile = cm.author + _User = _UserProfile.user + comment = {} + comment["username"] = _User.username + if _BoardContent.is_deleted: + comment["title"] = "--Deleted--" + comment["content"] = "--Deleted--" + comment["deleted"] = True + else: + comment["title"] = _BoardPost.title + content = _BoardContent.content + content = content.replace('<', '<') + content = content.replace('>', '>') + content = content.replace('\n', '
') + comment["content"] = content + comment["deleted"] = False + comment["comment_id"] = cm.id + comment["content_id"] = _BoardContent.id + comment["created_time"] = _BoardContent.created_time + comment["return"] = (_UserProfile.id + == request.user.userprofile.id) + if _BoardContent.is_anonymous: + comment["username"] = 'anonymous' + comment["return"] = (_UserProfile.id == reading_id) + comment["vote"] = _BoardContent.get_vote() + comments.append(comment) + adult_filter = request.GET.get('adult_filter') + board_filter = request.GET.get('board') + cur_board = "" + is_adult = False + if adult_filter == "true": + is_adult = True + if board_filter: + _NoticeBoardPost = BoardPost.objects.filter(board=board_filter, is_notice=True).order_by('-id') + _BoardPostIn = BoardPost.objects.filter(board=board_filter, is_notice=False).order_by('-id') + cur_board = Board.objects.filter(id=board_filter)[0] + else: + _NoticeBoardPost = BoardPost.objects.filter(is_notice=True).order_by('-id') + _BoardPostIn = BoardPost.objects.filter(is_notice=False).order_by('-id') + _Board = Board.objects.all() + paginator = Paginator(_BoardPostIn, ItemPerPage) + try: + page = int(request.GET['page']) + except: + page = 1 + _PageBoardPost = paginator.page(page) + posts = [] + boards = [] + for bd in _Board: + boards.append(bd) + for nbp in _NoticeBoardPost: + if nbp.board_content.is_deleted: + continue + npost = {} + npost = {} + if nbp.board_content.is_anonymous: + npost['username'] = "annonymous" + else: + npost['username'] = nbp.author.user.username + npost['board'] = nbp.board.name + if nbp.board_content.is_deleted: + npost['title'] = "--Deleted--" + else: + npost['title'] = nbp.title + npost['created_time'] = nbp.board_content.created_time + npost['id'] = nbp.id + npost['board_id'] = nbp.board.id + nvote = nbp.board_content.get_vote() + npost['up'] = nvote['up'] + npost['down'] = nvote['down'] + npost['is_notice'] = True + posts.append(npost) + for bp in _PageBoardPost: + postInList = {} # post for postList + if bp.board_content.is_anonymous: + postInList['username'] = "annonymous" + else: + postInList['username'] = bp.author.user.username + postInList['board'] = bp.board.name + if bp.board_content.is_deleted: + postInList['title'] = "--Deleted--" + else: + postInList['title'] = bp.title + postInList['created_time'] = bp.board_content.created_time + postInList['id'] = bp.id + postInList['board_id'] = bp.board.id + voteIn = bp.board_content.get_vote() + postInList['up'] = voteIn['up'] + postInList['down'] = voteIn['down'] + if adult_filter == 'true' and bp.board_content.is_adult: + postInList['title'] = "filterd" + posts.append(postInList) + if page == 1: + prevPage = 0 + else: + prevPage = paginator.page(page).previous_page_number() + if page == paginator.num_pages: + nextPage = page + else: + nextPage = paginator.page(page).next_page_number() return render(request, 'board/board_read.html', { - 'querystring': querystring, + 'error': error, # error for post 'post': post, # post for post - 'comment_list': comment_list, # comment for post - # Below,there are thing for postList. - 'post_list': post_list, - 'board_list': board_list, - 'current_board': current_board, - 'paginator': paginator, + 'comments': comments, # comment for post + 'Posts': posts, # Below,there are thing for postList. + 'Boards': boards, + 'Cur_board': cur_board, + 'Is_adult': is_adult, + 'show_paginator': paginator.num_pages > 1, + 'has_prev': paginator.page(page).has_previous(), + 'has_next': paginator.page(page).has_next(), + 'page': page, + 'pages': paginator.num_pages, + 'next_page': nextPage, + 'prev_page': prevPage, }) @login_required(login_url='/session/login') -def post_modify(request, board_url, post_id): - try: - board_post = BoardPost.objects.filter(id=post_id)[0] - if request.user.userprofile != board_post.author: - return - except: - return +def post_modify(request, pid): + post = {} + post["new"] = False + error = "" + _User = request.user + _BoardPost = BoardPost.objects.filter(id=pid) + if _BoardPost: + _BoardPost = _BoardPost[0] + if _BoardPost.author != _User.userprofile: + error = "Not allowed" + else: + error = "No post" + _BoardContent = _BoardPost.board_content + if _BoardContent.is_deleted: + error = "Deleted" + if error: + return redirect('../') if request.method == 'POST': - post_id = _write_post(request, 'Post', modify=True) - if post_id: - querystring = _get_querystring(request) - return redirect('../'+querystring) + if not request.user.is_authenticated(): + return redirect('session/login') + _User = request.user + post["title"] = request.POST.get('title', '') + post["content"] = request.POST.get('content', '') + post["board"] = request.POST.get('board', '') + post["category"] = request.POST.get('category', '') + adult = request.POST.get('adult', '') + if post["title"] == '': + error = 'title missing!' + if post["content"] == '': + error = 'body missing!' + if error: + return render(request, + 'board/board_write.html', + {"error": error, "post": post}) + if adult: + _BoardContent.is_adult = True + else: + _BoardContent.is_adult = False + _BoardContent.content = post["content"] + _BoardContent.save() + _BoardPost.title = post["title"] + _Board = Board.objects.filter(id=post["board"]) + _Category = BoardCategory.objects.filter(name=post["category"]) + if not _Board: + return redirect('../') + elif not _Category: + return redirect('../') + else: + _BoardPost.board = _Board[0] + _BoardPost.board_category = _Category[0] + _BoardPost.save() return redirect('../') - post = _get_content(request, post_id)[0] - post['new'] = False - current_board = _get_current_board(request, board_url) - board_list = _get_board_list() + post["title"] = _BoardPost.title + post["content"] = _BoardContent.content + cur_board = request.GET.get("board", '') + if cur_board: + Cur_board = Board.objects.filter(id=cur_board)[0] + else: + Cur_board = Board.objects.filter(id=1)[0] + _Board = Board.objects.all() # official=request.user.userprofile.is_official + boards = [] + for bd in _Board: + board = {} + board['name'] = bd.name + board['id'] = bd.id + board['description'] = bd.description + boards.append(board) categories = BoardCategory.objects.all() return render(request, 'board/board_write.html', - {"post": post, "board_list": board_list, - "current_board": current_board, + {"post": post, "Boards": boards, + "Cur_board": Cur_board, "Categories": categories}) - -@login_required(login_url='/session/login') -def comment_write(request, post_id_check): - if request.method == 'POST': - post_id = _write_post(request, 'Comment', post_id_check) - querystring = _get_querystring(request) - return redirect('../'+querystring) + return render(request, + 'board/board_write.html', + {"post": post}) @login_required(login_url='/session/login') -def comment_modify(request, post_id_check): +def comment_write(request, pid, error=''): + _User = request.user + _BoardPost = BoardPost.objects.filter(id=pid) + if _BoardPost: + _BoardPost = _BoardPost[0] + else: + error = "No post" + if error: + return redirect('../') if request.method == 'POST': - post_id = _write_post(request, 'Comment', post_id_check, True) - querystring = _get_querystring(request) - return redirect('../'+querystring) + if not request.user.is_authenticated(): + return redirect('session/login') + _User = request.user + _UserProfile = _User.userprofile + + content = request.POST.get('content', '') + anonymous = request.POST.get('anonymous', '') + if content == '': + error = 'content missing!' + if error: + return redirect('../') + _BoardContent = BoardContent() + _BoardContent.content = content + _BoardContent.created_time = datetime.datetime.today() + if anonymous == 'on': + _BoardContent.is_anonymous = True + _BoardContent.save() + _BoardComment = BoardComment() + _BoardComment.board_content = _BoardContent + _BoardComment.board_post = _BoardPost + _BoardComment.author = _UserProfile + _BoardComment.save() + return redirect('../') + return redirect('../') @login_required(login_url='/session/login') -def re_comment_write(request): - if request.method == 'POST': - post_id = _write_post(request, 'Re-Comment') - querystring = _get_querystring(request) - return redirect('../'+querystring) +def comment_modify(request, error=''): + if request.method == "POST": + _User = request.user + cid = request.POST.get('cid', '') + _BoardComment = BoardComment.objects.filter(id=cid) + if _BoardComment: + _BoardComment = _BoardComment[0] + if _BoardComment.author != _User.userprofile: + error = "Not allowd" + else: + error = "No Comment" + if error: + return redirect('../') + _BoardContent = _BoardComment.board_content + content = request.POST.get('content', '') + if content == '': + error = 'No comment content' + if error: + return redirect('../') + _BoardContent.content = content + _BoardContent.save() + return redirect('../') + error = "Invalid access" + return redirect('../') @login_required(login_url='/session/login') -def post_list(request, board_url): - get_post_list = _get_post_list(request, board_url) - post_list = get_post_list[0] - paginator = get_post_list[1] - board_list = _get_board_list() - querystring = _get_querystring(request) - current_board = _get_current_board(request, board_url) +def post_list(request, error=''): adult_filter = request.GET.get('adult_filter') + board_filter = request.GET.get('board') + cur_board = "" is_adult = False if adult_filter == "true": is_adult = True + if board_filter: + _NoticeBoardPost = BoardPost.objects.filter(board=board_filter, is_notice=True).order_by('-id') + _BoardPost = BoardPost.objects.filter(board=board_filter).order_by('-id') + cur_board = Board.objects.filter(id=board_filter)[0] + post_count = cur_board.post_count + else: + _NoticeBoardPost = BoardPost.objects.filter(is_notice=True).order_by('-id') + _BoardPost = BoardPost.objects.all().order_by('-id') + if _BoardPost: + post_count = _BoardPost[0].id + else: + post_count = 0 + if post_count < 1: + post_count = 1 + _Board = Board.objects.all() + # paginator = Paginator(_BoardPost, ItemPerPage) + try: + page = int(request.GET['page']) + except: + page = 1 + if page < 1: + page = 1 + if page > (post_count-1)/ItemPerPage+1: + page = (post_count-1)/ItemPerPage+1 + _NoticeBoardPost = _NoticeBoardPost[:5] + _PageBoardPost = _BoardPost[page*ItemPerPage-ItemPerPage:page*ItemPerPage] + # _PageBoardPost = paginator.page(page) + posts = [] + boards = [] + for bd in _Board[:]: + boards.append(bd) + for nbp in _NoticeBoardPost.iterator(): + if nbp.board_content.is_deleted: + continue + npost = {} + if nbp.board_content.is_anonymous: + npost['username'] = "annonymous" + else: + npost['username'] = nbp.author.user.username + npost['board'] = nbp.board.name + npost['title'] = nbp.title + npost['created_time'] = nbp.board_content.created_time + npost['id'] = nbp.id + npost['board_id'] = nbp.board.id + nvote = nbp.board_content.get_vote() + npost['up'] = nvote['up'] + npost['down'] = nvote['down'] + npost['is_notice'] = True + posts.append(npost) + for bp in _PageBoardPost.iterator(): + post = {} + if bp.board_content.is_anonymous: + post['username'] = "annonymous" + else: + post['username'] = bp.author.user.username + post['board'] = bp.board.name + if bp.board_content.is_deleted: + post['title'] = "--Deleted--" + else: + post['title'] = bp.title + post['created_time'] = bp.board_content.created_time + post['id'] = bp.id + post['board_id'] = bp.board.id + vote = bp.board_content.get_vote() + post['up'] = vote['up'] + post['down'] = vote['down'] + if adult_filter == 'true' and bp.board_content.is_adult: + post['title'] = "filterd" + posts.append(post) + if page == 1: + prevPage = page + else: + # prevPage = paginator.page(page).previous_page_number() + prevPage = page-1 + if page == (post_count-1)/ItemPerPage+1: + nextPage = page + else: + # nextPage = paginator.page(page).next_page_number() + nextPage = page+1 return render(request, 'board/board_list.html', { - 'post_list': post_list, - 'board_list': board_list, - 'current_board': current_board, - 'is_adult': is_adult, - 'querystring': querystring, - 'paginator': paginator, + 'Posts': posts, + 'Boards': boards, + 'Cur_board': cur_board, + 'Is_adult': is_adult, + 'show_paginator': ((post_count-1)/ItemPerPage > 1), + 'has_prev': (prevPage != page), + 'has_next': (nextPage != page), + 'page': page, + 'pages': (post_count-1)/ItemPerPage+1, + 'next_page': nextPage, + 'prev_page': prevPage, + }) @login_required(login_url='/session/login') -def content_vote(request): +def up(request): + message = "" + id = request.GET.get('id') + _BoardContent = BoardContent.objects.filter(id=id) + if _BoardContent: + _BoardContent = _BoardContent[0] + _BoardContentVote = BoardContentVote.objects.filter( + board_content=_BoardContent, + userprofile=request.user.userprofile) + if _BoardContentVote: + vote = _BoardContentVote[0] + if vote.is_up: + vote.delete() + message = "success_up_cancle" + else: + vote.is_up = True + vote.save() + message = "success_up" + else: + vote = BoardContentVote() + vote.is_up = True + vote.userprofile = request.user.userprofile + vote.board_content = _BoardContent + vote.save() + message = "success_up" + else: + message = "fail" result = {} - result['response'] = 'fail' - if request.method == 'POST': - vote_result = _vote(request) - if 'success' in vote_result: - result['response'] = 'success' - result['message'] = vote_result['success'] - result['vote'] = vote_result['vote'] + result['message'] = message + result['vote'] = _BoardContent.get_vote() + return HttpResponse(json.dumps(result), content_type="application/json") + + +@login_required(login_url='/session/login') +def down(request): + message = "" + id = request.GET.get('id') + _BoardContent = BoardContent.objects.filter(id=id) + if _BoardContent: + _BoardContent = _BoardContent[0] + _BoardContentVote = BoardContentVote.objects.filter( + board_content=_BoardContent, + userprofile=request.user.userprofile) + if _BoardContentVote: + vote = _BoardContentVote[0] + if not vote.is_up: + vote.delete() + message = "success_down_cancle" + else: + vote.is_up = False + vote.save() + message = "success_down" + else: + vote = BoardContentVote() + vote.is_up = False + vote.userprofile = request.user.userprofile + vote.board_content = _BoardContent + vote.save() + message = "success_down" + else: + message = "fail" + result = {} + result['message'] = message + result['vote'] = _BoardContent.get_vote() + return HttpResponse(json.dumps(result), content_type="application/json") + + +@login_required(login_url='/session/login') +def vote_adult(request): + message = "" + id = request.GET.get('id') + _BoardContent = BoardContent.objects.filter(id=id) + if _BoardContent: + _BoardContent = _BoardContent[0] + _BoardContentVoteAdult = BoardContentVoteAdult.objects.filter( + board_content=_BoardContent, + userprofile=request.user.userprofile) + if _BoardContentVoteAdult: + message = "already voted_adult" + else: + vote = BoardContentVoteAdult() + vote.userprofile = request.user.userprofile + vote.board_content = _BoardContent + vote.save() + message = "success" + else: + message = "content not exist" + result = {} + result['message'] = message + return HttpResponse(json.dumps(result), content_type="application/json") + + +@login_required(login_url='/session/login') +def vote_political(request): + message = "" + id = request.GET.get('id') + _BoardContent = BoardContent.objects.filter(id=id) + if _BoardContent: + _BoardContent = _BoardContent[0] + _BoardContentVotePolitical = BoardContentVotePolitical.objects.filter( + board_content=_BoardContent, + userprofile=request.user.userprofile) + if _BoardContentVotePolitical: + message = "already voted_political" + else: + vote = BoardContentVotePolitical() + vote.userprofile = request.user.userprofile + vote.board_content = _BoardContent + vote.save() + message = "success" + else: + message = "content not exist" + result = {} + result['message'] = message return HttpResponse(json.dumps(result), content_type="application/json") @login_required(login_url='/session/login') def delete(request): - message = 'invalid access' - if request.method == 'POST': - message = _delete_post(request) + message = "" + cid = request.GET.get('id') + _BoardContents = BoardContent.objects.filter(id=cid) + if _BoardContents: + BoardCont = _BoardContents[0] + if hasattr(BoardCont, 'boardpost'): + author = BoardCont.boardpost.author + elif hasattr(BoardCont, 'comment'): + author = BoardCont.comment.author + else: + message = "no post or comment" + return HttpResponse(message) + if author == request.user.userprofile: + BoardCont.is_deleted = True + BoardCont.save() + message = "success" + else: + message = "not allowed" + else: + message = "no content" return HttpResponse(message) @login_required(login_url='/session/login') def report(request): - message = 'invalid access' if request.method == 'POST': - message = _report(request) - return HttpResponse(message) + cid = request.POST.get('id', '') + reason = request.POST.get('report_reason', '') + content = request.POST.get('report_content', '') + if reason == '' or reason == '0': + message = 'no reason' + else: + board_content = BoardContent.objects.filter(id=cid) + if board_content: + board_content = board_content[0] + board_report = BoardReport() + board_report.reason = reason + board_report.content = content + board_report.board_content = board_content + board_report.created_time = datetime.datetime.today() + board_report.userprofile = request.user.userprofile + board_report.save() + message = 'success' + else: + message = 'no content' + return HttpResponse(message) diff --git a/apps/session/admin.py b/apps/session/admin.py index 371ad70..70b7982 100644 --- a/apps/session/admin.py +++ b/apps/session/admin.py @@ -1,4 +1,16 @@ from django.contrib import admin +from apps.session.models import UserProfile, Message + + +class UserProfileAdmin(admin.ModelAdmin): + list_display = ('user', 'nickname', 'points') + + +class MessageAdmin(admin.ModelAdmin): + list_display = ('content', 'sender', 'receiver') + +admin.site.register(UserProfile, UserProfileAdmin) +admin.site.register(Message, MessageAdmin) from apps.session.models import * # Register your models here. diff --git a/apps/session/models.py b/apps/session/models.py index cbc8620..98be519 100644 --- a/apps/session/models.py +++ b/apps/session/models.py @@ -3,19 +3,22 @@ class UserProfile(models.Model): - user = models.OneToOneField(User, related_name='userprofile') + user = models.OneToOneField(User) + nickname = models.TextField(max_length=12) points = models.IntegerField(default=0) def __str__(self): - return "User %s's profile object" % self.user + return "User %s (%s)'s profile object" % (self.user, self.nickname) class Message(models.Model): content = models.TextField() sender = models.ForeignKey('UserProfile', related_name='message_sent') - receiver = models.ForeignKey('UserProfile', related_name='message_received') + receiver = models.ForeignKey('UserProfile', + related_name='message_received') created_time = models.DateTimeField(auto_now=True) + is_read = models.BooleanField() def __str__(self): return "Message from %s to %s at %s" % \ - (sender, receiver, created_time) + (self.sender, self.receiver, self.created_time) diff --git a/apps/session/urls.py b/apps/session/urls.py index a00fa80..cf9c36a 100644 --- a/apps/session/urls.py +++ b/apps/session/urls.py @@ -13,8 +13,13 @@ 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ -from django.conf.urls import include, url -from django.contrib import admin +from django.conf.urls import url + urlpatterns = [ + url(r'^login/', 'apps.session.views.user_login'), + url(r'^logout/', 'apps.session.views.user_logout'), + url(r'^register/', 'apps.session.views.user_register'), + url(r'^message/', 'apps.session.views.send_message'), + url(r'^checkmessage/', 'apps.session.views.check_message') ] diff --git a/apps/session/views.py b/apps/session/views.py index 91ea44a..0a588e3 100644 --- a/apps/session/views.py +++ b/apps/session/views.py @@ -1,3 +1,84 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect +from django.contrib.auth import authenticate, login, logout +from django.contrib.auth.models import User +from apps.session.models import UserProfile, Message +from django.contrib.auth.decorators import login_required -# Create your views here. + +def user_login(request): + if request.method == 'POST': + username = request.POST['username'] + password = request.POST['password'] + user = authenticate(username=username, password=password) + + if user is not None and user.is_active: + login(request, user) + return redirect(request.POST['next']) + else: + error = "Invalid login" + return render(request, 'session/login.html', {'error': error}) + return render(request, 'session/login.html', + {'next': request.GET.get('next', '/')}) + + +def user_logout(request): + if request.user.is_authenticated(): + logout(request) + return redirect('/session/login') + + +def user_register(request): + if request.method == "POST": + username = request.POST['username'] + password = request.POST['password'] + if password != request.POST['password_confirmation']: + error = "Password doesn't match the confirmation" + return render(request, "session/register.html", {'error': error}) + email = request.POST['email'] + first_name = request.POST['first_name'] + last_name = request.POST['last_name'] + new_user = User.objects.create_user(username=username, + email=email, + password=password, + first_name=first_name, + last_name=last_name) + nickname = request.POST['nickname'] + new_user_profile = UserProfile(user=new_user, + nickname=nickname) + new_user_profile.save() + + return render(request, 'session/register_complete.html') + return render(request, 'session/register.html') + + +@login_required(login_url='/session/login/') +def send_message(request): + if request.method == "POST": + if request.user.is_authenticated(): + sender = UserProfile.objects.get(user=request.user) + else: + error = "Login required" + return render(request, + 'session/write_message.html', {'error': error}) + content = request.POST['content'] + receiver = UserProfile.objects.get(nickname=request.POST['nickname']) + new_message = Message(content=content, + sender=sender, + receiver=receiver, + is_read=False) + new_message.save() + + return render(request, 'session/message_success.html') + return render(request, 'session/write_message.html') + + +@login_required(login_url='/session/login/') +def check_message(request): + if request.user.is_authenticated(): + sender = UserProfile.objects.get(user=request.user) + else: + error = "Login required" + return render(request, 'session/check_message.html', {'error': error}) + messages = Message.objects.filter(receiver=sender) + return render(request, + 'session/check_message.html', {'messages': messages}) diff --git a/templates/base.html b/templates/base.html index 4281a97..29eaf10 100644 --- a/templates/base.html +++ b/templates/base.html @@ -11,6 +11,13 @@ {% block js %}{% endblock %} + {% if user.is_authenticated %} +
  • Hello, {{ user }}
  • +
  • Logout
  • + {% else %} +
  • Login
  • +
  • Join Araplus!
  • + {% endif %} {% block content %} {% endblock %} diff --git a/templates/board/board_list.html b/templates/board/board_list.html index b30274c..f2f7985 100644 --- a/templates/board/board_list.html +++ b/templates/board/board_list.html @@ -1,64 +1,63 @@ {% extends "base.html" %} {% block content %} -{% block board_read %} -{% endblock %} -
    -
    - - - - - - - - - - - - - {% for pst in post_list %} - - - - - {%if pst.is_notice%} - - {%else%} - - {%endif%} - - - - {% endfor %} - -
    user - - title+/-date
    {{pst.is_read}}{{pst.username}}{{pst.board.board_name}}{{pst.title}} [{{pst.comment_count}}]+{{pst.vote.up}}/-{{pst.vote.down}}{{pst.created_time}}
    - - Write -
    - {%for page in paginator%} - {{page.page}} - {%endfor%} -
    -
    -
    + + + + + + + + + + + + {% for post in Posts %} + + + + {%if post.is_notice%} + + {%else%} + + {%endif%} + + + + {% endfor %} + +
    user + + title+/-date
    {{post.username}}{{post.board}}{{post.title}}+{{post.up}}/-{{post.down}}{{post.created_time}}
    + + + {% if show_paginator %} +
    + {% if has_prev %} + « + {% endif %} + + {% if has_next %} + » + {% endif %} + (page {{page}} of {{pages}}) +
    + {% endif %} {% endblock %} diff --git a/templates/board/board_read.html b/templates/board/board_read.html index 3c1d93b..372b4de 100644 --- a/templates/board/board_read.html +++ b/templates/board/board_read.html @@ -1,71 +1,86 @@ -{% extends "board/board_list.html" %} +{% extends "base.html" %} {% block js %} {% endblock %} -{% block board_read %} +{% block content %}
    +

    {{error}}

    @@ -169,8 +185,8 @@
    @@ -184,12 +200,8 @@
    - {% for comment in comment_list %} - {% if comment.best_comment %} -
    - {% else %} + {% for comment in comments %}
    - {% endif %}
    {{ comment.username }} @@ -200,11 +212,11 @@
    -
    -
    {{ comment.content|safe }}
    +
    +
    {{ comment.content|safe }}
    -
    +
    {% if not comment.deleted %} {% if comment.return %} - + - {% else %} -
    {% endif %} - {% endif %}
    -
    -
    - {% for re_comment in comment.re_comment_list %} -
    -
    -
    - {{ re_comment.username }} -
    -
    - {{re_comment.created_time}} - 추천 +{{re_comment.vote.up}}/-{{re_comment.vote.down}} -
    -
    -
    -
    -
    {{ re_comment.content|safe }}
    -
    -
    -
    - {% if not re_comment.deleted %} - - - - {% if re_comment.return %} - - - {% else %} -
    - {% endif %} - {% endif %} -
    -
    -
    -
    -
    - {% endfor %} - {% endfor %} {% if not post.deleted %}
    -
    + {%csrf_token%} - + {{ error }} +
    @@ -296,7 +259,66 @@
    {% endif %} -
    + + + + + + + + + + + + + {% for post in Posts %} + + + + {%if post.is_notice%} + + {%else%} + + {%endif%} + + + + {% endfor %} + +
    user + + title+/-date
    {{post.username}}{{post.board}}{{post.title}}+{{post.up}}/-{{post.down}}{{post.created_time}}
    + + + {% if show_paginator %} +
    + {% if has_prev %} + « + {% endif %} + + {% if has_next %} + » + {% endif %} + (page {{page}} of {{pages}}) +
    + {% endif %} +
    @@ -333,6 +355,7 @@

    X

    + {% endblock %} diff --git a/templates/board/board_write.html b/templates/board/board_write.html index 7430f92..e7a71ec 100644 --- a/templates/board/board_write.html +++ b/templates/board/board_write.html @@ -2,13 +2,13 @@ {% block js %}