Permalink
Browse files

Various changes (Not very helpfull comment I know, I'll do better nex…

…t time)
  • Loading branch information...
varunpant committed Jan 20, 2013
1 parent c85fe5f commit 9f79202c1d0fa82ea0eb29b23aea2d96f0f4d711
View
@@ -1,4 +1,7 @@
*.py[co]
+blog.css
+varunpant.jpg
+BlogML.xml
# Packages
*.egg
@@ -34,4 +37,6 @@ pip-log.txt
.idea
.pydevproject
node_modules
-out
+.font-awesome
+out
+p
View
7 app.py
@@ -38,14 +38,19 @@
'/admin/settings', 'controllers.admin_controller.Settings',
'/sitemap.xml', 'controllers.api_controller.Sitemap',
+ '/sitemap', 'controllers.api_controller.Sitemap',
+ '/sitemap.xsd', 'controllers.api_controller.Sitemap',
'/sitemap.xsl', 'controllers.api_controller.SitemapStyle',
'/rsd.xml', 'controllers.api_controller.Rsd',
'/rsd.axd', 'controllers.api_controller.Rsd',
'/wlwmanifest.xml', 'controllers.api_controller.Wlwmanifest',
'/metaweblog.xml', 'controllers.api_controller.Metaweblog',
'/feed.xml', 'controllers.api_controller.Feed',
+ '/feed', 'controllers.api_controller.Feed',
'/opensearch.axd', 'controllers.api_controller.Opensearch',
+ '/opensearch', 'controllers.api_controller.Opensearch',
'/robots.txt', 'controllers.api_controller.Robots',
+ '/robots', 'controllers.api_controller.Robots',
'/(.+)', 'controllers.main_controller.PageSlug'
)
@@ -55,7 +60,7 @@
from controllers import main_controller
app.notfound = main_controller.notfound
-#app.internalerror = main_controller.internalerror
+app.internalerror = main_controller.internalerror
#application = app.wsgifunc()
@@ -8,7 +8,8 @@
# General Housekeeping ########################################################
###############################################################################
-blog_settings = settings_service.get_settings()
+blog_settings = settings_service.Settings().get_settings()
+
start_index = shared_helper.start_index
safe_number = shared_helper.safe_number
total_page = shared_helper.total_page
@@ -256,7 +257,7 @@ def GET(self):
@requires_auth
class Settings:
def GET(self):
- settings = settings_service.get_settings()
+ settings = settings_service.Settings().get_settings()
return render.settings(settings, False)
def POST(self):
@@ -10,7 +10,7 @@
all_cap_re = re.compile('([a-z0-9])([A-Z])')
before_dot = re.compile('(metaWeblog|blogger|mt|wp)\.')
-blog_settings = settings_service.get_settings()
+blog_settings = settings_service.Settings().get_settings()
global_settings = {'settings': blog_settings}
render = web.template.render('views/api', globals=global_settings)
@@ -23,6 +23,7 @@
class Sitemap:
def GET(self):
+ web.header('Content-Type', 'text/xml;charset=utf-8')
posts = post_service.get_all_published()
pages = page_service.get_all_published()
tags = tag_service.get_all()
@@ -34,7 +35,8 @@ def GET(self):
return render.sitemapXsl()
class Rsd:
- def GET(self):
+ def GET(self):
+ web.header('Content-Type', 'text/xml;charset=utf-8')
return render.rsd()
class Wlwmanifest:
@@ -45,18 +47,18 @@ class Metaweblog:
def POST(self):
web.header('Content-Type', 'text/xml;charset=utf-8')
xml = web.data()
- #print xml
+
if xml:
command = xmlrpclib.loads(xml)
name = before_dot.sub("", command[1])
- method = all_cap_re.sub(r'\1_\2', first_cap_re.sub(r'\1_\2', name)).lower()
- print method,":",command
+ method = all_cap_re.sub(r'\1_\2', first_cap_re.sub(r'\1_\2', name)).lower()
return metaweblog_service.__dict__[method](command[0])
else:
raise web.notfound("Invalid Post content.")
class Feed:
def GET(self):
+ web.header('Content-Type', 'text/xml;charset=utf-8')
posts = post_service.get_all(0, blog_settings.items_per_page)
if posts:
return render.atom(posts)
@@ -65,6 +67,7 @@ def GET(self):
class Opensearch:
def GET(self):
+ web.header('Content-Type', 'text/xml;charset=utf-8')
return render.opensearch()
class Robots:
@@ -1,24 +1,23 @@
import web, calendar
-from services import shared_helper, post_service, tag_service, page_service, settings_service, search_service
-
+from services import shared_helper, post_service, tag_service, page_service, search_service, blog_cache, settings_service
###############################################################################
# General Housekeeping ########################################################
###############################################################################
-blog_settings = settings_service.get_settings()
+blog_settings = settings_service.Settings().get_settings()
start_index = shared_helper.start_index
safe_number = shared_helper.safe_number
total_page = shared_helper.total_page
-global_settings = {'settings': blog_settings }
+global_settings = {'settings': blog_settings, 'blog_cache':blog_cache.Cache() }
render = web.template.render('views/themes/light', base='base', globals=global_settings)
def notfound(msg):
raise web.notfound(render.notfound(msg))
-def internalerror(msg):
- raise web.internalerror("Bad, bad server. No donut for you.\n" + msg)
+def internalerror():
+ return web.internalerror(render.notfound("Bad, bad server. No donut for you."))
###############################################################################
# Routes Handlers #############################################################
@@ -69,21 +68,22 @@ def GET(self, slug, page):
page_count = total_page(count, blog_settings.items_per_page)
nextLink = previousLink = None
if page < page_count:
- nextLink = "/archives/" + str(page + 1)
+ nextLink = "/topics/" + slug + "/" + str(page + 1)
if page > 1 :
- previousLink = "/archives/" + str(page - 1)
+ previousLink = "/topics/" + slug + "/" + str(page - 1)
return render.index(posts, nextLink, previousLink)
else:
return notfound("The requested tag: " + slug + " was not found.")
class Archives:
def GET(self):
- posts = post_service.find_recent(blog_settings.items_per_page)
+ posts = post_service.get_all_published()
_archives = post_service.get_archives()
archives = []
+ tags = tag_service.get_published()
for archive in _archives:
- archives.append({'full_month':calendar.month_name[archive.month],'month':archive.month, 'year':archive.year, 'posts_count':archive.posts_count})
- return render.archive(posts, archives)
+ archives.append({'full_month':calendar.month_name[archive.month], 'month':archive.month, 'year':archive.year, 'posts_count':archive.posts_count})
+ return render.archive(posts, tags, archives)
class ArchivePage:
def GET(self, page):
@@ -119,7 +119,7 @@ def GET(self, page, year):
offset = start_index(page, blog_settings.items_per_page)
limit = blog_settings.items_per_page
posts = post_service.find_published_by_year(year, offset, limit)
- page_count = total_page(count,limit)
+ page_count = total_page(count, limit)
nextLink = previousLink = None
if page < page_count:
nextLink = "/archives/" + str(page + 1)
@@ -171,7 +171,7 @@ def GET(self, page, year, month, day):
return notfound("No archived posts were found.")
offset = start_index(page, blog_settings.items_per_page)
limit = blog_settings.items_per_page
- posts = post_service.find_published_by_year_month_and_day(safe_year, safe_month, safe_day, offset,limit)
+ posts = post_service.find_published_by_year_month_and_day(safe_year, safe_month, safe_day, offset, limit)
page_count = total_page(count, limit)
nextLink = previousLink = None
if page < page_count:
@@ -234,4 +234,4 @@ def GET(self):
msg = "No results were found for query \" " + q + " \""
- return render.search(q,count, result, nextLink, previousLink, msg)
+ return render.search(q, count, result, nextLink, previousLink, msg)
@@ -8,7 +8,7 @@
all_cap_re = re.compile('([a-z0-9])([A-Z])')
before_dot = re.compile('(metaWeblog|blogger|mt|wp)\.')
-blog_settings = settings_service.get_settings()
+blog_settings = settings_service.Settings().get_settings()
global_settings = {'settings': blog_settings}
safe_number = shared_helper.safe_number
render = web.template.render('views/api', globals=global_settings)
View
@@ -78,7 +78,7 @@ def count_published_by_tag(slug):
def get_archives():
session = getSession()
- return session.query(Archives).filter(Archives.posts_count > 0).order_by(Archives.month.desc(), Archives.year.desc()).all()
+ return session.query(Archives).filter(Archives.posts_count > 0).order_by(Archives.year.desc(),Archives.month.desc()).all()
###############################################################################
@@ -115,8 +115,8 @@ def update(postId, title, slug, content, published_at, excerpt, tags):
post.slug = shared_helper.to_url(post.slug) if isNotNull(post.slug) else shared_helper.to_url(post.title)
if tags is not None and len(tags)>0 :
tags = unique_tags(tags)
- tags_to_remove = filter(lambda t: t not in tags,post.tags)
- tags_to_add = filter(lambda t: not any(filter(lambda pt:pt == t,post.tags)),tags)
+ tags_to_remove = filter(lambda t: t.title.lower() not in tags,post.tags)
+ tags_to_add = filter(lambda t: not any(filter(lambda pt:pt.title.lower() == t,post.tags)),tags)
remove_tags(session,post, tags_to_remove)
add_tags(session,post, tags_to_add)
else:
@@ -194,7 +194,7 @@ def __commit(session,o):
session.commit()
return True
except Exception,e:
- print e
+ raise
return False
def __destroy(session,o):
@@ -203,6 +203,6 @@ def __destroy(session,o):
session.commit()
return True
except Exception,e:
- print e
+ raise
return False
@@ -2,29 +2,7 @@
# Settings Querying Service #######################################################
###############################################################################
from models import getSession , Setting
-
-
-class CacheFetcher:
- def __init__(self):
- self.cache = None
- def fetch(self):
- if self.cache:
- return self.cache
- # Retrieve and cache
- session = getSession()
- #print "############# cached #############"
- self.cache = session.query(Setting).scalar()
- return self.cache
-
- def clear(self):
- self.cache = None
-
-def get_settings():
- return CacheFetcher().fetch()
-
-def reset():
- CacheFetcher().clear()
-
+
def update_settings(settings):
session = getSession()
current_settings = session.query(Setting).scalar()
@@ -51,13 +29,47 @@ def update_settings(settings):
try:
session.add(current_settings)
session.commit()
- reset();
- return get_settings()
+ s = Settings()
+ s.clear();
+ return s.get_settings()
except Exception, e:
print e
return None
- pass
-
-
+class Settings:
+
+ class __impl:
+ def __init__(self):
+ self.cache = None
+ def get_settings(self):
+ if self.cache:
+ return self.cache
+ # Retrieve and cache
+ session = getSession()
+ self.cache = session.query(Setting).scalar()
+ return self.cache
+
+ def clear(self):
+ self.cache = None
+
+ # storage for the instance reference
+ __instance = None
+
+ def __init__(self):
+ """ Create Settings instance """
+ # Check whether we already have an instance
+ if Settings.__instance is None:
+ # Create and remember instance
+ Settings.__instance = Settings.__impl()
+
+ # Store instance reference as the only member in the handle
+ self.__dict__['_Singleton__instance'] = Settings.__instance
+
+ def __getattr__(self, attr):
+ """ Delegate access to implementation """
+ return getattr(self.__instance, attr)
+
+ def __setattr__(self, attr, value):
+ """ Delegate access to implementation """
+ return setattr(self.__instance, attr, value)
View
@@ -17,7 +17,7 @@ def get_all():
def get_published():
session = getSession()
- return session.query(Tag).filter(Tag.posts.any(Post.published_at != None)).order_by(Tag.title.desc()).all()
+ return session.query(Tag).filter(Tag.posts.any(Post.published_at != None)).order_by(Tag.posts_count.desc()).all()
def get_unpublished():
session = getSession()
View
@@ -15,6 +15,7 @@
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="/static/css/admin.css" rel="stylesheet">
+ <link rel="shortcut icon" href="/static/ico/favicon.ico">
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
Oops, something went wrong.

0 comments on commit 9f79202

Please sign in to comment.