Skip to content

Commit b41886c

Browse files
committed
コメントと説明を追加
1 parent 12d0b66 commit b41886c

File tree

9 files changed

+38
-6
lines changed

9 files changed

+38
-6
lines changed

Diff for: README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ DjangoフレームワークとJavaScriptでアプリケーションを作るサ
1919
* venv
2020
* Djangoフレームワーク
2121
* Django REST Framework
22+
* django-debug-toolbar
2223
* フロントエンド
2324
* Babel
2425
* webpack
@@ -58,8 +59,10 @@ DjangoフレームワークとJavaScriptでアプリケーションを作るサ
5859
* Vueに依存しないほうがテストコードを書きやすいから
5960
* Vueインスタンスをエントリポイント(index.js)外のJavaScriptコードに渡さない
6061
* エントリポイントではVueに依存しないコントローラクラスのインスタンスを生成し、データはコントローラに持たせる
61-
* 規模が大きくなったらストアを用意するかも
6262
* コンポーネントから外へVueインスタンスを渡さない
63+
* Bootstrapのモーダルダイアログを表示する場合は、コントローラから呼び出すのではなく、コントローラからの戻り値をコンポーネント側で使って表示制御する
6364
* django-webpack-loaderを使っていない
6465
* なるべく依存を増やさない
6566
* 必要になったら入れよう
67+
* DjangoのCSRF対策をフロントエンドからも利用する
68+
* Cookieに書き込まれたCSRFトークンをAPI呼び出し時に利用しています

Diff for: note_client/src/common.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* 共通モジュール
3+
* BootstrapVueやFontAwesomeとCSSを適用するために使います
4+
*/
15
import 'bootstrap/dist/css/bootstrap.css'
26
import 'bootstrap-vue/dist/bootstrap-vue.css'
37
import './style/font-awesome-config.scss'

Diff for: note_client/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/*
2+
* クライアントアプリケーションのエントリポイント
3+
*/
14
import 'bootstrap/dist/css/bootstrap.css'
25
import 'bootstrap-vue/dist/bootstrap-vue.css'
36
import './style/font-awesome-config.scss'

Diff for: note_client/webpack.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ var path = require('path');
44
module.exports = {
55
entry: {
66
babel_polyfill: 'babel-polyfill',
7-
index: './src/index.js',
8-
common: './src/common.js'
7+
index: './src/index.js', // アプリケーションページ用
8+
common: './src/common.js' // 共通ページ用
99
},
1010
output: {
11-
path: path.resolve('./build'),
11+
path: path.resolve('./build'), // ビルドしたファイルの出力先
1212
filename: '[name].js'
1313
},
1414
resolve: {

Diff for: note_server/note/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44

55
class Page(models.Model):
6+
"""ページモデル
7+
"""
68
class Meta:
79
verbose_name = verbose_name_plural = "ページ"
810
ordering = ('id',)

Diff for: note_server/note/serializers.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66

77
class PageSerializer(serializers.ModelSerializer):
8+
"""Pageモデルのシリアライザ
9+
10+
更新系は、titleとcontentのみ許可
11+
"""
812
class Meta:
913
model = Page
1014
fields = [

Diff for: note_server/note/views.py

+6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66

77

88
class PageViewSet(ModelViewSet):
9+
"""Pageモデルの一覧、作成、更新、削除のAPI
10+
"""
911
serializer_class = PageSerializer
12+
# ログイン済みの場合だけ許可
1013
permission_classes = (IsAuthenticated,)
1114

1215
def get_queryset(self):
16+
# ログイン中のユーザーのページのみを返す
1317
return Page.objects.filter(
1418
user=self.request.user,
1519
).order_by('-updated_at', '-id')
1620

1721
def perform_create(self, serializer):
1822
"""追加時のフック
23+
24+
ログイン中のユーザー情報を記録します
1925
"""
2026
serializer.save(user=self.request.user)

Diff for: note_server/note_server/settings.py

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DEBUG = True
1414

1515
ALLOWED_HOSTS = ['*']
16+
# django-debug-toolbarはINTERNAL_IPSからの通信でのみ有効になるため、VMのNATのアドレスを入れています
1617
INTERNAL_IPS = ['192.168.33.1']
1718

1819
# Application definition
@@ -39,6 +40,7 @@
3940
'django.middleware.clickjacking.XFrameOptionsMiddleware',
4041
]
4142

43+
# デバッグ時のみミドルウェアを有効にします
4244
if DEBUG:
4345
MIDDLEWARE.append(
4446
'debug_toolbar.middleware.DebugToolbarMiddleware',
@@ -50,6 +52,7 @@
5052
{
5153
'BACKEND': 'django.template.backends.django.DjangoTemplates',
5254
'DIRS': [
55+
# プロジェクト直下のtemplatesディレクトリにテンプレートファイルをまとめます
5356
os.path.join(BASE_DIR, 'templates'),
5457
],
5558
'APP_DIRS': True,
@@ -111,6 +114,7 @@
111114

112115
STATIC_URL = '/static/'
113116

117+
# ビルドされたクライアントアプリケーションをDjangoのstaticfilesから参照します
114118
STATICFILES_DIRS = [
115119
('client', os.path.join(os.path.dirname(BASE_DIR), 'note_client/build')),
116120
]

Diff for: note_server/note_server/urls.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,33 @@
1010
from rest_framework.documentation import include_docs_urls
1111

1212
urlpatterns = [
13+
# 管理画面
1314
path('admin/', admin.site.urls),
15+
# ログイン
1416
path(
1517
'login',
1618
auth_views.LoginView.as_view(
1719
template_name='login.html',
1820
redirect_authenticated_user=True),
1921
name='login'),
22+
# ログアウト
2023
path(
2124
'logout',
2225
auth_views.LogoutView.as_view(
2326
next_page='login'),
2427
name='logout'),
2528

26-
# API
29+
# APIドキュメント
2730
path('docs/', include_docs_urls(title='API', public=False)),
31+
# ノートアプリケーションのAPI
2832
path('note/', include('note.urls')),
2933

34+
# ノートアプリケーションの画面
3035
path('', ensure_csrf_cookie(login_required(render)),
3136
kwargs={'template_name': 'index.html'}, name='index'),
32-
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
37+
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) # staticfilesのファイルを配信
3338

39+
# デバッグ時のみdjango-debug-toolbarのURLを追加
3440
if settings.DEBUG:
3541
import debug_toolbar
3642
urlpatterns = [

0 commit comments

Comments
 (0)