Permalink
Browse files

Ensuring we declare which version of Django (0.96) to use.

  • Loading branch information...
1 parent 45a64b4 commit 5db38742ade3e8072cd7d70dac2e276e6f543243 @detro committed May 25, 2012
Showing with 77 additions and 42 deletions.
  1. +6 −0 admin.py
  2. +5 −1 deferred.py
  3. +6 −0 empty_favicon.py
  4. +11 −9 handlers.py
  5. +2 −0 markup.py
  6. +4 −2 migrate.py
  7. +22 −17 minifier.py
  8. +14 −8 static.py
  9. +7 −5 utils.py
View
@@ -1,3 +1,9 @@
+# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+from google.appengine.dist import use_library
+use_library('django', '0.96')
+
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
View
@@ -21,7 +21,11 @@
"""
-
+# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+from google.appengine.dist import use_library
+use_library('django', '0.96')
from google.appengine.ext import deferred
View
@@ -1,3 +1,9 @@
+# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+from google.appengine.dist import use_library
+use_library('django', '0.96')
+
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
View
@@ -13,6 +13,8 @@
from generators import generator_list
# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '0.96')
from django import newforms as forms
@@ -28,7 +30,7 @@ class PostForm(djangoforms.ModelForm):
class Meta:
model = models.BlogPost
fields = [ 'title', 'body', 'tags' ]
-
+
class PageForm(djangoforms.ModelForm):
# Overridden constructor to initialise the Form properly
@@ -37,10 +39,10 @@ def __init__(self, current_page, *args, **kwargs):
if ( current_page ):
# Show all the pages, except the one associated with the current form instance
self.base_fields['parent_page'].query.filter("__key__ != ", current_page.key());
-
+
self.base_fields['parent_page'].widget.choices = self.base_fields['parent_page'].choices;
super(PageForm, self).__init__(*args, **kwargs);
-
+
title = forms.CharField( widget=forms.TextInput( attrs={'id':'name'} ));
parent_page = djangoforms.ModelChoiceField( models.Page, None, required=False, initial=None, empty_label="none" );
body = forms.CharField( widget=forms.Textarea( attrs={'id':'message', 'rows': 10, 'cols': 20} ));
@@ -61,7 +63,7 @@ def decorate(self, post_id=None):
return
fun(self, post)
return decorate
-
+
def with_page(fun):
def decorate(self, page_id=None):
@@ -93,7 +95,7 @@ class AdminHandler(BaseHandler):
def get(self):
# Entry per page
entry_per_page = 10
-
+
posts_offset = int(self.request.get('posts_start', 0));
posts_count = int(self.request.get('posts_count', entry_per_page));
posts = models.BlogPost.all().order('-published').fetch(posts_count, posts_offset);
@@ -200,15 +202,15 @@ def post(self, page):
form = PageForm(current_page=page, data=self.request.POST, instance=page, initial={'draft': page and page.published is None});
if form.is_valid():
page = form.save(commit=False);
-
+
# Ensure that a 'Child Page' is never assigned as 'Parent Page' as well
page.put();
for p in page.child_pages:
if page.parent_page and page.parent_page.key() == p.key():
page.parent_page = None;
page.put();
break;
-
+
if form.clean_data['draft']:
# Page is marked as DRAFT
page.published = datetime.datetime.max
@@ -253,9 +255,9 @@ class RegenerateHandler(BaseHandler):
def post(self):
# Force the regeneration of all the content
post_deploy.regenerate_all(force=True)
-
+
# Post-Deploy tasks (i.e. regenerate static pages)
deferred.defer(post_deploy.try_post_deploy, force=True);
- # Render a "regenerating" page
+ # Render a "regenerating" page
self.render_to_response("regenerating.html")
View
@@ -20,6 +20,8 @@
from cStringIO import StringIO
# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '0.96')
from django.utils import html
View
@@ -10,6 +10,8 @@
from google.appengine.ext import deferred
# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '0.96')
from django.utils import simplejson
@@ -40,7 +42,7 @@ def disqus_request(method, request_type=urlfetch.GET, **kwargs):
if not result['succeeded']:
raise Exception("RPC did not succeed", result)
return result
-
+
class BaseMigration(object):
@@ -130,7 +132,7 @@ def migrate_one(self, article):
deps={})
post.put()
deferred.defer(self.migrate_all_comments, article.key(), article.title)
-
+
def migrate_all(self, batch_size=20, start_key=None):
q = BloogBreakingMigration.Article.all()
if start_key:
View
@@ -1,6 +1,11 @@
+# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+from google.appengine.dist import use_library
+use_library('django', '0.96')
+
import logging
import wsgiref.handlers
-import os
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
@@ -18,7 +23,7 @@
Request Handler for Minified CSS
This allows to apply Templating and Minification to CSS Stylesheets.
"""
-class CssMinifier( webapp.RequestHandler ):
+class CssMinifier( webapp.RequestHandler ):
def get( self, requestedCssFilename ):
logging.debug("Requested CSS Path: "+requestedCssFilename);
# Build the Path to the CSS and check if we already have rendered it and is sitting in Memcache ready to use
@@ -27,15 +32,15 @@ def get( self, requestedCssFilename ):
logging.error("CSS not found: "+cssPath);
self.error(404); # Client Error 4xx - 404 Not Found
return;
-
+
cssRenderingResult = None;
# Check if Memcaching is enabled
if ( config.memcaching ):
cssRenderingResult = memcache.get(cssPath);
-
+
# In case the Memcache didn't contain the CSS rendered
- if ( cssRenderingResult is None ):
- logging.debug("Rendering CSS: "+cssPath);
+ if ( cssRenderingResult is None ):
+ logging.debug("Rendering CSS: "+cssPath);
# Render the CSS
cssRenderingResult = template.render(cssPath, { 'config' : config });
@@ -46,11 +51,11 @@ def get( self, requestedCssFilename ):
try:
cssRenderingResult = cssmin.minify(cssRenderingResult);
except:
- logging.warning("CSS Minification failed: " + requestedCssFilename);
-
+ logging.warning("CSS Minification failed: " + requestedCssFilename);
+
# Save in Memcache
memcache.set(cssPath, cssRenderingResult);
-
+
# Setting Content-Type as "text/javascript"
self.response.headers['Content-Type'] = 'text/css'
logging.debug("Serving Minified CSS: "+cssPath);
@@ -62,7 +67,7 @@ def get( self, requestedCssFilename ):
Request Handler for "./js/*".
This allows to apply Templating and Minification to Javascript.
"""
-class JSMinifier( webapp.RequestHandler ):
+class JSMinifier( webapp.RequestHandler ):
def get( self, requestedJsFilename ):
logging.debug("Requested Javascript: "+requestedJsFilename);
# Build the Path to the Javascript and check if we already have rendered it and is sitting in Memcache ready to use
@@ -71,14 +76,14 @@ def get( self, requestedJsFilename ):
logging.error("Javascript not found: "+jsPath);
self.error(404); # Client Error 4xx - 404 Not Found
return;
-
+
jsRenderingResult = None;
if ( config.memcaching ):
jsRenderingResult = memcache.get(jsPath);
-
+
# In case the Memcache didn't contain the Javascript rendered
- if ( jsRenderingResult is None ):
- logging.debug("Rendering Javascript: "+requestedJsFilename);
+ if ( jsRenderingResult is None ):
+ logging.debug("Rendering Javascript: "+requestedJsFilename);
# Render the Javascript
jsRenderingResult = template.render(jsPath, { 'config' : config });
@@ -89,11 +94,11 @@ def get( self, requestedJsFilename ):
try:
jsRenderingResult = jsmin.jsmin(jsRenderingResult);
except:
- logging.warning("Javascript Minification failed: " + requestedJsFilename);
-
+ logging.warning("Javascript Minification failed: " + requestedJsFilename);
+
# Save in Memcache
memcache.set(jsPath, jsRenderingResult);
-
+
# Setting Content-Type as "text/javascript"
self.response.headers['Content-Type'] = 'application/javascript'
logging.debug("Serving Minified Javascript: "+jsPath);
View
@@ -1,3 +1,9 @@
+# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+from google.appengine.dist import use_library
+use_library('django', '0.96')
+
import datetime
import hashlib
@@ -18,11 +24,11 @@
HTTP_DATE_FMT = "%a, %d %b %Y %H:%M:%S GMT"
-TYPE_HOME = 0x0001 # 'Homepage'
-TYPE_POST = 0x0002 # 'Post'
-TYPE_PAGE = 0x0004 # 'Page'
-TYPE_INDEX = 0x008 # 'Index' (i.e. Listing, Pagination, Tag, Archive, Search)
-TYPE_OTHER = 0x0010 # 'Other' (i.e. atom feed, robots.txt, ...)
+TYPE_HOME = 0x0001 # 'Homepage'
+TYPE_POST = 0x0002 # 'Post'
+TYPE_PAGE = 0x0004 # 'Page'
+TYPE_INDEX = 0x008 # 'Index' (i.e. Listing, Pagination, Tag, Archive, Search)
+TYPE_OTHER = 0x0010 # 'Other' (i.e. atom feed, robots.txt, ...)
SITEMAP_DATA_MAPPING = {
TYPE_HOME : { "priority" : 1, "changefreq" : "daily" },
@@ -61,9 +67,9 @@ def get(path):
A StaticContent object, or None if no content exists for this path.
"""
entity = None;
- if ( config.memcaching ):
+ if ( config.memcaching ):
entity = memcache.get(path);
-
+
if entity:
entity = db.model_from_protobuf(entity_pb.EntityProto(entity))
else:
@@ -164,7 +170,7 @@ def _dec(self, path):
class StaticContentHandler(webapp.RequestHandler):
PAGE_NOT_FOUND_404_PATH = "404.html";
-
+
def output_content(self, content, serve=True):
if content.content_type:
self.response.headers['Content-Type'] = content.content_type
View
@@ -8,6 +8,8 @@
from google.appengine.ext.webapp.template import _swap_settings
# Bloggart is currently based on Django 0.96
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '0.96')
import django.conf
@@ -55,10 +57,10 @@ def format_post_path(post, num):
def get_template_vals_defaults(template_vals=None):
import models;
-
+
if template_vals is None:
template_vals = {}
-
+
template_vals.update({
'config': config,
'devel': os.environ['SERVER_SOFTWARE'].startswith('Devel'),
@@ -102,7 +104,7 @@ def _regenerate_sitemap():
import static
import gzip
from StringIO import StringIO
-
+
static_contents = _get_all_static_content_data()
rendered = render_template('sitemap.xml', {'static_contents': static_contents})
static.set('/sitemap.xml', rendered, 'application/xml', indexed=False, type=static.TYPE_OTHER)
@@ -179,7 +181,7 @@ def _dec(content):
data = None;
if ( config.memcaching ):
data = memcache.get(content.path, namespace=self.namespace);
-
+
if data:
return data
else:
@@ -209,7 +211,7 @@ def clear_post_memoizer_cache(post):
post_summary_memoizer.delete(post);
post_hash_memoizer.delete(post);
post_summary_hash_memoizer.delete(post);
-
+
def clear_page_memoizer_cache(page):
page_body_memoizer.delete(page);
page_hash_memoizer.delete(page);

0 comments on commit 5db3874

Please sign in to comment.