From 06be2e2122b89b94488e3fb9991859f605855a80 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 28 Mar 2017 23:14:50 -0500 Subject: [PATCH] Initial commit --- .gitignore | 1 + MANIFEST.in | 8 ++ README.rst | 7 ++ rattail_tempmon_demo/__init__.py | 8 ++ rattail_tempmon_demo/_version.py | 3 + rattail_tempmon_demo/config.py | 20 +++++ rattail_tempmon_demo/emails.py | 11 +++ rattail_tempmon_demo/web/__init__.py | 0 rattail_tempmon_demo/web/app.py | 35 ++++++++ rattail_tempmon_demo/web/static/__init__.py | 9 ++ rattail_tempmon_demo/web/subscribers.py | 18 ++++ rattail_tempmon_demo/web/templates/base.mako | 18 ++++ rattail_tempmon_demo/web/templates/home.mako | 12 +++ rattail_tempmon_demo/web/templates/login.mako | 17 ++++ rattail_tempmon_demo/web/templates/menu.mako | 63 +++++++++++++ .../web/templates/mobile/base.mako | 27 ++++++ .../web/templates/mobile/home.mako | 7 ++ rattail_tempmon_demo/web/views/__init__.py | 22 +++++ rattail_tempmon_demo/web/views/common.py | 29 ++++++ setup.py | 88 +++++++++++++++++++ 20 files changed, 403 insertions(+) create mode 100644 .gitignore create mode 100644 MANIFEST.in create mode 100644 README.rst create mode 100644 rattail_tempmon_demo/__init__.py create mode 100644 rattail_tempmon_demo/_version.py create mode 100644 rattail_tempmon_demo/config.py create mode 100644 rattail_tempmon_demo/emails.py create mode 100644 rattail_tempmon_demo/web/__init__.py create mode 100644 rattail_tempmon_demo/web/app.py create mode 100644 rattail_tempmon_demo/web/static/__init__.py create mode 100644 rattail_tempmon_demo/web/subscribers.py create mode 100644 rattail_tempmon_demo/web/templates/base.mako create mode 100644 rattail_tempmon_demo/web/templates/home.mako create mode 100644 rattail_tempmon_demo/web/templates/login.mako create mode 100644 rattail_tempmon_demo/web/templates/menu.mako create mode 100644 rattail_tempmon_demo/web/templates/mobile/base.mako create mode 100644 rattail_tempmon_demo/web/templates/mobile/home.mako create mode 100644 rattail_tempmon_demo/web/views/__init__.py create mode 100644 rattail_tempmon_demo/web/views/common.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbf992a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +rattail_tempmon_demo.egg-info/ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..9db7ffd --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,8 @@ +# -*- mode: conf -*- + +include *.rst + +recursive-include rattail_tempmon_demo/web/static *.css +recursive-include rattail_tempmon_demo/web/static *.js + +recursive-include rattail_tempmon_demo/web/templates *.mako diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..8ab09ec --- /dev/null +++ b/README.rst @@ -0,0 +1,7 @@ + +rattail-tempmon-demo +==================== + +This is a simple demo for Rattail Tempmon. See the `Rattail website`_ for more info. + +.. _`Rattail website`: https://rattailproject.org/ diff --git a/rattail_tempmon_demo/__init__.py b/rattail_tempmon_demo/__init__.py new file mode 100644 index 0000000..8957cd4 --- /dev/null +++ b/rattail_tempmon_demo/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8; -*- +""" +Rattail Tempmon Demo package root +""" + +from __future__ import unicode_literals, absolute_import + +from ._version import __version__ diff --git a/rattail_tempmon_demo/_version.py b/rattail_tempmon_demo/_version.py new file mode 100644 index 0000000..e727f3d --- /dev/null +++ b/rattail_tempmon_demo/_version.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +__version__ = u'0.1.0' diff --git a/rattail_tempmon_demo/config.py b/rattail_tempmon_demo/config.py new file mode 100644 index 0000000..7bcb8bc --- /dev/null +++ b/rattail_tempmon_demo/config.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8; -*- +""" +Rattail config extension +""" + +from __future__ import unicode_literals, absolute_import + +from rattail.config import ConfigExtension + + +class RattailTempmonDemoConfig(ConfigExtension): + """ + Rattail config extension for Rattail Tempmon Demo + """ + key = 'rattail_tempmon_demo' + + def configure(self, config): + + # set some default config values + config.setdefault('rattail.mail', 'emails', 'rattail_tempmon_demo.emails') diff --git a/rattail_tempmon_demo/emails.py b/rattail_tempmon_demo/emails.py new file mode 100644 index 0000000..55fbb49 --- /dev/null +++ b/rattail_tempmon_demo/emails.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8; -*- +""" +Custom email profiles +""" + +from __future__ import unicode_literals, absolute_import + +from rattail.mail import Email + +# bring in some common ones from rattail +from rattail.emails import datasync_error_watcher_get_changes, filemon_action_error diff --git a/rattail_tempmon_demo/web/__init__.py b/rattail_tempmon_demo/web/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rattail_tempmon_demo/web/app.py b/rattail_tempmon_demo/web/app.py new file mode 100644 index 0000000..342fc9e --- /dev/null +++ b/rattail_tempmon_demo/web/app.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8; -*- +""" +Rattail Tempmon Demo web app +""" + +from __future__ import unicode_literals, absolute_import + +from tailbone import app + + +def main(global_config, **settings): + """ + This function returns a Pyramid WSGI application. + """ + # set some defaults for PostgreSQL + app.provide_postgresql_settings(settings) + + # prefer Rattail Tempmon Demo templates over Tailbone; use 'better' theme + settings.setdefault('mako.directories', ['rattail_tempmon_demo.web:templates', + 'tailbone:templates/themes/better', + 'tailbone:templates',]) + + # make config objects + rattail_config = app.make_rattail_config(settings) + pyramid_config = app.make_pyramid_config(settings) + + # bring in the rest of Rattail Tempmon Demo + pyramid_config.include('rattail_tempmon_demo.web.static') + pyramid_config.include('rattail_tempmon_demo.web.subscribers') + pyramid_config.include('rattail_tempmon_demo.web.views') + + # configure PostgreSQL some more + app.configure_postgresql(pyramid_config) + + return pyramid_config.make_wsgi_app() diff --git a/rattail_tempmon_demo/web/static/__init__.py b/rattail_tempmon_demo/web/static/__init__.py new file mode 100644 index 0000000..3769b1e --- /dev/null +++ b/rattail_tempmon_demo/web/static/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8; mode: python -*- +""" +Static assets +""" + + +def includeme(config): + config.include('tailbone.static') + config.add_static_view('rattail_tempmon_demo', 'rattail_tempmon_demo.web:static', cache_max_age=3600) diff --git a/rattail_tempmon_demo/web/subscribers.py b/rattail_tempmon_demo/web/subscribers.py new file mode 100644 index 0000000..4ac7e66 --- /dev/null +++ b/rattail_tempmon_demo/web/subscribers.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8; mode: python -*- +""" +Pyramid event subscribers +""" + +from __future__ import unicode_literals, absolute_import + +import rattail_tempmon_demo + + +def add_rattail_tempmon_demo_to_context(event): + renderer_globals = event + renderer_globals['rattail_tempmon_demo'] = rattail_tempmon_demo + + +def includeme(config): + config.include('tailbone.subscribers') + config.add_subscriber(add_rattail_tempmon_demo_to_context, 'pyramid.events.BeforeRender') diff --git a/rattail_tempmon_demo/web/templates/base.mako b/rattail_tempmon_demo/web/templates/base.mako new file mode 100644 index 0000000..0274007 --- /dev/null +++ b/rattail_tempmon_demo/web/templates/base.mako @@ -0,0 +1,18 @@ +## -*- coding: utf-8; mode: html; -*- +<%inherit file="tailbone:templates/themes/better/base.mako" /> + +<%def name="app_title()">Tempmon Demo + +<%def name="favicon()"> + + + +<%def name="header_logo()"> + ${h.image(request.static_url('tailbone:static/img/rattail.ico'), "Header Logo", height='49')} + + +<%def name="footer()"> + ${h.link_to("Tempmon Demo {}{}".format(rattail_tempmon_demo.__version__, '' if request.rattail_config.production() else '+dev'), url('about'))} + + +${parent.body()} diff --git a/rattail_tempmon_demo/web/templates/home.mako b/rattail_tempmon_demo/web/templates/home.mako new file mode 100644 index 0000000..8f6cac7 --- /dev/null +++ b/rattail_tempmon_demo/web/templates/home.mako @@ -0,0 +1,12 @@ +## -*- coding: utf-8; mode: html; -*- +<%inherit file="tailbone:templates/home.mako" /> + +<%def name="title()">Home + + + +

