Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for the Mako templating engine. hooray for mvc

  • Loading branch information...
commit df24c77d96acb2b70a53bb79edee886472eee366 1 parent 3e95ee5
@MusikPolice authored
Showing with 55 additions and 4 deletions.
  1. +6 −0 .gitignore
  2. +28 −4 musik.py
  3. +21 −0 templates/index.html
View
6 .gitignore
@@ -25,3 +25,9 @@ pip-log.txt
#Mr Developer
.mr.developer.cfg
+
+#Database files
+*.db
+
+#Mako templates compilation directory
+templates/compiled/
View
32 musik.py
@@ -3,6 +3,9 @@
import cherrypy
from cherrypy.process import wspbus, plugins
+
+from mako.template import Template
+from mako.lookup import TemplateLookup
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
@@ -13,6 +16,9 @@
# Helper to map and register a Python class a db table
Base = declarative_base()
+# Template looker-upper that handles loading and caching of mako templates
+templates = TemplateLookup(directories=['templates'], module_directory='templates/compiled')
+
# Represents a media file on the local hard drive
class Media(Base):
__tablename__ = 'media'
@@ -46,7 +52,7 @@ def __init__(self, bus):
self.bus.subscribe("bind", self.bind)
def start(self):
- db_path = os.path.abspath(os.path.join(os.curdir, 'my.db'))
+ db_path = os.path.abspath(os.path.join(os.curdir, 'musik.db'))
self.sa_engine = create_engine('sqlite:///%s' % db_path, echo=True)
Base.metadata.create_all(self.sa_engine)
@@ -84,11 +90,25 @@ def commit_transaction(self):
self.session.remove()
+# provides functionality for adding new media to the database
+class Import:
+
+ @cherrypy.expose
+ def directory(self, path):
+ return "Importing the directory %s" % path
+
+ @cherrypy.expose
+ def file(self, path):
+ return "Importing the file %s" % path
+
+
# defines an api with a dynamic url scheme composed of /<tag>/<value>/ pairs
# these pairs are assembled into an SQL query. Each term is combined with the AND operator.
# unknown <tag> elements are ignored.
class API:
+ importmedia = Import()
+ @cherrypy.expose
def default(self, *params):
#TODO: pull all available tags from the database so this regex is dynamic and allows any tag
regex = re.compile("genre|artist|album|track")
@@ -105,7 +125,6 @@ def default(self, *params):
str += "* <br />"
return str
- default.exposed = True
# defines the web application that is the default client
@@ -114,8 +133,13 @@ class Musik:
@cherrypy.expose
def index(self):
- media = [str(path) for path in Media.list(cherrypy.request.db)]
- return "Media in the library: %s" % '\n'.join(media)
+ #media = [str(path) for path in Media.list(cherrypy.request.db)]
+ #return "Media in the library: %s" % '\n'.join(media)
+ return templates.get_template('index.html').render()
+
+ @cherrypy.expose
+ def importmedia(self):
+ return ""
# application entry - starts the database connection and dev server
View
21 templates/index.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Musik!</title>
+ </head>
+ <body>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
+
+ <h1>Welcome to Musik!</h1>
+ <h2>The worlds' finest web-based music player</h2>
+ <p>
+ It may not look like much right now, but eventually, this bad boy will be capable of managing and streaming all of your precious media files to you, no matter where you are in the world.
+ </p>
+
+ <h3>Try it out:</h3>
+ <ul>
+ <li>Import Files</li>
+ </ul>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.