Commits

Sergey Astanin committed a39566d Merge

merged in changes from default to demo-www

Comments (0)

Files changed (1)

 
 def parse_accept_language(accept_language):
 	"Parse Accept-Language header. See RFC2616, sec. 14."
+	if not accept_language: return []
 	ll=[ v.strip().split(';') for v in accept_language.split(',') ]
 	ll=[ len(l)==1 and l.append(1.0) or l for l in ll]
 	ll=[ [l[0],float(re.sub('q\s*=\s*','',str(l[1])))] for l in ll]
 					self.site=self.create_site_if_not_exists()
 					logging.debug('site='+str(self.site))
 					p=PageData(url=path,site=self.site.key())
+					p.orderid=1+PageData.get_max_order_id()
 		elif path == 'index' and not users.is_current_user_admin():
 			# disallow changing an index page on the demo site
 			# TODO: error message
 		if p.title == '':
 			p.title=path
 		p.content=cgi.escape(self.request.get('content'))
-		p.orderid=1+PageData.get_max_order_id()
 		p.put()
 		redirect_url='/'+path.encode('utf8')
 		if path != path.encode('utf8'):
 		x=x+'</urlset>\n'
 		self.response.out.write(x)
 
+class ExportXml(webapp.RequestHandler):
+	"""export all site contents in XML format"""
+	@require_admin
+	def get(self):
+		site=SiteData.get_the_first()
+		pages=PageData.all().fetch(1000)
+		xml='<?xml version="1.0" encoding="UTF-8"?>\n<site>\n'
+		xml=xml+site.to_xml()
+		for p in pages:
+			xml=xml+p.to_xml()
+		xml=xml+'</site>'
+		self.response.headers['Content-Type']='text/xml; charset=utf-8'
+		self.response.out.write(xml)
+
 class NewPage(webapp.RequestHandler):
 	"""display a form to add a new page"""
 
 
 application = webapp.WSGIApplication([
 			('/sitemap\.xml',SitemapPage),
+			('/export\.xml',ExportXml),
 			('/__newpage',NewPage),
 			('/__options',OptionsPage),
 			('/__save_options',SaveOptionsPage),