Welcome to the Tempmon Demo

diff --git a/rattail_tempmon_demo/web/templates/login.mako b/rattail_tempmon_demo/web/templates/login.mako new file mode 100644 index 0000000..584436a --- /dev/null +++ b/rattail_tempmon_demo/web/templates/login.mako @@ -0,0 +1,17 @@ +## -*- coding: utf-8; mode: html; -*- +<%inherit file="tailbone:templates/login.mako" /> + +<%def name="extra_styles()"> + ${parent.extra_styles()} + + + +<%def name="logo()"> + ${h.image(request.static_url('tailbone:static/img/home_logo.png'), "Rattail Logo", id='logo')} + + +${parent.body()} diff --git a/rattail_tempmon_demo/web/templates/menu.mako b/rattail_tempmon_demo/web/templates/menu.mako new file mode 100644 index 0000000..81a9915 --- /dev/null +++ b/rattail_tempmon_demo/web/templates/menu.mako @@ -0,0 +1,63 @@ +## -*- coding: utf-8 -*- + +<%def name="main_menu_items()"> + + % if request.has_any_perm('tempmon.clients.list', 'tempmon.probes.list', 'tempmon.readings.list'): +
  • + Tempmon + +
  • + % endif + + % if request.has_any_perm('people.list', 'users.list', 'roles.list', 'settings.list', 'emailprofiles.list'): +
  • + Admin + +
  • + % endif + + % if request.user: +
  • + ${request.user}${" ({})".format(inbox_count) if inbox_count else ''} +
      + % if request.is_root: +
    • ${h.link_to("Stop being root", url('stop_root'))}
    • + % elif request.is_admin: +
    • ${h.link_to("Become root", url('become_root'))}
    • + % endif +
    • ${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'))}
    • +
    • ${h.link_to("Change Password", url('change_password'))}
    • +
    • ${h.link_to("Logout", url('logout'))}
    • +
    +
  • + % else: +
  • ${h.link_to("Login", url('login'))}
  • + % endif + + diff --git a/rattail_tempmon_demo/web/templates/mobile/base.mako b/rattail_tempmon_demo/web/templates/mobile/base.mako new file mode 100644 index 0000000..969c392 --- /dev/null +++ b/rattail_tempmon_demo/web/templates/mobile/base.mako @@ -0,0 +1,27 @@ +## -*- coding: utf-8; mode: html; -*- +<%inherit file="tailbone:templates/mobile/base.mako" /> + +<%def name="app_title()">Tempmon Demo + +<%def name="mobile_usermenu()"> +
    + +
    + + +<%def name="mobile_footer()"> +
    +

    ${h.link_to("Tempmon Demo {}{}".format(rattail_tempmon_demo.__version__, '' if request.rattail_config.production() else '+dev'), url('mobile.about'))}

    +
    + + +${parent.body()} diff --git a/rattail_tempmon_demo/web/templates/mobile/home.mako b/rattail_tempmon_demo/web/templates/mobile/home.mako new file mode 100644 index 0000000..aa37de8 --- /dev/null +++ b/rattail_tempmon_demo/web/templates/mobile/home.mako @@ -0,0 +1,7 @@ +## -*- coding: utf-8; mode: html; -*- +<%inherit file="tailbone:templates/mobile/home.mako" /> + +
    + ${h.image(request.static_url('tailbone:static/img/home_logo.png'), "Rattail Logo", width='400')} +

    Welcome to ${self.app_title()}

    +
    diff --git a/rattail_tempmon_demo/web/views/__init__.py b/rattail_tempmon_demo/web/views/__init__.py new file mode 100644 index 0000000..125cfa1 --- /dev/null +++ b/rattail_tempmon_demo/web/views/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8; mode: python; -*- +""" +Views +""" + +from __future__ import unicode_literals, absolute_import + + +def includeme(config): + + # core views + config.include('rattail_tempmon_demo.web.views.common') + config.include('tailbone.views.auth') + + # main table views + config.include('tailbone.views.email') + config.include('tailbone.views.messages') + config.include('tailbone.views.people') + config.include('tailbone.views.roles') + config.include('tailbone.views.settings') + config.include('tailbone.views.users') + config.include('tailbone.views.tempmon') diff --git a/rattail_tempmon_demo/web/views/common.py b/rattail_tempmon_demo/web/views/common.py new file mode 100644 index 0000000..6687b61 --- /dev/null +++ b/rattail_tempmon_demo/web/views/common.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8; -*- +""" +Common views +""" + +from __future__ import unicode_literals, absolute_import + +from tailbone.views import common as base + +import rattail_tempmon_demo + + +class CommonView(base.CommonView): + + project_title = "Rattail-Tempmon-Demo" + project_version = rattail_tempmon_demo.__version__ + '+dev' + + def get_packages(self): + import rattail_tempmon + + packages = super(CommonView, self).get_packages() + packages['rattail-tempmon'] = rattail_tempmon.__version__ + for key in packages: + packages[key] = packages[key] + '+dev' + return packages + + +def includeme(config): + CommonView.defaults(config) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5dfa765 --- /dev/null +++ b/setup.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8; -*- +""" +Rattail Tempmon Demo setup script +""" + +from __future__ import unicode_literals, absolute_import + +import os +from setuptools import setup, find_packages + + +here = os.path.abspath(os.path.dirname(__file__)) +execfile(os.path.join(here, 'rattail_tempmon_demo', '_version.py')) +README = open(os.path.join(here, 'README.rst')).read() + + +requires = [ + # + # Version numbers within comments below have specific meanings. + # Basically the 'low' value is a "soft low," and 'high' a "soft high." + # In other words: + # + # If either a 'low' or 'high' value exists, the primary point to be + # made about the value is that it represents the most current (stable) + # version available for the package (assuming typical public access + # methods) whenever this project was started and/or documented. + # Therefore: + # + # If a 'low' version is present, you should know that attempts to use + # versions of the package significantly older than the 'low' version + # may not yield happy results. (A "hard" high limit may or may not be + # indicated by a true version requirement.) + # + # Similarly, if a 'high' version is present, and especially if this + # project has laid dormant for a while, you may need to refactor a bit + # when attempting to support a more recent version of the package. (A + # "hard" low limit should be indicated by a true version requirement + # when a 'high' version is present.) + # + # In any case, developers and other users are encouraged to play + # outside the lines with regard to these soft limits. If bugs are + # encountered then they should be filed as such. + # + # package # low high + + 'psycopg2', # 2.6.2 + 'rattail', # 0.7.25 + 'Tailbone', # 0.5.29 +] + + +setup( + name = "rattail-tempmon-demo", + version = __version__, + author = "Lance Edgar", + author_email = "lance@edbob.org", + url = "https://rattailproject.org/", + description = "Demo for Rattail Tempmon", + long_description = README, + + classifiers = [ + 'Private :: Do Not Upload', + 'Development Status :: 3 - Alpha', + 'Environment :: Console', + 'Environment :: Web Environment', + 'Framework :: Pyramid', + 'Intended Audience :: Developers', + 'Natural Language :: English', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Topic :: Office/Business', + ], + + install_requires = requires, + packages = find_packages(), + + entry_points = { + + 'rattail.config.extensions': [ + 'rattail_tempmon_demo = rattail_tempmon_demo.config:RattailTempmonDemoConfig', + ], + + 'paste.app_factory': [ + 'main = rattail_tempmon_demo.web.app:main', + ], + }, +)