Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop' into star-angular
Browse files Browse the repository at this point in the history
Conflicts:
	src/kawaz/templates/base.html
  • Loading branch information
giginet committed Jul 23, 2014
2 parents 8b49d44 + 7a9c50f commit 07247d9
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 9 deletions.
41 changes: 38 additions & 3 deletions src/kawaz/apps/blogs/tests/views/test_crud.py
@@ -1,8 +1,10 @@
import datetime
from django.conf import settings
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.contrib.auth.models import AnonymousUser
from ..factories import EntryFactory
from ..factories import CategoryFactory
from ...models import Entry
from kawaz.core.personas.tests.factories import PersonaFactory

Expand Down Expand Up @@ -68,8 +70,6 @@ def test_organizer_can_view_draft_entry(self):
class EntryCreateViewTestCase(TestCase):
def setUp(self):
self.user = PersonaFactory()
self.user.set_password('password')
self.user.save()

def test_anonymous_user_can_not_create_view(self):
'''Tests anonymous user can not view EntryCreateView'''
Expand Down Expand Up @@ -128,13 +128,47 @@ def test_user_cannot_modify_author_id(self):
self.assertEqual(e.author, self.user)
self.assertNotEqual(e.author, other)

def test_user_can_create_entry_with_category(self):
"""
カテゴリを指定してブログ記事を新しく投稿できる
"""
category = CategoryFactory(author=self.user)
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.post('/blogs/{0}/create/'.format(self.user.username), {
'pub_state': 'public',
'title': '日記です',
'body': '天気が良かったです',
'category': category.pk
})
today = datetime.date.today()
self.assertRedirects(r, '/blogs/{0}/{1}/{2}/{3}/1/'.format(self.user.username, today.year, today.month, today.day))
self.assertEqual(Entry.objects.count(), 1)
e = Entry.objects.get(pk=1)
self.assertEqual(e.author, self.user)
self.assertEqual(e.category, category)

def test_user_can_create_entry_with_others_category(self):
"""
他人のカテゴリを指定してブログ記事を新しく投稿しようとすると
ValidationErrorを送出する
"""
category = CategoryFactory()
self.assertTrue(self.client.login(username=self.user, password='password'))
r = self.client.post('/blogs/{0}/create/'.format(self.user.username), {
'pub_state': 'public',
'title': '日記です',
'body': '天気が良かったです',
'category': category.pk
})
self.assertEqual(r.status_code, 200)
self.assertEqual(Entry.objects.count(), 0)


class EntryUpdateViewTestCase(TestCase):
def setUp(self):
self.user = PersonaFactory(username='author_kawaztan')
self.user.set_password('password')
self.other = PersonaFactory(username='black_kawaztan')
self.other.set_password('password')
self.user.save()
self.other.save()
self.entry = EntryFactory(title='かわずたんだよ☆', author=self.user)
Expand Down Expand Up @@ -216,6 +250,7 @@ def test_user_cannot_modify_author_id(self):
self.assertNotEqual(e.author, other)
self.assertEqual(e.title, 'ID書き換えます!')


