Skip to content
Permalink
Browse files

Refactor to cleanup the directory structure

Put HTML Templates and CSS into separate folders from the root
  • Loading branch information...
wwsean08 committed Sep 23, 2016
1 parent bb1d6c8 commit 3d1c4ef81e9e2c03cc179f08b29e062825161141
File renamed without changes.
39 go.py
@@ -776,7 +776,7 @@ def undirect(self):
raise cherrypy.HTTPRedirect(cherrypy.request.headers.get("Referer", "/"))

def notfound(self, msg):
return env.get_template("notfound.html").render(message=msg)
return env.get_template("html/notfound.html").render(message=msg)

def redirectIfNotFullHostname(self, scheme=None):
if scheme is None:
@@ -813,12 +813,6 @@ def favicon_ico(self):
cherrypy.response.headers["Cache-control"] = "max-age=172800"
return self.redirect(cfg_urlFavicon, status=301)

@cherrypy.expose
def bootstrap_css(self):
cherrypy.response.headers["Cache-control"] = "max-age=172800"
cherrypy.response.headers["Content-Type"] = "text/css"
return file("bootstrap.min.css").read()

@cherrypy.expose
def lucky(self):
luckylink = random.choice(g_db.getNonFolders())
@@ -832,7 +826,7 @@ def index(self, **kwargs):
if "keyword" in kwargs:
return self.redirect("/" + kwargs["keyword"])

return env.get_template('index.html').render(now=today())
return env.get_template('html/index.html').render(now=today())

@cherrypy.expose
def default(self, *rest, **kwargs):
@@ -873,7 +867,7 @@ def default(self, *rest, **kwargs):
return self.notfound("No match found for '%s'" % keyword)

# serve up empty fake list
return env.get_template('list.html').render(L=ListOfLinks(0), keyword=kw)
return env.get_template('html/list.html').render(L=ListOfLinks(0), keyword=kw)
elif len(matches) == 1:
R, L, genL = matches[0] # actual regex, generated link
R.clicked()
@@ -882,7 +876,7 @@ def default(self, *rest, **kwargs):
else: # len(matches) > 1
LL = ListOfLinks(-1) # -1 means non-editable
LL.links = [genL for R, L, genL in matches]
return env.get_template('list.html').render(L=LL, keyword=keyword)
return env.get_template('html/list.html').render(L=LL, keyword=keyword)

listtarget = ll.getDefaultLink()

@@ -891,7 +885,7 @@ def default(self, *rest, **kwargs):
listtarget.clicked()
return self.redirect(deampify(listtarget.url()))

tmplList = env.get_template('list.html')
tmplList = env.get_template('html/list.html')
return tmplList.render(L=ll, keyword=keyword)

@cherrypy.expose
@@ -901,7 +895,7 @@ def special(self):
LL.links = g_db.getSpecialLinks()

env.globals['g_db'] = g_db
return env.get_template('list.html').render(L=LL, keyword="special")
return env.get_template('html/list.html').render(L=LL, keyword="special")

@cherrypy.expose
def _login_(self, redirect=""):
@@ -925,23 +919,23 @@ def _add_(self, *args, **kwargs):
# _add_/tag1/tag2/tag3
link = Link()
link.lists = [g_db.getList(listname, create=False) or ListOfLinks(0, listname) for listname in args]
return env.get_template("editlink.html").render(L=link, returnto=(args and args[0] or None), **kwargs)
return env.get_template("html/editlink.html").render(L=link, returnto=(args and args[0] or None), **kwargs)

@cherrypy.expose
def _edit_(self, linkid, **kwargs):
link = g_db.getLink(linkid)
if link:
return env.get_template("editlink.html").render(L=link, **kwargs)
return env.get_template("html/editlink.html").render(L=link, **kwargs)

# edit new link
return env.get_template("editlink.html").render(L=Link(), **kwargs)
return env.get_template("html/editlink.html").render(L=Link(), **kwargs)

@cherrypy.expose
def _editlist_(self, keyword, **kwargs):
K = g_db.getList(keyword, create=False)
if not K:
K = ListOfLinks()
return env.get_template("list.html").render(L=K, keyword=keyword)
return env.get_template("html/list.html").render(L=K, keyword=keyword)

@cherrypy.expose
def _setbehavior_(self, keyword, **kwargs):
@@ -1045,26 +1039,26 @@ def _modify_(self, **kwargs):
@cherrypy.expose
def _internal_(self, *args, **kwargs):
# check, toplinks, special, dumplist
return env.get_template(args[0] + ".html").render(**kwargs)
return env.get_template("html/" + args[0] + ".html").render(**kwargs)

