Anonymous avatar Anonymous committed fabd23c

- refactor admin template
- cache context
- nicer button
- navbar config for pages

Comments (0)

Files changed (23)

context/context_processors.py

 # this is a context processor for template
 from pages.models import Page
+from google.appengine.api import memcache
 
 def pages(request):
-    pages = Page.all().filter('publish =', True)
+    if memcache.get('context_pages'):
+        context_pages = memcache.get('context_pages')
+    else:
+        pages = Page.all().filter('publish =', True)
 
-    # get all page titles and url
-    context_pages = []
+        # get all page titles and url
+        context_pages = []
 
-    if pages :
-        for page in pages:
-            context_pages.append({'name':page.name,
-                                  'url':page.get_absolute_url()})
+        if pages :
+            for page in pages:
+                context_pages.append({'name':page.name,
+                                      'url':page.get_absolute_url()})
+            memcache.set('context_pages', context_pages)
 
     return {'context_pages':context_pages}
Add a comment to this file

context/context_processors.pyc

Binary file modified.

pages/contactform.py

 
 
 class ContactForm(forms.Form):
-    name = forms.CharField(max_length=100)
-    email = forms.EmailField()
+    name = forms.CharField(label="Your Name",max_length=100)
+    email = forms.EmailField(label="Your Email")
     message = forms.CharField(widget=forms.Textarea)

Binary file modified.

     body = db.TextProperty()
     body_html = db.TextProperty()
     template = db.StringProperty()
+    navbar = db.BooleanProperty()
     publish = db.BooleanProperty()
     created = db.DateTimeProperty(auto_now_add=True)
     author = db.UserProperty(auto_current_user_add=True)

Binary file modified.

pages/pageform.py

     description = forms.CharField(max_length=300, required=False)
     body = forms.CharField(widget=forms.Textarea)
     template = forms.CharField(max_length=30)
+    navbar = forms.BooleanField(required=False)
     publish = forms.BooleanField(required=False)
 
     def save(self, page=None, commit=True):

Binary file modified.

 
 from gaesessions import get_current_session
 
+
+
 def listPost(request):
 	posts = models.Post.all()
 	return render_to_response('admin/postlist.html', {
 
 def stream(request):
 	PAGESIZE = int(settings.PAGESIZE)
+	offset = 0
 
 	# get post list
 	if request.GET.get('page'):
 		#get the corrent page
 		page = int(request.GET.get('page'))
-		offset = settings.PAGESIZE *(page - 1)
-		posts = models.Post.all().order('-pub_date').fetch(settings.PAGESIZE, offset)
 	else:
-		posts = models.Post.all().order('-pub_date').fetch(settings.PAGESIZE)
 		page = 1
 
 
+	offset = settings.PAGESIZE *(page - 1)
+
+	if memcache.get('blogpage-'+str(page)):
+		posts = memcache.get('blogpage-'+str(page))
+	else:
+		posts = models.Post.all().order('-pub_date').fetch(settings.PAGESIZE, offset)
+		memcache.set('blogpage-'+str(page), posts)
+
 	# check if there is next page
 	offset = settings.PAGESIZE *(page)
 	next_page = models.Post.all().order('-pub_date').fetch(settings.PAGESIZE, offset)
 
 
 
+
 def listPostByCategory(request, cat):
 	posts = models.Post.all().filter('category =', cat.replace('-',' '))
 
                            						context_instance=RequestContext(request))
 
 
+
 def showPost(request, year, month, day, key_name):
 	post = models.Post.get_by_key_name(key_name)
-
 	if post:
 		# get tag and categories
 		cat_tag = get_tag_cat_list()

Binary file modified.

resources/css/admin.css

 	width:100px;
 	float:left;
 	margin:0px;
-	padding:2px;
+	padding:0px;
 	list-style:none;
 }
 
+#admin-menu ul li{
+	margin-left:0;
+}
 
 #admin-menu ul .top a{
 	text-decoration: none;
 table{
 	width: 90%;
 	border-collapse:collapse;
-	float:left;
-	margin-left:30px;
+	margin-left;
 }
 
 td{
 	text-align:center;
 }
 
+td.left{
+	text-align:left;
+}
+
+table .menu{width:150px;}
+table .date{width:150px;}
+
 tr.odd td {
 	background:#f7fbff;
 }
 	border-top-right-radius:6px;
 }
 
+
+
 form p label{
 	width: 300;
 	display:block;
 	text-align:left;
 }
 
