Commits

Janto Dreijer  committed e624d73

individual page editing

  • Participants
  • Parent commits f99c1e4

Comments (0)

Files changed (2)

File code/scikits.py

 
 """
 
+class NoSuchTemplateException(Exception):
+	pass
+
 class Page(webapp.RequestHandler):
 
 	name = ""
 		self.response.out.write(text)
 
 	def print_header(self):
-		title = self.name
+		name = self.name
 		search_box_html = SearchPage.search_box()
 
 		# latest changes
 		if ON_DEV_SERVER:
 			google_analytics = "<!-- google analytics skipped when not run at google -->"
 		load_time = time.time() - self.init_time
+		name = self.name
 		self.write(get_template("footer") % locals())
 
 	def print_menu(self):
 	def get(self):
 		self.print_header()
 		self.print_menu()
-		self.write(get_template("main_page")% locals())
+		self.write(get_template(self.name)% locals())
 		self.print_footer()
 
 class ContributePage(Page):
 	def get(self):
 		self.print_header()
 		self.print_menu()
-		self.write(get_template("contribute_page") % locals())
+		self.write(get_template(self.name) % locals())
 		self.print_footer()
 
 class PackagesPage(Page):
 		self.print_footer()
 
 def get_template(name):
+	assert name, name
 	template = PageTemplate.all().filter("name =", name).get()
 	if template is not None:
 		return template.text
-	return getattr(templates, name+"_template").strip()
+	try:
+		return getattr(templates, name+"_template").strip()
+	except AttributeError:
+		raise NoSuchTemplateException(name)
 
 class PageTemplate(db.Model):
 	name = db.StringProperty(required=True)
 
 		user = users.get_current_user()
 		self.write("<p>")
+		url_requested = os.environ["PATH_INFO"] + "?" + os.environ["QUERY_STRING"]
 		if not user:
 			self.write('only site editors allowed here.\n')
-			self.write('<a href="%s">sign in</a>' % users.create_login_url("/edit"))
+			self.write('<a href="%s">sign in</a>' % users.create_login_url(url_requested))
 			self.print_footer()
 			return
 		if users.get_current_user().email().lower() not in self.editors:
 			self.write('only site editors allowed here.\n')
-			self.write('<a href="%s">sign out</a>.' % users.create_logout_url("/edit"))
+			self.write('<a href="%s">sign out</a>.' % users.create_logout_url(url_requested))
 			self.print_footer()
 			return
 		self.write("welcome %s.\n" % user.nickname())
-		self.write('<a href="%s">sign out</a>.' % users.create_logout_url("/edit"))
+		self.write('<a href="%s">sign out</a>.' % users.create_logout_url(url_requested))
 		self.write("</p>")
 
 		# backup and stats
 			self.write("last_modified(<em>%s</em>) = %s" % (template.name, template.modified))
 			self.write("</p>")
 
+		template_name = self.request.get("template_name", None)
+		template_names = [template_name] if template_name is not None else templates.names
+
 		# list templates
-		for template_name in [
-			"header",
-			"footer",
-			"main_page",
-			"about",
-			"contribute_page",
-			"package_info",
-		]:
+		for template_name in template_names:
 			# check if in db
 			template = PageTemplate.all().filter("name =", template_name).get()
 			if template:

File code/templates.py

+names = [
+	"header",
+	"footer",
+	"main",
+	"about",
+	"contribute",
+	"package_info",
+]
+
 header_template = """
 
 <html>
 <head>
-	<title>SciKits - %(title)s</title>
+	<title>SciKits - %(name)s</title>
 	<script type="text/javascript" src="/static/jquery.js"></script>
 	<script type="text/javascript" src="/static/jquery.corners.min.js"></script>
 
 <div class="bodywrapper">
 <div class="body">
 
-<div class="section" id="%(title)s">
+<div class="section" id="%(name)s">
 
 """
 
 
 <div class="footer">
 See the <a href="http://code.google.com/p/scikits-index/source/checkout">source</a>.
-Created page in %(load_time)0.3f seconds. <a href="/edit">Edit Pages</a>.
+Created page in %(load_time)0.3f seconds. Edit <a href="/edit?template_name=%(name)s">this page</a> (<a href="/edit">all</a>).
 <br />
 Designed by <a href="http://janto.blogspot.com/">Janto Dreijer</a>.
 Appearance based on <a href="http://sphinx.pocoo.org/">Sphinx</a> and <a href="http://www.vistaicons.com/icon/i160s0/phuzion_icon_pack.htm">Phuzion icons</a>.
 
 # =======================================
 
-main_page_template = """
+main_template = """
 <p>
 Welcome to SciKits!  Here you'll find a searchable index of
 add-on toolkits that complement <a href="http://www.scipy.org">SciPy</a>, a library of scientific computing routines.
 
 """
 
-contribute_page_template = """
+contribute_template = """
 <h1>Contribute</h1>
 
 <h3>Add your own package</h3>