@cherrypy.expose
def toplinks(self, n="100"):
return env.get_template("toplinks.html").render(n=int(n))
return env.get_template("html/toplinks.html").render(n=int(n))

@cherrypy.expose
def variables(self):
return env.get_template("variables.html").render()
return env.get_template("html/variables.html").render()

@cherrypy.expose
def help(self):
return env.get_template("help.html").render()
return env.get_template("html/help.html").render()

@cherrypy.expose
def _override_vars_(self, **kwargs):
cherrypy.response.cookie["variables"] = urllib.urlencode(kwargs)
cherrypy.response.cookie["variables"]["max-age"] = 10 * 365 * 24 * 3600

return self.redirect("/variables")
return self.redirect("variables")

@cherrypy.expose
def _set_variable_(self, varname="", value=""):
@@ -1096,7 +1090,8 @@ def main():
cherrypy.process.plugins.BackgroundTask(60, lambda: g_db.save()).start()

file_path = os.getcwd().replace("\\", "/")
conf = {'/images': {"tools.staticdir.on": True, "tools.staticdir.dir": file_path+"/images"}}
conf = {'/images': {"tools.staticdir.on": True, "tools.staticdir.dir": file_path + "/images"},
'/css': {"tools.staticdir.on": True, "tools.staticdir.dir": file_path + "/css"}}
print "Cherrypy conf: %s" % conf
cherrypy.quickstart(Root(), "/", config=conf)

@@ -1,7 +1,7 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en"><head>
<title>{% block title %}go/{% block titlekeyword %}{% endblock titlekeyword %}{% endblock title %}</title>
<link rel="stylesheet" href="/bootstrap.css" media="screen"/>
<link rel="stylesheet" href="/css/bootstrap.min.css" media="screen"/>
<link rel="shortcut icon" href="http://www.f5.com/favicon.ico" />

<style type="text/css">
@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% set username = getSSOUsername() %}

@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% block keyword %}:dumplist{% endblock %}
{% block css %}
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% from "listinc.html" import clickstats %}
{% extends "html/base.html" %}
{% from "html/listinc.html" import clickstats %}

<!-- {% set username = getSSOUsername() %} -->

@@ -79,7 +79,7 @@

<div class="column span6">
<div class="inner">
{% include "vartable.html" %}
{% include "html/vartable.html" %}
<p>also see <a href="http://docs.python.org/2/library/string.html#format-specification-mini-language">Python Format Syntax</a> for variable formatting
and <a href="http://docs.python.org/library/re.html#regular-expression-syntax">Python Regex Syntax</a> for regexes
</div>
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% from "listinc.html" import editlink %}
{% from "html/listinc.html" import editlink %}

{% block title %}go/help{% endblock title %}

@@ -1,10 +1,10 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% set username = getSSOUsername(False) %}
{% set topLinks = byClicks(g_db.getNonFolders()) %}
{% set folderLinks = byClicks(g_db.getSpecialLinks()) %}

{% from "listinc.html" import renderlink %}
{% from "html/listinc.html" import renderlink %}

{% block keyword %}<form style="display: inline;" action="/"><input type="text" name="keyword" size="12" value=""/></form>{% endblock %}

@@ -1,9 +1,9 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% set popularLinks = L.getPopularLinks() %}
<!-- {% set username = getSSOUsername(False) %} -->

{% from "listinc.html" import renderlink, clickstats with context %}
{% from "html/listinc.html" import renderlink, clickstats with context %}

{% block titlekeyword %}{{ keyword }}{% endblock %}
{% block keyword %}{{ keyword }}{% endblock %}
File renamed without changes.
@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% block title %}Not Found{% endblock title %}
{# block keyword %}{{ keyword }}{% endblock keyword #}
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% from "listinc.html" import editlink %}
{% from "html/listinc.html" import editlink %}

{% set username = getSSOUsername() %}

@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% extends "html/base.html" %}

{% from "listinc.html" import renderlink with context %}
{% from "html/listinc.html" import renderlink with context %}
{% set username = getSSOUsername(False) %}

{% block keyword %}toplinks{% endblock keyword %}
@@ -1,10 +1,10 @@

{% extends "base.html" %}
{% extends "html/base.html" %}
{% set username = getSSOUsername(False) %}

{% block keyword %}variables{% endblock keyword %}
{% block body %}
{% include "vartable.html" %}
{% include "html/vartable.html" %}
{% if username %}
<hr/>

File renamed without changes.
@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "html/base.html" %}
{% block keyword %}{{ regex }}{% endblock %}
{% block body %}

0 comments on commit 3d1c4ef

Please sign in to comment.
You can’t perform that action at this time.