Ejemplo n.º 1
0
def main():
	global acc
	form = cgi.FieldStorage()
	ssn = session.Session(form)
	ssn.start()	
	#print("Status:303\r\nLocation: https://www.google.com\r\n")
	#return
	if form.getvalue('theme', 0):
		theme = form.getvalue('themeselect', 0)
		if theme:
			af = os.path.join(static.SB_PATH, 'admin.acc')
			with open(af, 'rb') as f:
				acc = dict(json.load(f))
			acc['theme'] = theme
			with open(af, 'wb') as f:
				json.dump(acc, f)
			# TODO: need to cycle through existing pages & update theme.
			# for now, theme choosen at start.
		elif not theme:
			# send error back to client
			pass
	output.redirect_6bit_home(ssn)
Ejemplo n.º 2
0
def main():
	global acc
	af = os.path.join(static.SB_PATH, 'admin.acc')
	with open(af, 'rb') as f:
		acc = dict(json.load(f))
	logging.debug('before form')
	try:
		# frm = form.FileFieldStorage(static.IMAGE_PATH)
		frm = cgi.FieldStorage()
	except Exception:
		logging.exception('something wrong with FileFieldStorage')

	logging.debug('after form')
	ssn = session.Session(frm)
	ssn.start()	

	form_present = frm.getvalue('addpage', 0)
	logging.debug('form_present: %s' % str(form_present))
	if form_present:
		template = frm.getvalue('template', 0)
		tb = engine.TwoBit(static.SB_PATH, static.IMAGE_PATH, os.path.join(static.THEME_PATH, acc['theme']), static.PAGE_PATH)
		templ_path = os.path.join(static.INPUT_PATH, template+'.html')
		title = tb.populate_vals(templ_path, template, frm)
		# fields = tb.read_template(os.path.join(static.INPUT_PATH, template+'.html'))
		# title = tb.create_vals(template, fields, frm)
		try:
			tb.store_vals( title)
			tb.store_dyn_vals( title)
		except:
			print 'Content-type: text/plain'
			print ssn.output()
			print ''
			print os.path.join(static.INPUT_PATH, template+'.html')
			return
		if title and title not in static.RESERVED_URLS and template and template+'.2b' in os.listdir(static.THEME_PATH+'/'+acc['theme']) and not tb.exists(title):
			# DOTO: check if page title is duplicate
			tf = os.path.join(static.THEME_PATH, acc['theme'], template + '.2b')
			pf = os.path.join(static.PAGE_PATH, '%s.html' % title)
			tb.create_file( tf, pf)

			# file created, now change .htaccess
			rewrite_rule = 'RewriteRule ^%s %s/%s.html [nc]\r\n' % (title, static.PAGE_PATH[static.PAGE_PATH.find('/')+1:], title)
			logging.debug('rewrite_rule: %s' % rewrite_rule)
			htf = os.path.join(static.RELATIVE_PATH, '.htaccess')
			with open(htf, 'a') as f:
				logging.debug('updating .htaccess')
				f.write(rewrite_rule)
			# on each new page added, need to rebuild all pages with any dynamic tags based on pagecount (ie menu)
			# most efficient method?
			# search through templates for dynamic tags, make note of name/list key/val and how to ref in static html without
			# rejigging entire static file list? prob just rejig entire static file list...
			# other dynamic tags: last x posts, tag/category lists (so, blogs basically)
			# so we need dynamic tag class
		elif title and title in static.RESERVED_URLS:
			# send error back to client
			print 'Content-type: text/plain'
			print ssn.output()
			print ''
			print 'Reserved name used for title'
			return
		elif not title:
			# send error back to client
			print 'Content-type: text/plain'
			print ssn.output()
			print ''
			print 'No title entered'
			return
		elif template+'.2b' not in os.listdir(static.THEME_PATH+'/'+acc['theme']):
			# error
			print 'Content-type: text/plain'
			print ssn.output()
			print ''
			print 'Template does not exist'
			return
		elif tb.exists(title):
			print 'Content-type: text/plain'
			print ssn.output()
			print ''
			print 'Page already exists'
			return 
	# output.show_blank(ssn)
	output.redirect_6bit_home( ssn)