Skip to content

Commit e0b23a4

Browse files
author
pythonpro
committed
First implementation.
1 parent de6428c commit e0b23a4

27 files changed

+525
-0
lines changed

chat/__init__.py

Whitespace-only changes.

chat/documents.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from mongoengine import Document, fields
2+
from mongoengine.django.auth import User
3+
import datetime
4+
5+
6+
class Message(Document):
7+
author = fields.ReferenceField(User, required=True)
8+
addressee = fields.ReferenceField(User, required=True)
9+
text = fields.StringField(required=True, max_length=40)
10+
created = fields.DateTimeField(required=True,
11+
default=datetime.datetime.now)
12+
read = fields.BooleanField(required=True, default=False)

chat/forms.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from mongodbforms import DocumentForm
2+
from documents import Message
3+
4+
5+
class MessageForm(DocumentForm):
6+
class Meta:
7+
document = Message
8+
fields = ("text",)

chat/settings.py

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Django settings for chat project.
2+
from mongoengine import connect
3+
4+
DEBUG = True
5+
TEMPLATE_DEBUG = DEBUG
6+
7+
ADMINS = (
8+
# ('Your Name', '[email protected]'),
9+
)
10+
11+
MANAGERS = ADMINS
12+
13+
DATABASES = {
14+
'default': {
15+
'ENGINE': 'django.db.backends.dummy', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
16+
'NAME': '', # Or path to database file if using sqlite3.
17+
# The following settings are not used with sqlite3:
18+
'USER': '',
19+
'PASSWORD': '',
20+
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
21+
'PORT': '', # Set to empty string for default.
22+
}
23+
}
24+
25+
# Hosts/domain names that are valid for this site; required if DEBUG is False
26+
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
27+
ALLOWED_HOSTS = []
28+
29+
# Local time zone for this installation. Choices can be found here:
30+
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
31+
# although not all choices may be available on all operating systems.
32+
# In a Windows environment this must be set to your system time zone.
33+
TIME_ZONE = 'America/Chicago'
34+
35+
# Language code for this installation. All choices can be found here:
36+
# http://www.i18nguy.com/unicode/language-identifiers.html
37+
LANGUAGE_CODE = 'en-us'
38+
39+
SITE_ID = 1
40+
41+
# If you set this to False, Django will make some optimizations so as not
42+
# to load the internationalization machinery.
43+
USE_I18N = True
44+
45+
# If you set this to False, Django will not format dates, numbers and
46+
# calendars according to the current locale.
47+
USE_L10N = True
48+
49+
# If you set this to False, Django will not use timezone-aware datetimes.
50+
USE_TZ = True
51+
52+
# Absolute filesystem path to the directory that will hold user-uploaded files.
53+
# Example: "/var/www/example.com/media/"
54+
MEDIA_ROOT = ''
55+
56+
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
57+
# trailing slash.
58+
# Examples: "http://example.com/media/", "http://media.example.com/"
59+
MEDIA_URL = ''
60+
61+
# Absolute path to the directory static files should be collected to.
62+
# Don't put anything in this directory yourself; store your static files
63+
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
64+
# Example: "/var/www/example.com/static/"
65+
STATIC_ROOT = ''
66+
67+
# URL prefix for static files.
68+
# Example: "http://example.com/static/", "http://static.example.com/"
69+
STATIC_URL = '/static/'
70+
71+
# Additional locations of static files
72+
STATICFILES_DIRS = (
73+
# Put strings here, like "/home/html/static" or "C:/www/django/static".
74+
# Always use forward slashes, even on Windows.
75+
# Don't forget to use absolute paths, not relative paths.
76+
)
77+
78+
# List of finder classes that know how to find static files in
79+
# various locations.
80+
STATICFILES_FINDERS = (
81+
'django.contrib.staticfiles.finders.FileSystemFinder',
82+
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
83+
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
84+
)
85+
86+
# Make this unique, and don't share it with anybody.
87+
SECRET_KEY = '%h886c4&)vsb0l)g^2mv+a3@q8_ww8-i110u$v2kontw61kxl)'
88+
89+
# List of callables that know how to import templates from various sources.
90+
TEMPLATE_LOADERS = (
91+
'django.template.loaders.filesystem.Loader',
92+
'django.template.loaders.app_directories.Loader',
93+
# 'django.template.loaders.eggs.Loader',
94+
)
95+
96+
MIDDLEWARE_CLASSES = (
97+
'django.middleware.common.CommonMiddleware',
98+
'django.contrib.sessions.middleware.SessionMiddleware',
99+
'django.middleware.csrf.CsrfViewMiddleware',
100+
'django.contrib.auth.middleware.AuthenticationMiddleware',
101+
'django.contrib.messages.middleware.MessageMiddleware',
102+
# Uncomment the next line for simple clickjacking protection:
103+
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
104+
)
105+
106+
ROOT_URLCONF = 'chat.urls'
107+
108+
# Python dotted path to the WSGI application used by Django's runserver.
109+
WSGI_APPLICATION = 'chat.wsgi.application'
110+
111+
TEMPLATE_DIRS = (
112+
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
113+
# Always use forward slashes, even on Windows.
114+
# Don't forget to use absolute paths, not relative paths.
115+
'/Users/tier/Job/Maxim/projects/chat/chat/templates',
116+
)
117+
118+
INSTALLED_APPS = (
119+
'django.contrib.auth',
120+
'mongoengine.django.mongo_auth',
121+
'django.contrib.contenttypes',
122+
'django.contrib.sessions',
123+
# 'django.contrib.sites',
124+
'django.contrib.messages',
125+
'django.contrib.staticfiles',
126+
# Uncomment the next line to enable the admin:
127+
# 'django.contrib.admin',
128+
# Uncomment the next line to enable admin documentation:
129+
# 'django.contrib.admindocs',
130+
'registration',
131+
)
132+
133+
# A sample logging configuration. The only tangible logging
134+
# performed by this configuration is to send an email to
135+
# the site admins on every HTTP 500 error when DEBUG=False.
136+
# See http://docs.djangoproject.com/en/dev/topics/logging for
137+
# more details on how to customize your logging configuration.
138+
LOGGING = {
139+
'version': 1,
140+
'disable_existing_loggers': False,
141+
'filters': {
142+
'require_debug_false': {
143+
'()': 'django.utils.log.RequireDebugFalse'
144+
}
145+
},
146+
'handlers': {
147+
'mail_admins': {
148+
'level': 'ERROR',
149+
'filters': ['require_debug_false'],
150+
'class': 'django.utils.log.AdminEmailHandler'
151+
}
152+
},
153+
'loggers': {
154+
'django.request': {
155+
'handlers': ['mail_admins'],
156+
'level': 'ERROR',
157+
'propagate': True,
158+
},
159+
}
160+
}
161+
162+
# Email settings.
163+
EMAIL_HOST = 'smtp.gmail.com'
164+
EMAIL_PORT = 587
165+
EMAIL_HOST_PASSWORD = 'xxxxxxxx'
166+
EMAIL_HOST_USER = '[email protected]'
167+
EMAIL_USE_TLS = True
168+
169+
# Django-registration settings.
170+
ACCOUNT_ACTIVATION_DAYS = 3
171+
SITE = {'name': 'Cool Site', 'domain': 'www.coolsite.ru'}
172+
LOGIN_REDIRECT_URL = "index"
173+
174+
# Mongo settings.
175+
connect('chat', host='192.168.1.5')
176+
AUTHENTICATION_BACKENDS = (
177+
'mongoengine.django.auth.MongoEngineBackend',
178+
)
179+
AUTH_USER_MODEL = 'mongo_auth.MongoUser'
180+
MONGOENGINE_USER_DOCUMENT = 'mongoengine.django.auth.User'
181+
SESSION_ENGINE = 'mongoengine.django.sessions'