+form input.submit{
+	width:70px;
+	background-color: #878485;
+	display: inline-block;
+	color: #fff;
+	text-decoration: none;
+	-moz-border-radius: 6px;
+	-webkit-border-radius: 6px;
+	-moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
+	-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
+	text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
+	border-bottom: 1px solid rgba(0,0,0,0.25);
+	position: relative;
+	font-size: 14px;
+	padding: 8px 14px 9px;
+	border:1px solid #dedede;
+	margin-top:15px;
+}
+form input.submit:hover{
+	cursor: pointer;
+	background-color: #737272;
+}
+
+form input.submit:active{
+	background-color: #5E5E5E;
+	top:1px;
+}
+
+
 form ul.errorlist{
 	color:red;
 	list-style:none;

resources/css/theme.css

 	box-shadow: rgba(255,255,255,0.5) 1px 1px 3px;
 }
 
+form#contact input{
+	width:270px;
+}
+
+form#contact input.submit{
+	width:70px;
+	background-color: #878485;
+	display: inline-block;
+	color: #fff;
+	text-decoration: none;
+	-moz-border-radius: 6px;
+	-webkit-border-radius: 6px;
+	-moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
+	-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
+	text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
+	border-bottom: 1px solid rgba(0,0,0,0.25);
+	position: relative;
+	font-size: 14px;
+	padding: 8px 14px 9px;
+	border:1px solid #dedede;
+	margin-top:15px;
+}
+form#contact input.submit:hover{
+	cursor: pointer;
+	background-color: #737272;
+}
+
+form#contact input.submit:active{
+	background-color: #5E5E5E;
+	top:1px;
+}
+
 form ul.errorlist{
 	color:red;
 	list-style:none;

templates/admin/base.html

 
 <body>
 <div class="container_12">
-	<div class="grid_6">
-		<div id="admin-menu">
-			<ul>
-				<li class="top"><a href="/posts/">Posts</a></li>
-				<li class="item"><a href="/post/new/">New Post</a></li>
-			</ul>
-			<ul>
-				<li class="top"><a href="/pages/">Pages</a></li>
-				<li class="item"><a href="/page/new/">New Page</a></li>
-			</ul>
-		</div>
-	</div>
+	{% include 'admin/header.html' %}
 
-	<div class="grid_6">
-		&nbsp;
-	</div>
-
-	<div class="clear" style="height:100"></div>
+	<div class="clear" style="height:130"></div>
 
 	{% block content %}{% endblock %}
 

templates/admin/header.html

+<div id=header>
+<div class="grid_12">
+	<div id="admin-menu">
+		<ul>
+			<li class="top"><a href="/posts/">Posts</a></li>
+			<li class="item"><a href="/post/new/">New Post</a></li>
+		</ul>
+		<ul>
+			<li class="top"><a href="/pages/">Pages</a></li>
+			<li class="item"><a href="/page/new/">New Page</a></li>
+		</ul>
+	</div>
+</div>
+</div>

templates/admin/newpage.html

 {% extends 'admin/base.html' %}
 
 {% block content %}
-<div style="width:400px">
+<div id="content" class="grid_12">
 	<form method="POST" action="{% if action %}{{ action }}{% else %}/page/new/{% endif %}">
 		{{ pageForm.as_p }}
-	<input type="submit" value="Save"/>
+	<p><input class="submit" type="submit" value="Save"/></p>
 	</form>
 </div>
 {% endblock %}

templates/admin/newpost.html

 {% extends 'admin/base.html' %}
 
 {% block content %}
-<div style="width:400px">
+<div id="content" class="grid_12">
 	<form method="POST" action="{% if action %}{{ action }}{% else %}/post/new/{% endif %}">
-		<p>
-		<label for="id_title">Title : </label>{{ postForm.title.errors }}<br />
-		{{ postForm.title }}
-		</p>
-		<p>
-		<label for="id_body">Body : </label><br />
-		{{ postForm.body }}
-		</p>
-		<p>
-		<label for="id_category">Category (word or phrase) : </label><br />
-		{{ postForm.category }}
-		</p>
-		<p>
-		<label for="id_tags">Tags (separate by space): </label><br />
-		{{ postForm.tags }}
-		</p>
-	<input type="submit" value="Publish"/>
+		{{ postForm.as_p }}
+	<p><input class="submit" type="submit" value="Publish"/>
 	</form>
 </div>
 {% endblock %}

templates/admin/pagelist.html

 
 {% block content %}
 <div class="grid_12">
+	<h3>Pages</h3>
 	<table>
 		<thead>
 			<tr>
-				<th class="first">Action</th>
+				<th class="first menu">Action</th>
 				<th>Name</th>
-				<th>Published</th>
+				<th class="menu">Published</th>
 				<th>Template</th>
-				<th class="last">Created</th>
+				<th class="last date">Created</th>
 			</tr>
 		</thead>
 		<tbody>

templates/admin/postlist.html

 
 {% block content %}
 <div class="grid_12">
+	<h3>Posts</h3>
 	<table>
 		<thead>
 			<tr>
-				<th class="first">Action</th>
-				<th>Title</th>
-				<th class="last">Created</th>
+				<th class="first menu">Action</th>
+				<th class="title">Title</th>
+				<th class="last date">Created</th>
 			</tr>
 		</thead>
 		<tbody>
 			{% for p in posts %}
 				<tr>
 					<td><a href="{{ p.get_edit_url }}">Edit</a> | <a href="{{ p.get_delete_url }}">Remove</a></td>
-					<td>{{ p.title }}</td>
+					<td class="left">{{ p.title }}</td>
 					<td>{{ p.pub_date.year }}-{{ p.pub_date.month }}-{{ p.pub_date.day }}</td>
 				</tr>
 			{% endfor %}

templates/front/base.html

 <link rel="stylesheet" type="text/css" media="all" href="/resources/css/960.css" />
 <link rel="stylesheet" type="text/css" media="all" href="/resources/css/theme.css" />
 
-<link rel="stylesheet" type="text/css" media="all" href="/resources/css/chat.css" />
 <script src="/resources/js/chat.js" type="text/javascript"></script>
+
 </head>
 
 <body>

templates/front/footer.html

-<div id="chatbox">
-	<iframe class="chatfr" src="http://www.google.com/talk/service/badge/Show?tk=z01q6amlqvo0vil23dcg7ti23t1699osf0sf204i074nkm5bhpu487krv1osson6n2ggmffer7buiflgqi9937emg32qa4itg9718nsdq58l6p3pabtb2t12lthn7l7hil67dutq1c0c995s77nq7f58397abmuumk9b994qr1fbnbdg2d2sfnepj22qlmskm2c&amp;w=200&amp;h=60" allowtransparency="true" frameborder="0" height="60" width="200"></iframe>
-</div>
+

templates/pages/base.html

+<html>
+<head>
+
+<link rel="stylesheet" type="text/css" media="all" href="/resources/css/reset.css" />
+<link rel="stylesheet" type="text/css" media="all" href="/resources/css/text.css" />
+<link rel="stylesheet" type="text/css" media="all" href="/resources/css/960.css" />
+<link rel="stylesheet" type="text/css" media="all" href="/resources/css/theme.css" />
+
+</head>
+
+<body>
+<div class="container_12">
+	{% include 'front/header.html' %}
+
+	<div class="clear" style="height:30"></div>
+
+	{% if page.navbar %}
+		<div id="main-content" class="grid_9">
+			<div class="content">
+				{% block main_content %}{% endblock %}
+			</div>
+		</div>
+
+		<div id="side-menu" class="grid_3">
+			{% block side-menu %}{% endblock %}
+		</div>
+	{% else %}
+		<div id="main-content" class="grid_12">
+			<div class="content">
+				{% block main_content %}{% endblock %}
+			</div>
+		</div>
+	{% endif %}
+
+	<div class="clear"></div>
+</div>
+</body>
+</html>

templates/pages/contact.html

 
 {% block main_content %}
 <div style="width:400px">
-	<form action="/contact/" method="POST">
+	<form id="contact" action="/contact/" method="POST">
 		{{ form.as_p }}
 		{% if msg %}<span class="msg">{{ msg }}</span>{% endif %}
-		<input type="submit" value="Send" />
+
+		<p><input class="submit" type="submit" value="Send" /></p>
 	</form>
 </div>
 {% endblock %}

templates/pages/default.html

+{% extends "pages/base.html" %}
+
+{% block main_content %}
+{% if page %}
+	{% autoescape off %}
+	{{ page.body_html }}
+	{% endautoescape %}
+{% else %}
+	<h3>Sorry, this page is not ready yet. Please come back soon.</h3>
+{% endif %}
+{% endblock %}
+
+{% if page.navbar %}
+	{% block side_menu %}{% endblock %}
+{% endif %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.