class EntryListViewTestCase(TestCase):
def setUp(self):
self.entries = (
Expand Down
9 changes: 7 additions & 2 deletions src/kawaz/apps/blogs/views.py
Expand Up @@ -40,10 +40,15 @@ class EntryCreateView(CreateView):
model = Entry
form_class = EntryForm

def form_valid(self, form):
def get_form(self, form_class):
# Model.cleanでValidationを行うために
# ここで作者を設定している
# 議論参照
# https://github.com/kawazrepos/Kawaz3rd/pull/134
form = super().get_form(form_class)
# 記事の作成者を自動的に指定
form.instance.author = self.request.user
return super().form_valid(form)
return form


@permission_required('blogs.change_entry')
Expand Down
4 changes: 4 additions & 0 deletions src/kawaz/settings.py
Expand Up @@ -35,6 +35,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.comments',
'rest_framework',
'permission',
'thumbnailfield',
Expand Down Expand Up @@ -175,6 +177,8 @@

RECENT_ACTIVITY_FEED_URL = 'http://kawazinfo.hateblo.jp/rss'

SITE_ID = 1

if DEBUG:
# テスト時のRuntimeWarningをexceptionにしている
# https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#code
Expand Down
3 changes: 3 additions & 0 deletions src/kawaz/statics/coffee/comment.coffee
@@ -0,0 +1,3 @@
$ ->
# ログインユーザーはMace Editorを使える
$('.comment-form.authenticated-form').find('#id_comment').addClass('mace-editor')
75 changes: 75 additions & 0 deletions src/kawaz/statics/less/comment.less
@@ -0,0 +1,75 @@
@import "common/define";
@import "common/vendor-prefixes";

.comment-form {
margin: 20px;
&.authenticated-form {
// ログインフォームではname, email, urlを隠す
.disable-field(name);
.disable-field(email);
.disable-field(url);
}
.disable-field(honeypot);
}
// 指定したフィールド名のフィールドを消し去るお便利mixin
.disable-field(@field_name) {
[for="id_@{field_name}"] {
display: none;
& ~ div {
display: none;
}
}
}
.comment-list {
margin: 20px 0 30px;
}
.comment-item {
@border-radius: 5px;
background-color: white;
border: solid 1px @gray-lighter;
.border-radius(@border-radius);
margin: 20px;
.comment-avatar {
height: 100%;
img {
border: solid 1px @gray-lighter;
background-color: @gray-lighter;
}
}
.comment-info {
.comment-avatar {
top: -@avatar-size-small / 2;
left: -@avatar-size-small / 2;
position: absolute;
}
background-color: @brand-primary;
border-radius: @border-radius @border-radius 0 0;
-webkit-border-radius: @border-radius @border-radius 0 0;
-moz-border-radius: @border-radius @border-radius 0 0;
margin: 0;
padding: 5px @avatar-size-small + 16px;
.comment-index {
font-weight: bold;
}
.username {
font-size: 12px;
color: @gray-light;
a {
color: @gray-light;
}
}
}
.comment-body {
width: 100%;
height: 100%;
padding: 15px 20px;
min-height: 40px;
}
.comment-date {
time {
float: right;
}
padding-bottom: 3px;
}

}
4 changes: 4 additions & 0 deletions src/kawaz/templates/base.html
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" href="{% static "css/social.css" %}" media="screen">
<link rel="stylesheet" href="{% static "css/form.css" %}" media="screen">
<link rel="stylesheet" href="{% static "css/markdown.css" %}" media="screen">
<link rel="stylesheet" href="{% static "css/comment.css" %}" media="screen">
<link rel="stylesheet" href="{% static "vendor/lightbox.css" %}" media="screen">
<link rel="stylesheet" href="{% static "css/star.css" %}" media="screen">
<!--
Expand Down Expand Up @@ -98,10 +99,13 @@
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
<script src="{% static "vendor/angular-sanitize.min.js" %}"></script>
<script src="{% static "vendor/lightbox.min.js" %}"></script>
<script src="{% static "vendor/mace.min.js" %}"></script>
<script src="{% static "js/angular.js" %}"></script>
<script src="{% static "js/bootstrap.js" %}"></script>
<script src="{% static "js/social.js" %}"></script>
<script src="{% static "js/star.js" %}"></script>
<script src="{% static "js/comment.js" %}"></script>
<script src="{% static "js/editor.js" %}"></script>
{% endblock %}
</body>
</html>
4 changes: 3 additions & 1 deletion src/kawaz/templates/blogs/entry_detail.html
@@ -1,4 +1,6 @@
{% extends "base.html" %}
{% block content %}
{{ object }}
{% include "blogs/components/entry_detail.html" %}
{% include "comments/components/comment_items.html" %}
{% include "comments/components/comment_form.html" %}
{% endblock %}
2 changes: 1 addition & 1 deletion src/kawaz/templates/blogs/entry_list.html
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block content %}
{% for object in object_list %}
{{ object }}
<a href="{{ object.get_absolute_url }}">{{ object }}</a>
{% endfor %}
{% endblock %}
14 changes: 14 additions & 0 deletions src/kawaz/templates/comments/components/comment_form.html
@@ -0,0 +1,14 @@
{% load comments %}
{% load bootstrap %}
{% get_comment_form for object as comment_form %}
<h2>コメントの投稿</h2>
<div class="comment-form{% if request.user.is_authenticated %} authenticated-form{% endif %}">
<form class="form-horizontal" method="POST" action="{% comment_form_target %}">{% csrf_token %}
<div class="row">
{{ comment_form | bootstrap_horizontal }}
<div class="form-group col col-lg-12">
<input type="submit" class="btn btn-primary" value="投稿">
</div>
</div>
</form>
</div>
42 changes: 42 additions & 0 deletions src/kawaz/templates/comments/components/comment_items.html
@@ -0,0 +1,42 @@
{% load comments %}
{% get_comment_list for object as comments %}
<div class="comment-list">
<h2>コメント</h2>
{% for comment in comments %}
<article class="comment-item row" id="c{{ comment.pk }}">
<header class="col col-lg-12 comment-info">
<div class="comment-avatar">
{% if comment.user.is_authenticated %}
{# ログインユーザーはuserのavatar #}
<img src="{{ MEDIA_URL }}{{ comment.user.avatar.middle }}" class="avatar avatar-middle" alt="@{{ comment.user.username }}">
{% else %}
{# 非ログインユーザーはデフォルトのアイコン #}
<img src="{{ MEDIA_URL }}" class="avatar avatar-middle">
{% endif %}
</div>
<span class="comment-index">{{ forloop.counter }}</span>
{% if comment.user.is_authenticated %}
<span class="nickname">{{ comment.user.nickname }}さん</span>
<span class="username">(<a href="{{ comment.user.profile.get_absolute_url }}">@{{ comment.user.username }}</a>)</span>
{% else %}
<span>{{ comment.name }}さん</span>
{% endif %}
</header>
<div class="comment-body col col-lg-12 comment-body">
{% if comment.user.is_authenticated %}
{# ログインユーザーはmarkdownを使える #}
<div class="markdown">
{{ comment.comment | markdown }}
</div>
{% else %}
{# 非ログインユーザーは改行のみ変換される #}
{{ comment.comment | linebreaksbr }}
{% endif %}
</div>

<footer class="col col-lg-12 comment-date">
<time><a href="{{ comment.get_absolute_url }}">{{ comment.submit_date|date:"Y/m/d H:i" }}</a></time>
</footer>
</article>
{% endfor %}
</div>
2 changes: 0 additions & 2 deletions src/kawaz/templates/form_base.html
Expand Up @@ -31,9 +31,7 @@
{% endblock %}
{% block post_javascript %}
{{ block.super }}
<script src="{% static "vendor/mace.min.js" %}"></script>
<script src="{% static "vendor/jquery.datetimepicker.min.js" %}"></script>
<script src="{% static "js/editor.js" %}"></script>
<script src="{% static "js/form.js" %}"></script>
<script src="{% static "js/preview.js" %}"></script>
{% endblock %}
1 change: 1 addition & 0 deletions src/kawaz/urls.py
Expand Up @@ -18,6 +18,7 @@
url(r'^attachments/', include('kawaz.apps.attachments.urls')),
url(r'^registration/', include('kawaz.core.personas.urls')),
url(r'^registration/', include('registration.urls')),
url(r'^comments/', include('django.contrib.comments.urls')),
)

from django.conf.urls.static import static
Expand Down

0 comments on commit 07247d9

Please sign in to comment.