-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdemo.py
83 lines (67 loc) · 2.31 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/env python
#-*- coding: utf-8 -*-
"""
Demo script. Run:
python.exe demo.py
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import logging
logging.basicConfig()
from django.conf import settings
from django.conf.urls import patterns, url, include
from django.core.wsgi import get_wsgi_application
basename = os.path.splitext(os.path.basename(__file__))[0]
def rel(*path):
return os.path.abspath(
os.path.join(os.path.dirname(__file__), *path)
).replace("\\", "/")
if not settings.configured:
settings.configure(
DEBUG=True,
TIMEZONE="UTC",
DATABASES={
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "demo.sqlite"
}
},
INSTALLED_APPS=[
"django.contrib.auth",
"django.contrib.sessions",
"django.contrib.admin",
"django.contrib.contenttypes",
"django.contrib.staticfiles",
"session_activity"
],
MIDDLEWARE_CLASSES=[
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"session_activity.middleware.SessionActivityMiddleware",
],
TEMPLATE_DIRS=[rel("tests", "templates")],
STATICFILES_DIRS=[rel("tests", "static")],
STATIC_URL="/static/",
ROOT_URLCONF=basename,
WSGI_APPLICATION="{}.application".format(basename),
LOGIN_URL="/login/",
USE_I18N=True,
USE_L10N=True,
)
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns("",
url(r'^admin/', include(admin.site.urls)),
url(r"^login/$", "django.contrib.auth.views.login"),
url(r"^", include('session_activity.urls')),
)
application = get_wsgi_application()
if __name__ == "__main__":
from django.core.management import call_command
from django.contrib.auth.models import User
call_command("syncdb", interactive=False)
if not User.objects.filter(username="admin").exists():
User.objects.create_superuser("admin", "[email protected]", "pass")
call_command("runserver", "8000")