Commit 51ffe675 authored by Alan Mitchell's avatar Alan Mitchell
Browse files

Changes related to Upgrading Django version.

Also, restructuring of the Settings file into a BMON-specific file and
then a file containing Settings that are generally the same across BMON
installations.  This settings_common.py file can be put under source
control and updated as needed over time.
parent daea6179
"""This file contains Django settings that are generally the same across
different BMON installation. You can override these settings in the settings.py
file if the insert the overridden settings into the settings.py file after
the execfile() statement at the end of the file.
NOTE: This file depends upon import statements and variables created in the
settings.py file, so will not run alone. This file is execute using the
execfile() function from the settings.py file, and executes in the namespace
of that file.
"""
# Name of this Django project. Note that if you change this from bmon, you will also
# have to change values in the manage.py, wsgi.py, and appache2/conf/httpd.conf files.
BMSAPP_PROJ_NAME = 'bmon'
# This is the name you gave to the Static application created in the Webfaction Control
# Panel to serve static Django media. This is only used to create the STATIC_ROOT setting
# further down in this settings file.
BMSAPP_STATIC_APP_NAME = 'bmon_static'
# Determine the path to this project directory, which is one directory above
# the directory of this file (thus the two applications of 'dirname').
PROJ_PATH = dirname(dirname(abspath(__file__)))
# Suprresses warning about unittests and older projects.
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': join(PROJ_PATH, '%s.sqlite' % BMSAPP_PROJ_NAME), # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = join(PROJ_PATH, '..', '..', BMSAPP_STATIC_APP_NAME)
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# join(PROJ_PATH, 'static'),
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = '%s.urls' % BMSAPP_PROJ_NAME
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = '%s.wsgi.application' % BMSAPP_PROJ_NAME
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
# 'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'bmsapp',
'django_extensions',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
......@@ -2,6 +2,7 @@
# Django settings for BMON project #
##################################################
import logging
from os.path import dirname, join, abspath
#----------------- Settings Specific to the Monitoring App ----------------------
......@@ -48,15 +49,6 @@ BMSAPP_NAV_LINKS = ( ('Map', 'map'),
('Training Videos and Project Reports', 'training_anthc'),
)
# Name of this Django project. Note that if you change this from bmon, you will also
# have to change values in the manage.py, wsgi.py, and appache2/conf/httpd.conf files.
BMSAPP_PROJ_NAME = 'bmon'
# This is the name you gave to the Static application created in the Webfaction Control
# Panel to serve static Django media. This is only used to create the STATIC_ROOT setting
# further down in this settings file.
BMSAPP_STATIC_APP_NAME = 'bmon_static'
# The number of hours before a sensor is considered to be inactive (not posting data).
BMSAPP_SENSOR_INACTIVITY = 2.0 # Hours
......@@ -142,148 +134,9 @@ SERVER_EMAIL = 'valid_from_email_for_error_messages' # this is the FROM for er
# debug information.
DEBUG = False
# ----------- Generally shouldn't need to change anything beyond here ------------
from os.path import dirname, join, realpath
# Suprresses warning about unittests and older projects.
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
PROJ_PATH = realpath(join(dirname(__file__), '..')) # probably don't need the "realpath" function
TEMPLATE_DEBUG = DEBUG
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': join(PROJ_PATH, '%s.sqlite' % BMSAPP_PROJ_NAME), # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = join(PROJ_PATH, '..', '..', BMSAPP_STATIC_APP_NAME)
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# join(PROJ_PATH, 'static'),
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = '%s.urls' % BMSAPP_PROJ_NAME
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = '%s.wsgi.application' % BMSAPP_PROJ_NAME
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
join(PROJ_PATH, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
# 'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'bmsapp',
'django_extensions',
)
# Execute in this namespace the file containing settings that are generally common to all
# installs of BMON.
execfile(join(dirname(abspath(__file__)), 'settings_common.py'))
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
# If you need to override any of the settings in the 'settings_common.py' file
# do so below this point in this file.
# Execute in this namespace the file containing settings that are generally common to all
# installs of BMON.
execfile(join(dirname(abspath(__file__)), 'settings_common.py'))
# If you need to override any of the settings in the 'settings_common.py' file
# do so below this point in this file.
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'rm.views.home', name='home'),
# url(r'^rm/', include('rm.foo.urls')),
urlpatterns = [
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('bmsapp.urls')),
)
]
......@@ -74,6 +74,7 @@ class BuildingAdmin(admin.ModelAdmin):
class BuildingModeAdmin(admin.ModelAdmin):
list_display = ('name',)
list_editable = ('name',)
list_display_links = None
@admin.register(BuildingGroup)
......
......@@ -184,7 +184,7 @@ class Building(models.Model):
schedule = models.TextField("Occupied Schedule of Facility (e.g. M-F: 8a-5p)", blank=True)
# the sensors and calculated values associated with this building
sensors = models.ManyToManyField(Sensor, through='BldgToSensor', blank=True, null=True)
sensors = models.ManyToManyField(Sensor, through='BldgToSensor', blank=True)
def __unicode__(self):
return self.title
......@@ -506,7 +506,7 @@ class AlertCondition(models.Model):
wait_before_next = models.FloatField('Hours to Wait before Notifying Again', default=4.0)
# the recipients who should receive this alert
recipients = models.ManyToManyField(AlertRecipient, verbose_name='Who should be notified?', blank=True, null=True)
recipients = models.ManyToManyField(AlertRecipient, verbose_name='Who should be notified?', blank=True)
# when the last notification of this alert condition was sent out, Unix timestamp.
# This is filled out when alert conditions are evaluated and is not accessible in the Admin
......
import time
from django.template import Context, loader
from django.template import loader
import bmsapp.models, bmsapp.data_util
import bmsapp.formatters
import basechart
......@@ -54,7 +54,7 @@ class CurrentValues(basechart.BaseChart):
footer_title = ""
# context for template
context = Context( {} )
context = {}
# Make markdown entries available to the template to be used in the footer
context['footer'] = footer
......
import yaml
import time
from django.template import Context, loader
from django.template import loader
import bmsapp.models, bmsapp.data_util, bmsapp.view_util
import bmsapp.formatters
import basechart
......@@ -83,7 +83,7 @@ class CurrentValuesMulti(basechart.BaseChart):
# context for template
context = Context({})
context = {}
# create a report title
context['report_title'] = self.chart_info.title
......
......@@ -2,25 +2,26 @@
URLs for the BMS Application
'''
from django.conf.urls import patterns, url
from django.conf.urls import url
from . import views
urlpatterns = patterns('bmsapp.views',
url(r'^readingdb/reading/(\w+)/store/$', 'store_reading'), # URL to store one reading into database
url(r'^readingdb/reading/store/$', 'store_readings'), # URL to store multiple readings into database
url(r'^st8(\w+)/', 'store_reading_old'), # Old URL pattern for storing. Shouldn't be used for new sensors.
url(r'^readingdb/reading/(\w+)/$', 'get_readings'), # gets all readings for one reading ID.
url(r'^$', 'index'),
url(r'^reports/$', 'reports', name='reports'),
url(r'^reports/results/$', 'get_report_results'),
url(r'^reports/(\d+)/$', 'reports'),
url(r'^show_log/$', 'show_log'),
url(r'^bldg_list/(\d+)/$', 'bldg_list'),
url(r'^chart_sensor_list/(\d+)/(multi)/$', 'chart_sensor_list'),
url(r'^chart_sensor_list/(\d+)/(\d+)/$', 'chart_sensor_list'),
url(r'^map_json/$', 'map_json', name='map-json'),
url(r'^training/video/(\w+)/(\d+)/(\d+)/$', 'show_video', name='show-video'),
url(r'^make_store_key/$', 'make_store_key'),
urlpatterns = [
url(r'^readingdb/reading/(\w+)/store/$', views.store_reading), # URL to store one reading into database
url(r'^readingdb/reading/store/$', views.store_readings), # URL to store multiple readings into database
url(r'^st8(\w+)/', views.store_reading_old), # Old URL pattern for storing. Shouldn't be used for new sensors.
url(r'^readingdb/reading/(\w+)/$', views.get_readings), # gets all readings for one reading ID.
url(r'^$', views.index, name='index'),
url(r'^reports/$', views.reports, name='reports'),
url(r'^reports/results/$', views.get_report_results),
url(r'^reports/(\d+)/$', views.reports),
url(r'^show_log/$', views.show_log),
url(r'^bldg_list/(\d+)/$', views.bldg_list),
url(r'^chart_sensor_list/(\d+)/(multi)/$', views.chart_sensor_list),
url(r'^chart_sensor_list/(\d+)/(\d+)/$', views.chart_sensor_list),
url(r'^map_json/$', views.map_json, name='map-json'),
url(r'^training/video/(\w+)/(\d+)/(\d+)/$', views.show_video, name='show-video'),
url(r'^make_store_key/$', views.make_store_key),
# catches URLs that don't match the above patterns. Assumes they give a template name to render.
url(r'^(\w+)/$', 'wildcard'),
)
url(r'^(\w+)/$', views.wildcard, name='wildcard'),
]
......@@ -35,7 +35,7 @@ def base_context():
Had to do this because I could not run the 'reverse' method from the module level.
'''
ctx = TMPL_CONTEXT.copy()
ctx['bmsapp_nav_link_base_url'] = reverse('bmsapp.views.index')
ctx['bmsapp_nav_link_base_url'] = reverse('index')
return ctx
def index(request):
......@@ -45,7 +45,7 @@ def index(request):
# find the index page in the set of navigation links
for lnk in TMPL_CONTEXT['bmsapp_nav_links']:
if len(lnk)==3 and lnk[2]==True:
return redirect( reverse('bmsapp.views.wildcard', args=(lnk[1],)) )
return redirect( reverse('wildcard', args=(lnk[1],)) )
def reports(request, bldg_id=None):
'''
......
......@@ -5,9 +5,9 @@
# Django is needed but it will be installed through the Webfaction control
# panel
# Django==1.7.3
# Django==1.10.2
django-extensions==1.4.9
django-extensions==1.7.4
# numpy==1.9.1 must be installed prior to running this requirements file
# due to numexpr install requiring it.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment