Skip to content

Commit b31a8cc

Browse files
committed
initial commit
1 parent 4426b11 commit b31a8cc

File tree

17 files changed

+460
-0
lines changed

17 files changed

+460
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ docs/_build/
5555

5656
# PyBuilder
5757
target/
58+
59+
# Databases
60+
db.*
61+
62+
# Misc Files
63+
.DS_Store

comments_demo/comments_demo/__init__.py

Whitespace-only changes.
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""
2+
Django settings for comments_demo project.
3+
4+
Generated by 'django-admin startproject' using Django 1.8.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.8/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.8/ref/settings/
11+
"""
12+
13+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14+
import os
15+
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '&e1pwnrffy=z3k^(3rqubtjhq9=&o)b)=_6wqjxxtlu#acw(oi'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = ['127.0.0.1']
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = (
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'demo',
41+
)
42+
43+
MIDDLEWARE_CLASSES = (
44+
'django.contrib.sessions.middleware.SessionMiddleware',
45+
'django.middleware.common.CommonMiddleware',
46+
'django.middleware.csrf.CsrfViewMiddleware',
47+
'django.contrib.auth.middleware.AuthenticationMiddleware',
48+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
'django.middleware.security.SecurityMiddleware',
52+
)
53+
54+
ROOT_URLCONF = 'comments_demo.urls'
55+
56+
TEMPLATES = [
57+
{
58+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59+
'DIRS': [os.path.join(BASE_DIR, 'templates')],
60+
'APP_DIRS': True,
61+
'OPTIONS': {
62+
'context_processors': [
63+
'django.template.context_processors.debug',
64+
'django.template.context_processors.request',
65+
'django.contrib.auth.context_processors.auth',
66+
'django.contrib.messages.context_processors.messages',
67+
],
68+
},
69+
},
70+
]
71+
72+
WSGI_APPLICATION = 'comments_demo.wsgi.application'
73+
74+
75+
# Database
76+
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
77+
78+
DATABASES = {
79+
'default': {
80+
'ENGINE': 'django.db.backends.sqlite3',
81+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
82+
}
83+
}
84+
85+
86+
# Internationalization
87+
# https://docs.djangoproject.com/en/1.8/topics/i18n/
88+
89+
LANGUAGE_CODE = 'en-us'
90+
91+
TIME_ZONE = 'UTC'
92+
93+
USE_I18N = True
94+
95+
USE_L10N = True
96+
97+
USE_TZ = True
98+
99+
100+
# Static files (CSS, JavaScript, Images)
101+
# https://docs.djangoproject.com/en/1.8/howto/static-files/
102+
103+
STATIC_URL = '/static/'
104+
STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), )

comments_demo/comments_demo/urls.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.conf.urls import include, url
2+
from django.contrib import admin
3+
from comments_demo.views import home
4+
5+
urlpatterns = [
6+
# Examples:
7+
# url(r'^$', 'comments_demo.views.home', name='home'),
8+
# url(r'^blog/', include('blog.urls')),
9+
10+
url(r'^admin/', include(admin.site.urls)),
11+
url(r'^$', home),
12+
]

comments_demo/comments_demo/views.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django.shortcuts import render, render_to_response
2+
3+
def home(request):
4+
return render_to_response('demo.html')

comments_demo/comments_demo/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for comments_demo project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "comments_demo.settings")
15+
16+
application = get_wsgi_application()

comments_demo/demo/__init__.py

Whitespace-only changes.

comments_demo/demo/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

comments_demo/demo/demo.html

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!-- template.html -->
2+
<html>
3+
<head>
4+
<title>Comments Please!</title>
5+
6+
</head>
7+
<body>
8+
<div id="content"></div>
9+
<script type="text/jsx">
10+
/** @jsx React.DOM */
11+
12+
13+
var CommentBox = React.createClass({
14+
15+
getInitialState: function() {
16+
return {data: []};
17+
},
18+
19+
loadCommentsFromServer: function() {
20+
$.ajax({
21+
url : this.props.url,
22+
dataType : 'json',
23+
success : function(data) {
24+
this.setState({data: data});
25+
}.bind(this),
26+
error : function(xhr, status, err) {
27+
console.error(this.props.url, status, err.toString());
28+
}.bind(this)
29+
});
30+
},
31+
32+
handleCommentSubmit: function(comment) {
33+
var comments = this.state.data;
34+
var newComments = comments.concat([comment]);
35+
this.setState({data: newComments});
36+
37+
$.ajax({
38+
url: ' ',
39+
dataType: 'json',
40+
type: 'POST',
41+
data: comment,
42+
success: function(data) {
43+
this.setState({data: data});
44+
}.bind(this),
45+
error: function(xhr, status, err) {
46+
console.error(' ', status, err );
47+
}.bind(this)
48+
});
49+
},
50+
51+
componentDidMount: function() {
52+
this.loadCommentsFromServer();
53+
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
54+
},
55+
56+
render: function() {
57+
return (
58+
<div className="commentBox">
59+
<h1>Comments</h1>
60+
<CommentList data={this.state.data} />
61+
<CommentForm onCommentSubmit={this.handleCommentSubmit} />
62+
</div>
63+
);
64+
}
65+
66+
});
67+
68+
// tutorial2.js
69+
var CommentList = React.createClass({
70+
71+
render: function() {
72+
var commentNodes = this.props.data.map(function (comment) {
73+
return (
74+
<Comment author={comment.author}>
75+
{comment.text}
76+
</Comment>
77+
);
78+
});
79+
return (
80+
<div className="commentList">
81+
{commentNodes}
82+
</div>
83+
);
84+
}
85+
86+
});
87+
88+
var CommentForm = React.createClass({
89+
90+
handleSubmit: function() {
91+
var author = this.refs.author.getDOMNode().value.trim();
92+
var text = this.refs.text.getDOMNode().value.trim();
93+
this.props.onCommentSubmit({author: author, text: text});
94+
95+
if (!text || !author) {
96+
return false;
97+
}
98+
// TODO: send request to the server
99+
this.refs.author.getDOMNode().value = '';
100+
this.refs.text.getDOMNode().value = '';
101+
return false;
102+
},
103+
104+
render: function() {
105+
return (
106+
<form className="commentForm" onSubmit={this.handleSubmit}>
107+
<input type="text" placeholder="Your name" ref="author" />
108+
<input type="text" placeholder="Say something..." ref="text" />
109+
<input type="submit" value="Post" />
110+
</form>
111+
);
112+
}
113+
114+
});
115+
116+
// tutorial6.js
117+
var converter = new Showdown.converter();
118+
119+
// tutorial5.js
120+
var Comment = React.createClass({
121+
122+
render: function() {
123+
var rawMarkup = converter.makeHtml(this.props.children.toString());
124+
return (
125+
<div className="comment">
126+
<h2 className="commentAuthor">
127+
{this.props.author}
128+
</h2>
129+
<span dangerouslySetInnerHTML={{__html: rawMarkup}} />
130+
</div>
131+
);
132+
}
133+
134+
});
135+
136+
React.renderComponent(
137+
<CommentBox url=" " pollInterval={2000} />,
138+
document.getElementById('content')
139+
);
140+
</script>
141+
142+
143+
<script src="http://fb.me/react-0.11.1.js"></script>
144+
<script src="http://fb.me/JSXTransformer-0.11.1.js"></script>
145+
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
146+
<script src="http://cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js"></script>
147+
</body>
148+
</html>

comments_demo/demo/migrations/__init__.py

Whitespace-only changes.

comments_demo/demo/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

comments_demo/demo/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

comments_demo/demo/urls.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.conf.urls import include, url
2+
from django.contrib import admin
3+
4+
urlpatterns = [
5+
# Examples:
6+
# url(r'^$', 'comments_demo.views.home', name='home'),
7+
# url(r'^blog/', include('blog.urls')),
8+
9+
url(r'^admin/', include(admin.site.urls)),
10+
url(r'^$', views.home),
11+
]

comments_demo/demo/views.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django.shortcuts import render, render_to_response
2+
3+
def home(request):
4+
return render_to_response('demo.html')

comments_demo/manage.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "comments_demo.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

comments_demo/static/css/style.css

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
body {
2+
background: #eee;
3+
}
4+
5+
#textName {
6+
position: relative;
7+
margin-top: 1rem;
8+
height: 10%;
9+
width: 90%;
10+
border: none;
11+
border-radius: 10px;
12+
padding: 2%;
13+
margin: 1%;
14+
}
15+
16+
#submitButton {
17+
background-color: #DEDEDE;
18+
padding: 19px 15px;
19+
border-radius: 50%;
20+
z-index: 100;
21+
}
22+

0 commit comments

Comments
 (0)