chat/templates/base.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{% load i18n %}
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5+
6+
<head>
7+
<link rel="stylesheet" href="/style.css" />
8+
<title>{% block title %}User test{% endblock %}</title>
9+
</head>
10+
11+
<body>
12+
<div id="header">
13+
{% block header %}
14+
<a href="{% url 'index' %}">{% trans "Home" %}</a> |
15+
16+
{% if user.is_authenticated %}
17+
{% trans "Logged in" %}: {{ user.username }}
18+
(<a href="{% url 'auth_logout' %}">{% trans "Log out" %}</a> |
19+
<a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a>)
20+
{% else %}
21+
<a href="{% url 'auth_login' %}">{% trans "Log in" %}</a>
22+
{% endif %}
23+
<hr />
24+
{% endblock %}
25+
</div>
26+
27+
<div id="content">
28+
{% block content %}{% endblock %}
29+
</div>
30+
31+
<div id="footer">
32+
{% block footer %}
33+
<hr />
34+
{% endblock %}
35+
</div>
36+
</body>
37+
38+
</html>

chat/templates/chat.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
4+
{% block content %}
5+
<h2>Chat with {{ addressee.username }}:</h2>
6+
{% for m in all_messages %}
7+
{% ifequal m.author user %}
8+
<p style="background: lightgrey"><b>{{ m.author.username }}: </b>{{ m.text }}</p>
9+
{% else %}
10+
<p style="background: lightblue"><b>{{ m.author.username }}: </b>{{ m.text }}</p>
11+
{% endifequal %}
12+
{% endfor %}
13+
<h2>Reply:</h2>
14+
<form action="" method="post">
15+
{% csrf_token %}
16+
{{ form.as_p }}
17+
<p><input type="submit" value="Send" /></p>
18+
</form>
19+
{% endblock %}

chat/templates/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
4+
{% block content %}
5+
{% if user.is_authenticated %}
6+
<h2>All users:</h2>
7+
<ul>
8+
{% for u in udata %}
9+
<li><a href="{% url 'chat' u.0 %}">{{ u.0 }} ({{ u.1 }}/<b>{{ u.2 }})</b></a></li>
10+
{% endfor %}
11+
</ul>
12+
{% else %}
13+
Please log in to start the chat.
14+
{% endif %}
15+
{% endblock %}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
4+
{% block content %}
5+
6+
{% if account %}
7+
8+
<p>{% trans "Account successfully activated" %}</p>
9+
10+
<p><a href="{% url 'auth_login' %}">{% trans "Log in" %}</a></p>
11+
12+
{% else %}
13+
14+
<p>{% trans "Account activation failed" %}</p>
15+
16+
{% endif %}
17+
18+
{% endblock %}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
4+
{% block content %}
5+
<p>{% trans "Your account is now activated." %}</p>
6+
{% endblock %}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% load i18n %}
2+
{% trans "Activate account at" %} {{ site.name }}:
3+
4+
http://{{ site.domain }}{% url 'registration_activate' activation_key %}
5+
6+
{% blocktrans %}Link is valid for {{ expiration_days }} days.{% endblocktrans %}

0 commit comments

Comments
 (0)