def run():
    print("Creating timeline/index")
    html = templates.get("timeline/index")
    html = templates.initial_replace(html, 1)

    tablehtml = ""
    upcominghtml = ""
    for row in t_db:
        rowhtml = templates.get("timeline/index_row")
        rowhtml = rowhtml.replace("__NUMBER__", row["number"])
        rowhtml = rowhtml.replace("__YEAR__", row["year"])
        rowhtml = rowhtml.replace("__DATE__", row["date"])
        rowhtml = rowhtml.replace("__CODE__", row["code"])
        rowhtml = rowhtml.replace("__CITY__", row["city"])
        rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[row["code"]])
        rowhtml = rowhtml.replace("__P_COUNTRY__", row["p_country"])
        rowhtml = rowhtml.replace("__P_STUDENT__", row["p_student"])
        if "code2" in row:
            rowhtml = rowhtml.replace("__CODE2__", row["code2"])
            rowhtml = rowhtml.replace("__COUNTRY2__",
                                      code_to_country[row["code2"]])
            rowhtml = rowhtml.replace("__CODE2_STYLE__", "")
        else:
            rowhtml = rowhtml.replace("__CODE2_STYLE__", "display: none;")
            rowhtml = rowhtml.replace("__CODE2__", ".")  # Google crawler fix
        if int(row["year"]) < int(config.previous_year) + 3:
            # Reverse list
            tablehtml = rowhtml + tablehtml
        else:
            upcominghtml = rowhtml + upcominghtml
    html = html.replace("__TABLE__", tablehtml)
    html = html.replace("__UPCOMING__", upcominghtml)

    html = templates.final_replace(html, "..")
    util.writefile("../timeline/index.html", html)
def run():
    print("Creating contestants/index")
    html = templates.get("contestants/index")
    html = templates.initial_replace(html, 2)

    def keyfn(item):
        return (item[1]["G"], item[1]["S"], item[1]["B"], item[1]["H"],
                sum(item[1].values()))

    sorted_items = sorted(s_db_h.items(), reverse=True, key=keyfn)
    tablehtml = ""
    for contestant, history in sorted_items:
        rowhtml = templates.get("contestants/index_row") \
                    .replace("__NAME__", s_db_c[contestant][0]["name"]) \
                    .replace("__USER_ID__", contestant) \
                    .replace("__GOLD__", str(history["G"])) \
                    .replace("__SILVER__", str(history["S"])) \
                    .replace("__BRONZE__", str(history["B"])) \
                    .replace("__HONOURABLE_MENTION__", str(history["H"])) \
                    .replace("__PARTICIPATIONS__", str(sum(history.values())))
        tablehtml += rowhtml

    html = html.replace("__TABLE__", tablehtml)
    html = templates.final_replace(html, "..")
    util.writefile("../dest/contestants/index.html", html)
def make_html(raw_listing):

	html_listing = ""

	files = {}

	for i in raw_listing:
		i = i.filename.replace("/dres/","")
		i = i.split("/")
		f = i[-1]
		d = "".join(i[:-1])
		try:
			files[d].append(f)
		except KeyError:
			files[d] = [f]

	for d in sorted(files.keys()):
		for f in files[d]:
			print "D: " + d
			print "F: " + f
			if d:
				uri = "{d}/{f}".format(**locals())
			else:
				uri = f
			html_listing += '''<tr><td><a href="/dres/{uri}" target="_blank">/dres/{uri}</a></td></tr>'''.format(**locals())



	import templates
	return templates.get("gcs_directory").format(**locals())
Exemple #4
0
def run():
    print("Creating search")
    util.makedirs("../dest/search")
    util.copyfile("templates/search/search.js", "../dest/search/search.js")
    html = templates.get("search/index")
    html = templates.initial_replace(html, 3)
    html = templates.final_replace(html, "..")
    util.writefile("../dest/search/index.html", html)
Exemple #5
0
def run():
    print("Creating 404")
    html = templates.get("404")
    html = templates.initial_replace(html, -1)
    # This can't both work local and Github :/
    # but it only works on Github anyways
    html = templates.final_replace(html, "")
    util.writefile("../404.html", html)
def run():
    print("Creating countries/index")
    html = templates.get("countries/index")
    html = templates.initial_replace(html, 2)

    tablehtml = ""
    for row in c_db:
        rowhtml = templates.get("countries/index_row")
        rowhtml = rowhtml.replace("__CODE__", row["code"])
        rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[row["code"]])

        if row["website"] != "":
            rowhtml = rowhtml.replace("__NATIONAL_SITE__", row["website"])
            if len(row["website"]) < 50:
                rowhtml = rowhtml.replace("__NATIONAL_SITE_TEXT__",
                                          row["website"])
            else:
                rowhtml = rowhtml.replace("__NATIONAL_SITE_TEXT__",
                                          row["website"][0:35] + "...")
            rowhtml = rowhtml.replace("__NATIONAL_SITE_STYLE__", "")
        else:
            rowhtml = rowhtml.replace("__NATIONAL_SITE_STYLE__",
                                      "display: none;")

        if row["code"] in t_db_c:
            hosts = ""
            flag = False
            for year in t_db_c[row["code"]]:
                if flag:
                    hosts += ", "
                hosts += templates.get("countries/index_hostyear").replace(
                    "__YEAR__", year["year"])
                flag = True
            rowhtml = rowhtml.replace("__HOSTS__", hosts)
        else:
            rowhtml = rowhtml.replace("__HOSTS__", "")

        rowhtml = rowhtml.replace("__CLASS__",
                                  "tr-former" if row["former"] else "")

        tablehtml += rowhtml
    html = html.replace("__TABLE__", tablehtml)

    html = templates.final_replace(html, "..")
    util.writefile("../countries/index.html", html)
Exemple #7
0
def run():
    print("Creating timeline/index")
    html = templates.get("timeline/index")
    html = templates.initial_replace(html, 1)

    tablehtml = ""
    for row in t_db:
        rowhtml = templates.get("timeline/index_row")
        rowhtml = rowhtml.replace("__NUMBER__", row["number"])
        rowhtml = rowhtml.replace("__MONTH__", row["month"])
        rowhtml = rowhtml.replace("__CONTEST_NAME__", row["name"])
        rowhtml = rowhtml.replace("__DATE__", row["date"])
        rowhtml = rowhtml.replace("__P_STUDENT__", row["p_student"])
        tablehtml = rowhtml + tablehtml
    html = html.replace("__TABLE__", tablehtml)

    html = templates.final_replace(html, "..")
    util.writefile("../dest/timeline/index.html", html)
Exemple #8
0
def run():
    print("Creating timeline/index")
    html = templates.get("timeline/index")
    html = templates.initial_replace(html, 1)

    tablehtml = ""
    upcominghtml = ""
    upcoming_row_ctr = 0
    for row in t_db:
        rowhtml = templates.get("timeline/index_row")
        rowhtml = rowhtml.replace("__NUMBER__", row["number"])
        rowhtml = rowhtml.replace("__YEAR__", row["year"])
        rowhtml = rowhtml.replace("__DATE__", row["date"])
        rowhtml = rowhtml.replace("__CODE__", row["code"])
        rowhtml = rowhtml.replace("__CITY__", row["city"])
        rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[row["code"]])
        rowhtml = rowhtml.replace("__P_COUNTRY__", row["p_country"])
        rowhtml = rowhtml.replace("__P_STUDENT__", row["p_student"])
        if "code2" in row:
            rowhtml = rowhtml.replace("__CODE2__", row["code2"])
            rowhtml = rowhtml.replace("__COUNTRY2__",
                                      code_to_country[row["code2"]])
            rowhtml = rowhtml.replace("__CODE2_STYLE__", "")
        else:
            rowhtml = rowhtml.replace("__CODE2_STYLE__", "display: none;")
            rowhtml = rowhtml.replace("__CODE2__", ".")  # Google crawler fix
        if int(row["year"]) <= int(config.next_year) + 2:
            # Reverse list
            tablehtml = rowhtml + tablehtml
        else:
            upcominghtml = rowhtml + upcominghtml
            upcoming_row_ctr += 1
        if int(row["year"]) == 2019:
            tablehtml = templates.get("timeline/index_row_2020") + tablehtml

    # Append an empty row to preserve row parity between tables for styling purposes
    if upcoming_row_ctr % 2:
        upcominghtml = "<tr style=\"display:none;\"></tr>" + upcominghtml

    html = html.replace("__TABLE__", tablehtml)
    html = html.replace("__UPCOMING__", upcominghtml)

    html = templates.final_replace(html, "..")
    util.writefile("../timeline/index.html", html)
Exemple #9
0
def templatify_external(message):

	message.sender = "Rocketeria <*****@*****.**>"
	message.subject = "%s [Automatically Generated]" % message.subject

	content = message.body
	full_body = templates.get("mail_template_external","txt","email").format(**locals())
	message.body = full_body

	return message
Exemple #10
0
def run():
    print("Creating search")
    util.makedirs("../search")
    util.copyfile("database/countries.csv", "../search/countries.csv")
    util.copyfile("database/estudiantes.csv", "../search/estudiantes.csv")
    util.copyfile("templates/search/search.js", "../search/search.js")
    util.copyfile("templates/search/asciify.js", "../search/asciify.js")
    html = templates.get("search/index")
    html = templates.initial_replace(html, 3)
    html = templates.final_replace(html, "..")
    util.writefile("../search/index.html", html)
def run():
    print("Creating countries/index")
    html = templates.get("countries/index")
    html = templates.initial_replace(html, 2)
    
    tablehtml = ""
    for row in c_db:
        rowhtml = templates.get("countries/index_row")
        rowhtml = rowhtml.replace("__CODE__", row["code"])
        rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[row["code"]])
        
        if row["website"] != "":
            rowhtml = rowhtml.replace("__NATIONAL_SITE__", row["website"])
            if len(row["website"]) < 50:
                rowhtml = rowhtml.replace("__NATIONAL_SITE_TEXT__", row["website"])
            else:
                rowhtml = rowhtml.replace("__NATIONAL_SITE_TEXT__", row["website"][0:35] + "...")
            rowhtml = rowhtml.replace("__NATIONAL_SITE_STYLE__", "")
        else:
            rowhtml = rowhtml.replace("__NATIONAL_SITE_STYLE__", "display: none;")
        
        if row["code"] in t_db_c:
            hosts = ""
            flag = False
            for year in t_db_c[row["code"]]:
                if flag:
                    hosts += ", "
                hosts += templates.get("countries/index_hostyear").replace("__YEAR__", year["year"])
                flag = True
            rowhtml = rowhtml.replace("__HOSTS__", hosts)
        else:
            rowhtml = rowhtml.replace("__HOSTS__", "")

        rowhtml = rowhtml.replace("__CLASS__", "tr-former" if row["former"] else "")
        
        tablehtml += rowhtml
    html = html.replace("__TABLE__", tablehtml)
    
    html = templates.final_replace(html, "..")
    util.writefile("../countries/index.html", html)
Exemple #12
0
def templatify_internal(message, remote_addr, remote_ua):
	version = get_env.version()
	environment = get_env.as_hardcoded()

	message.sender = "SCMS Application Server <*****@*****.**>"
	message.to = "*****@*****.**"
	message.subject = "[SCMS] %s" % message.subject

	content = message.body
	full_body = templates.get("mail_template_internal","txt","email").format(**locals())
	message.body = full_body

	return message
 def post(self):
     
     try:
         username = self.request.arguments['username'][0]
         password = self.request.arguments['password'][0]
         print username,password
     except KeyError:
         pass
     if username in users and password == users[username]:
         self.redirect('/main')
     else:
         template = templates.get('login.html')
         #now = datetime.datetime.now()
         self.finish(template.render())
Exemple #14
0
def run(code):
    print("Creating countries/" + code + "/individual")
    html = templates.get("countries/code/individual")
    html = templates.initial_replace(html, 2)
    
    html = html.replace("__CODE__", code)
    html = html.replace("__COUNTRY__", c_db_c[code]["country"])
    
    if code in previous_code:
        html = html.replace("__PREVIOUS_CODE__", previous_code[code])
        html = html.replace("__PREVIOUS_CODE_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_CODE_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_CODE__", ".") # Google crawler fix
        
    if code in next_code:
        html = html.replace("__NEXT_CODE__", next_code[code])
        html = html.replace("__NEXT_CODE_STYLE__", "")
    else:
        html = html.replace("__NEXT_CODE_STYLE__", "display: none;")
        html = html.replace("__NEXT_CODE__", ".") # Google crawler fix

    tablehtml = ""
    if code in s_db_c:
        yearhtml = ""
        lastyear = ""
        for studentdata in s_db_c[code]:
            rowhtml = templates.get("countries/code/individual_row")
            rowhtml = rowhtml.replace("__NAME__", studentdata["name"])
            rowhtml = rowhtml.replace("__RANK__", ("&ge;" if studentdata["rank>="] else "") + studentdata["rank"])
            rowhtml = rowhtml.replace("__YEAR__", studentdata["year"])
            if studentdata["medal"] == "G":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("countries/code/individual_gold"))
            elif studentdata["medal"] == "S":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("countries/code/individual_silver"))
            elif studentdata["medal"] == "B":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("countries/code/individual_bronze"))
            elif studentdata["medal"] == "H":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("countries/code/individual_honourable"))
            else:
                rowhtml = rowhtml.replace("__MEDAL__", "")
            if lastyear == studentdata["year"]:
                rowhtml = rowhtml.replace("__CLASS__", "")
                yearhtml += rowhtml
            else:
                lastyear = studentdata["year"]
                # reverse ordered:
                tablehtml = yearhtml + tablehtml
                rowhtml = rowhtml.replace("__CLASS__", "doubleTopLine")
                yearhtml = rowhtml
        # Hacky way of removing first double top line:
        yearhtml = yearhtml.replace("doubleTopLine", "", 1)
        tablehtml = yearhtml + tablehtml

    html = html.replace("__TABLE__", tablehtml)
    html = templates.final_replace(html, "../..")
    util.writefile("../countries/" + code + "/individual.html", html)
def run(year):
    print("Creating timeline/" + year + "/individual")
    html = templates.get("timeline/year/individual")
    html = templates.initial_replace(html, 1)
    yeardata = t_db_y[year]
    html = html.replace("__YEAR__", year)
    html = html.replace("__NUMBER__", yeardata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(yeardata["number"]))
    
    if year in previous_year:
        html = html.replace("__PREVIOUS_YEAR__", previous_year[year])
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_YEAR__", ".") # Google crawler fix
        
    if year in next_year:
        html = html.replace("__NEXT_YEAR__", next_year[year])
        html = html.replace("__NEXT_YEAR_STYLE__", "")
    else:
        html = html.replace("__NEXT_YEAR_STYLE__", "display: none;")
        html = html.replace("__NEXT_YEAR__", ".") # Google crawler fix
    
    tablehtml = ""
    if year in s_db_y:
        for row in s_db_y[year]:
            rowhtml = templates.get("timeline/year/individual_row")
            if row["code"] == "":
                rowhtml = rowhtml.replace("__CODE__", "TUR") # Yup, this is my hack
                rowhtml = rowhtml.replace("__COUNTRY__", "")
            else:
                rowhtml = rowhtml.replace("__CODE__", row["code"])
                rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[row["code"]])
            rowhtml = rowhtml.replace("__NAME__", row["name"])
            rowhtml = rowhtml.replace("__RANK__", ("&ge;" if row["rank>="] else "") + row["rank"])
            if row["medal"] == "G":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("timeline/year/individual_gold"))
            elif row["medal"] == "S":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("timeline/year/individual_silver"))
            elif row["medal"] == "B":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("timeline/year/individual_bronze"))
            elif row["medal"] == "H":
                rowhtml = rowhtml.replace("__MEDAL__", templates.get("timeline/year/individual_honourable"))
            else:
                rowhtml = rowhtml.replace("__MEDAL__", "")
            tablehtml += rowhtml
    html = html.replace("__TABLE__", tablehtml)
    
    html = templates.final_replace(html, "../..")
    util.writefile("../timeline/" + year + "/individual.html", html)
Exemple #16
0
	def getFile(self,  filename, toPrivate=False):
		"""
		Get file content 
	
		@param filename: file name 
		@type filename: string				
		
		@param toPrivate: save the file in the private area on True (default=False)
		@type toPrivate: boolean			
		"""
		if not self.__logged:
			self.warning( "not logged" )
			return
		
		tpl = self.encapsule( sftp_event=templates.get(filename=filename), cmd=GET_FILE )
		tpl.addRaw( filename )
		self.logSentEvent( shortEvt = "get file", tplEvt = tpl )
		if self.cfg['agent-support']:
			agent_cmd = {'cmd':  GET_FILE, 'filename': filename}
			self.ssh().notifyAgent(cfg=agent_cmd)
		else:
			try:
				myfile = io.BytesIO()
				self.ssh().channel().getfo(filename, myfile)
				read_data = myfile.getvalue() 
			except Exception as e:
				tpl = self.encapsule( sftp_event=templates.response_error(rsp=str(e)), cmd=GET_FILE )
				tpl.addRaw( str(e) )
				self.logRecvEvent( shortEvt = "response error", tplEvt = tpl )
			else:
				if toPrivate:
					head, tail = os.path.split(filename)
					self.privateSaveFile(destname=tail, data=read_data)
					
				# log event
				tpl = self.encapsule( sftp_event=templates.response(content=read_data), cmd=GET_FILE )
				tpl.addRaw( read_data )
				self.logRecvEvent( shortEvt = "file downloaded", tplEvt = tpl )
def run():
    print("Creating timeline/2020")
    util.makedirs("../timeline/2020")
    html = templates.get("timeline/2020/index")
    html = templates.initial_replace(html, 1)

    tablehtml = ""
    for row in database:
        rowhtml = templates.get("timeline/year/individual_row")
        rowhtml = rowhtml.replace("__CODE__", row["code"])
        rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[row["code"]])
        if row["website"]:
            link = templates.get("timeline/year/individual_student_link")
            link = link.replace("__LINK__", row["website"])
            link = link.replace("__NAME__", row["name"])
            rowhtml = rowhtml.replace("__NAME__", link)
        else:
            rowhtml = rowhtml.replace("__NAME__", row["name"])
        rowhtml = rowhtml.replace("__RANK__", row["rank"])
        if row["medal"] == "G":
            rowhtml = rowhtml.replace(
                "__MEDAL__", templates.get("timeline/year/individual_gold"))
        elif row["medal"] == "S":
            rowhtml = rowhtml.replace(
                "__MEDAL__", templates.get("timeline/year/individual_silver"))
        elif row["medal"] == "B":
            rowhtml = rowhtml.replace(
                "__MEDAL__", templates.get("timeline/year/individual_bronze"))
        elif row["medal"] == "H":
            rowhtml = rowhtml.replace(
                "__MEDAL__",
                templates.get("timeline/year/individual_honourable"))
        else:
            rowhtml = rowhtml.replace("__MEDAL__", "")
        rowhtml = rowhtml.replace("__POINTS_STYLE__", "display: none;")
        tablehtml += rowhtml
    html = html.replace("__TABLE__", tablehtml)

    html = templates.final_replace(html, "../..")
    util.writefile("../timeline/2020/index.html", html)
def run(user_id):
    print("Creating contestants/" + user_id + "/index")
    history = contestant_history[user_id]
    html = templates.get("contestants/profile")
    html = templates.initial_replace(html, 2) \
            .replace("__NAME__", contestant_grouped[user_id][0]["name"]) \
            .replace("__GOLD__", str(history["G"])) \
            .replace("__SILVER__", str(history["S"])) \
            .replace("__BRONZE__", str(history["B"])) \
            .replace("__HONOURABLE_MENTION__", str(history["H"])) \
            .replace("__PARTICIPATIONS__", str(sum(history.values())))

    beg, inter, adv, modsmo, special = [""] * 5
    beg_anon, inter_anon, adv_anon, modsmo_anon, special_anon = [False] * 5
    for row in contestant_grouped[user_id]:
        rowhtml = templates.get("contestants/profile_row_" + str(len(row["scores"]))) \
                    .replace("__MONTH__", row["month"]) \
                    .replace("__CONTEST_NAME__", row["contest_name"]) \
                    .replace("__TOTAL_SCORE__", "" if row["is_anonymous"] else str(row["total_score"])) \
                    .replace("__RANK__", "" if row["is_anonymous"] else str(row["rank"]))

        for i, x in enumerate(row["scores"]):
            rowhtml = rowhtml.replace(f"__SCORE_{i+1}__",
                                      "" if row["is_anonymous"] else str(x))

        if not row["is_anonymous"]:
            if row["medal"] == "G":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_gold"))
            elif row["medal"] == "S":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_silver"))
            elif row["medal"] == "B":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_bronze"))
            elif row["medal"] == "H":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_honourable"))
            else:
                rowhtml = rowhtml.replace("__MEDAL__", "")
        else:
            rowhtml = rowhtml.replace("__MEDAL__", "")
        if row["contest_name"] == "Beginner":
            beg += rowhtml
            beg_anon = beg_anon or row["is_anonymous"]
        elif row["contest_name"] == "Intermediate":
            inter += rowhtml
            inter_anon = inter_anon or row["is_anonymous"]
        elif row["contest_name"] == "Advanced":
            adv += rowhtml
            adv_anon = adv_anon or row["is_anonymous"]
        elif row["contest_name"] == "MODSMO":
            modsmo += rowhtml
            modsmo_anon = modsmo_anon or row["is_anonymous"]
        else:
            special += rowhtml
            special_anon = special_anon or row["is_anonymous"]

    header4 = templates.get("contestants/profile_table_header_4")
    header6 = templates.get("contestants/profile_table_header_6")
    header_special = templates.get("contestants/profile_table_header_special")
    for code, text, anon, header in (("BEG", beg, beg_anon,
                                      header4), ("INT", inter, inter_anon,
                                                 header4), ("ADV", adv,
                                                            adv_anon, header4),
                                     ("MODSMO", modsmo, modsmo_anon, header6),
                                     ("SPECIAL", special, special_anon,
                                      header_special)):
        if text:
            html = html.replace(
                "__TABLE_HEADER_" + code + "__",
                header_special if code == "SPECIAL" else header)
            html = html.replace("__TABLE_" + code + "__", text)
        else:
            html = html.replace("__TABLE_HEADER_" + code + "__", "")
            html = html.replace("__TABLE_" + code + "__",
                                "<dd>No participation yet.</dd>")
        html = html.replace(
            "__ANONYMOUS_MSG_" + code + "__",
            "Results of anonymous participations are hidden." if anon else "")

    html = templates.final_replace(html, "../..")
    util.writefile("../dest/contestants/" + user_id + "/index.html", html)
Exemple #19
0
def run(year):
    print("Creating timeline/" + year + "/country")
    html = templates.get("timeline/year/country")
    html = templates.initial_replace(html, 1)
    yeardata = t_db_y[year]
    html = html.replace("__YEAR__", year)
    html = html.replace("__NUMBER__", yeardata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(yeardata["number"]))

    if year in previous_year:
        html = html.replace("__PREVIOUS_YEAR__", previous_year[year])
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_YEAR__", ".")  # Google crawler fix

    if year in next_year:
        html = html.replace("__NEXT_YEAR__", next_year[year])
        html = html.replace("__NEXT_YEAR_STYLE__", "")
    else:
        html = html.replace("__NEXT_YEAR_STYLE__", "display: none;")
        html = html.replace("__NEXT_YEAR__", ".")  # Google crawler fix

    medals = {}
    if year in s_db_y:
        for row in s_db_y[year]:
            if row["code"] == "":
                # Country unknown
                continue
            if row["code"] not in medals:
                medals[row["code"]] = {
                    "bestrank": int(row["rank"]),
                    "bestrank>=": "&ge;" if row["rank>="] else "",
                    "gold": 0,
                    "silver": 0,
                    "bronze": 0,
                    "honourable": 0
                }
            if row["medal"] == "G":
                medals[row["code"]]["gold"] += 1
            elif row["medal"] == "S":
                medals[row["code"]]["silver"] += 1
            elif row["medal"] == "B":
                medals[row["code"]]["bronze"] += 1
            elif row["medal"] == "H":
                medals[row["code"]]["honourable"] += 1

    def keyfn(code):
        m = medals[code]
        return (m["gold"], m["silver"], m["bronze"], m["honourable"],
                -m["bestrank"])

    sortedcodes = reversed(sorted(medals, key=keyfn))

    tablehtml = ""
    prevcode = ""
    prevrank = 0
    for i, code in enumerate(sortedcodes):
        rowhtml = templates.get("timeline/year/country_row")
        rowhtml = rowhtml.replace("__CODE__", code)
        rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[code])
        if prevcode != "" and keyfn(prevcode) == keyfn(code):
            rowhtml = rowhtml.replace("__RANK__", prevrank)
        else:
            rowhtml = rowhtml.replace("__RANK__", str(i + 1))
            prevcode = code
            prevrank = str(i + 1)
        rowhtml = rowhtml.replace("__GOLD__", str(medals[code]["gold"]))
        rowhtml = rowhtml.replace("__SILVER__", str(medals[code]["silver"]))
        rowhtml = rowhtml.replace("__BRONZE__", str(medals[code]["bronze"]))
        rowhtml = rowhtml.replace("__HONOURABLE__",
                                  str(medals[code]["honourable"]))
        rowhtml = rowhtml.replace(
            "__BEST_RANK__",
            medals[code]["bestrank>="] + str(medals[code]["bestrank"]))
        tablehtml += rowhtml
    html = html.replace("__TABLE__", tablehtml)

    html = templates.final_replace(html, "../..")
    util.writefile("../timeline/" + year + "/country.html", html)
def create(name):
    util.makedirs("../" + name + ".php")
    html = templates.get("backward_compatibility/" + name)
    html = templates.final_replace(html, "..")
    util.writefile("../" + name + ".php/index.html", html)
def create(name):
    util.makedirs("../" + name + ".php")
    html = templates.get("backward_compatibility/" + name)
    html = templates.final_replace(html, "..")
    util.writefile("../" + name + ".php/index.html", html)
 def get(self):
     template = templates.get('camera.html')
     self.finish(template.render())  
Exemple #23
0
def run(month):
    print("Creating timeline/" + month + "/individual")
    html = templates.get("timeline/month/individual")
    html = templates.initial_replace(html, 1)
    monthdata = t_db_m[month]
    html = html.replace("__MONTH__", month)
    html = html.replace("__CONTEST_NAME__", monthdata["name"])
    html = html.replace("__NUMBER__", monthdata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(monthdata["number"]))

    if month in previous_month:
        html = html.replace("__PREVIOUS_MONTH__", previous_month[month])
        html = html.replace("__PREVIOUS_MONTH_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_MONTH_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_MONTH__", ".")  # Google crawler fix

    if month in next_month:
        html = html.replace("__NEXT_MONTH__", next_month[month])
        html = html.replace("__NEXT_MONTH_STYLE__", "")
    else:
        html = html.replace("__NEXT_MONTH_STYLE__", "display: none;")
        html = html.replace("__NEXT_MONTH__", ".")  # Google crawler fix

    tablehtml = ""
    anonymous_found = False
    if month in s_db_y:
        for row in s_db_y[month]:
            rowhtml = templates.get("timeline/month/individual_row_" +
                                    str(len(row["scores"])))
            rowhtml = rowhtml.replace("__TOTAL_SCORE__",
                                      str(row["total_score"]))
            rowhtml = rowhtml.replace("__RANK__", str(row["rank"]))

            for i, x in enumerate(row["scores"]):
                rowhtml = rowhtml.replace(f"__SCORE_{i+1}__", str(x))

            if row["medal"] == "G":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_gold"))
            elif row["medal"] == "S":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_silver"))
            elif row["medal"] == "B":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_bronze"))
            elif row["medal"] == "H":
                rowhtml = rowhtml.replace(
                    "__MEDAL__",
                    templates.get("timeline/month/individual_honourable"))
            else:
                rowhtml = rowhtml.replace("__MEDAL__", "")

            if row["is_anonymous"]:
                rowhtml = rowhtml.replace("__NAME__", "")
                rowhtml = rowhtml.replace("__USER_ID__", "")
                tablehtml += rowhtml
                anonymous_found = True
            else:
                rowhtml = rowhtml.replace("__NAME__", row["name"])
                rowhtml = rowhtml.replace("__USER_ID__", row["user-id"])
                tablehtml += rowhtml

    header = ""
    script = ""
    if month in s_db_y and len(s_db_y[month]) >= 1:
        header = templates.get("timeline/month/individual_header_" +
                               str(len(s_db_y[month][0]["scores"])))
        script = templates.get("timeline/month/individual_script_" +
                               str(len(s_db_y[month][0]["scores"])))

    html = html.replace("__TABLE__", tablehtml)
    html = html.replace("__TABLE_HEADER__", header)
    html = html.replace("__SORT_SCRIPT__", script)

    html = html.replace(
        "__ANONYMOUS_MSG__",
        "The names of anonymous contestants are not shown."
        if anonymous_found else "")

    html = templates.final_replace(html, "../..")
    util.writefile("../dest/timeline/" + month + "/individual.html", html)
Exemple #24
0
def run():
    print("Creating 404")
    html = templates.get("404")
    html = templates.initial_replace(html, -1)
    html = templates.final_replace(html, ".")
    util.writefile("../404.html", html)
Exemple #25
0
	def _makeLocalized(self, page, **kwargs):
		return templates.get(page, get = self._chooseLocale().get, **kwargs)
Exemple #26
0
	def get(self):
		'''handle HTTP GETs'''

		self.response.headers['Content-Type'] = 'text/html'
		request_path = self.request.path.strip('/')

		from google.appengine.api import users
		current_user = users.get_current_user()
		nickname = current_user.email()

		if not users.is_current_user_admin():
			logging.error("SECURITY: non-admin user %s requested %s" % (nickname, request_path))
			return

		if request_path == "modify/upload":
			import cloudstorage

			content = templates.get("uploader").format(**locals())

			self.response.write(
				templates.get("upload_wrap").format(**locals())
			)

		elif request_path == "modify/new":

			current_user = users.get_current_user()
			nickname = current_user.email()

			seteditable = '''<script>var editable_existing = false; var new_editor = true;</script>'''
			title = "New Page"
			
			self.response.write(
				templates.get("header").format(**locals())
			)
			self.response.write(
				templates.get("header-sub")
			)
			self.response.write('''<div id="content_sub" contenteditable>''')
			self.response.write(
				'''
				<p>Click here to begin editing...</p>
				<p>Remember to change the page title above. Click the background of the title to cycle colors. Before clicking &quot;Save&quot; below, enter the desired URL in the &quot;Save to&quot; field. The page URL does not have to match the page title above.</p>
				<p>Consult the <a href="https://docs.google.com/a/rocketeria.biz/document/d/161u3MvfQGBfpvJJqEpcVHPntjfqvizoCDssJQLySAEc/edit?usp=sharing" target="_blank">Content Author's Manual</a> for further guidance.</p>
				'''
			)
			self.response.write('''</div> <!--End of #content_sub -->''')

			random_quote = "This text replaces Quote Feed content when creating a new page. Please disregard."
			self.response.write(
				templates.get("sidebar").format(**locals())
			)

			admin_bar = templates.get("admin_bar").format(**locals())

			self.response.write(
				templates.get("footer").format(**locals())
			)

		elif request_path == "modify/banner":
			self.response.write(
				templates.get("alert_banner_settings")
			)
		elif request_path == "modify/info":
			from google.appengine.api import users
			import get_env
			environment = get_env.from_url(self.request.url)
			version = get_env.version()
			current_user = users.get_current_user()
			nickname = current_user.email().split('@')[0] # user, no domain
			self.response.write(
				templates.get("info").format(**locals())
			)
		elif request_path == "modify/logout":
			from google.appengine.api import users
			self.redirect(users.create_logout_url('/'))
def run(code):
    print("Creating countries/" + code + "/index")
    html = templates.get("countries/code/index")
    html = templates.initial_replace(html, 2)
    codedata = c_db_c[code]
    
    html = html.replace("__CODE__", code)
    html = html.replace("__COUNTRY__", codedata["country"])
    
    if codedata["website"] != "":
        html = html.replace("__CONTACT_STYLE__", "")
        html = html.replace("__NATIONAL_SITE__", codedata["website"])
        if len(codedata["website"]) < 50:
            html = html.replace("__NATIONAL_SITE_TEXT__", codedata["website"])
        else:
            html = html.replace("__NATIONAL_SITE_TEXT__", codedata["website"][0:50] + "...")
    else:
        html = html.replace("__CONTACT_STYLE__", "display: none;")
        html = html.replace("__NATIONAL_SITE__", ".") # Google crawler fix
    
    if code in previous_code:
        html = html.replace("__PREVIOUS_CODE__", previous_code[code])
        html = html.replace("__PREVIOUS_CODE_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_CODE_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_CODE__", ".") # Google crawler fix
        
    if code in next_code:
        html = html.replace("__NEXT_CODE__", next_code[code])
        html = html.replace("__NEXT_CODE_STYLE__", "")
    else:
        html = html.replace("__NEXT_CODE_STYLE__", "display: none;")
        html = html.replace("__NEXT_CODE__", ".") # Google crawler fix
    
    if code in t_db_c:
        hostshtml = ""
        for yeardata in t_db_c[code]:
            hosthtml = templates.get("countries/code/index_host")
            if yeardata["city"] != "":
                hosthtml = hosthtml.replace("__CITY__", " - " + yeardata["city"])
            else:
                hosthtml = hosthtml.replace("__CITY__", "")
            if yeardata["homepage"] != "":
                homepagehtml = templates.get("countries/code/index_host_homepage")
                homepagehtml = homepagehtml.replace("__LINK__", yeardata["homepage"])
                hosthtml = hosthtml.replace("__HOMEPAGE__", homepagehtml)
            else:
                hosthtml = hosthtml.replace("__HOMEPAGE__", "")
            hosthtml = hosthtml.replace("__YEAR__", yeardata["year"])
            hostshtml += hosthtml
        html = html.replace("__HOST__", "<dt>IPhO Host</dt>" + hostshtml)
    else:
        html = html.replace("__HOST__", "")
    
    gold = 0
    silver = 0
    bronze = 0
    honourable = 0
    if code in s_db_c:
        for studentdata in s_db_c[code]:
            if studentdata["medal"] == "G":
                gold += 1
            elif studentdata["medal"] == "S":
                silver += 1
            elif studentdata["medal"] == "B":
                bronze += 1
            elif studentdata["medal"] == "H":
                honourable += 1
    html = html.replace("__GOLD__", str(gold))
    html = html.replace("__SILVER__", str(silver))
    html = html.replace("__BRONZE__", str(bronze))
    html = html.replace("__HONOURABLE__", str(honourable))
    
    html = templates.final_replace(html, "../..")
    util.writefile("../countries/" + code + "/index.html", html)
Exemple #28
0
def run():
    print("Creating 404")
    html = templates.get("404")
    html = templates.initial_replace(html, -1)
    html = templates.final_replace(html, ".")
    util.writefile("../404.html", html)
Exemple #29
0
def run(month):
    print("Creating timeline/" + month + "/index")
    html = templates.get("timeline/month/index")
    html = templates.initial_replace(html, 1)
    monthdata = t_db_m[month]
    html = html.replace("__MONTH__", month)
    html = html.replace("__CONTEST_NAME__", monthdata["name"])
    html = html.replace("__NUMBER__", monthdata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(monthdata["number"]))
    html = html.replace("__DATE__", monthdata["date"])

    if month in previous_month:
        html = html.replace("__PREVIOUS_MONTH__", previous_month[month])
        html = html.replace("__PREVIOUS_MONTH_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_MONTH_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_MONTH__", ".")  # Google crawler fix

    if month in next_month:
        html = html.replace("__NEXT_MONTH__", next_month[month])
        html = html.replace("__NEXT_MONTH_STYLE__", "")
    else:
        html = html.replace("__NEXT_MONTH_STYLE__", "display: none;")
        html = html.replace("__NEXT_MONTH__", ".")  # Google crawler fix

    if monthdata["p_student"] != "":
        html = html.replace("__P_STUDENT_STYLE__", "")
        html = html.replace("__P_STUDENT__", monthdata["p_student"])
    else:
        html = html.replace("__P_STUDENT_STYLE__", "display: none;")

    gold = 0
    silver = 0
    bronze = 0
    honourable = 0
    if month in contest_results:
        for studentdata in contest_results[month]:
            if studentdata["medal"] == "G":
                gold += 1
            elif studentdata["medal"] == "S":
                silver += 1
            elif studentdata["medal"] == "B":
                bronze += 1
            elif studentdata["medal"] == "H":
                honourable += 1
        html = html.replace("__AWARDS_STYLE__", "")
        html = html.replace("__GOLD__", str(gold))
        html = html.replace("__SILVER__", str(silver))
        html = html.replace("__BRONZE__", str(bronze))
        html = html.replace("__HONOURABLE__", str(honourable))
    else:
        html = html.replace("__AWARDS_STYLE__", "display: none;")

    if month in contest_results:
        html = html.replace("__INDIVIDUAL_STYLE__", "")
        num_problems = len(contest_results[month][0]["scores"])
        header = templates.get(f"timeline/month/stats/header_{num_problems}")
        count = [[0 for _ in range(8)] for _ in range(num_problems)]
        for entry in contest_results[month]:
            for i, score in enumerate(entry["scores"]):
                count[i][score] += 1
        nums = ""
        for score in range(8):
            rowhtml = templates.get(f"timeline/month/stats/num_{num_problems}")
            rowhtml = rowhtml.replace("__SCORE__", str(score))
            for i in range(num_problems):
                rowhtml = rowhtml.replace(f"__P{i+1}__", str(count[i][score]))
            nums += rowhtml
        means = templates.get(f"timeline/month/stats/index_value_{num_problems}") \
                    .replace("__NAME__", "Mean") \
                    .replace("__STYLE__", "mean")
        maxs = templates.get(f"timeline/month/stats/index_value_{num_problems}") \
                    .replace("__NAME__", "Max") \
                    .replace("__STYLE__", "max")
        sigmas = templates.get(f"timeline/month/stats/index_value_{num_problems}") \
                    .replace("__NAME__", "σ") \
                    .replace("__STYLE__", "sigma")
        for i in range(num_problems):
            total = sum(count[i])
            total_score = sum(score * count[i][score] for score in range(8))
            mean = total_score / total
            means = means.replace(f"__P{i+1}__", "%.3f" % mean)
            max_score = max(score for score in range(8)
                            if count[i][score] or score == 0)
            maxs = maxs.replace(f"__P{i+1}__", str(max_score))
            variance = sum(
                pow((score - mean), 2) * count[i][score]
                for score in range(8)) / total
            sigmas = sigmas.replace(f"__P{i+1}__", "%.3f" % sqrt(variance))

        html = html.replace("__STATS_STYLE__", "") \
                   .replace("__TABLE_HEADER__", header) \
                   .replace("__TABLE_NUM__", nums) \
                   .replace("__TABLE_MEAN__", means) \
                   .replace("__TABLE_MAX__", maxs) \
                   .replace("__TABLE_SIGMA__", sigmas)
    else:
        html = html.replace("__INDIVIDUAL_STYLE__", "display: none;")
        html = html.replace("__STATS_STYLE__", "display: none;")

    html = templates.final_replace(html, "../..")
    util.writefile("../dest/timeline/" + month + "/index.html", html)
 def get(self):
     template = templates.get('simple.html')
     self.finish(template.render())  
Exemple #31
0
	def post(self):

		# status is bad until set good
		self.response.set_status(400)

		if obvious_spam(self.request):
			return

		uri = self.request.path.strip('/')
		messages = {
			"internal": [],
			"external": [],
		}
		message = mail.EmailMessage()

		if uri == "sendmail/deadlink":
			badurl = self.request.get("badurl").encode('utf-8', 'xmlcharrefreplace')
			message.subject = "Missing resource reported by user"
			message.body = templates.get("404","txt","email").format(**locals())
			messages["internal"].append(message)

		elif uri == "sendmail/changerequest":

			# performs rudimentary checks before sending mail. will not catch but the most basic weirdness.
			account_name = self.request.get("account_name").encode('utf-8', 'xmlcharrefreplace')
			student_name = self.request.get("student_name").encode('utf-8', 'xmlcharrefreplace')

			if account_name and student_name:

				message.subject = "Lesson Change Request for %s" % (student_name)

				lesson_date = self.request.get("lesson_date").encode('utf-8', 'xmlcharrefreplace')
				lesson_time = self.request.get("lesson_time").encode('utf-8', 'xmlcharrefreplace')
				comment = self.request.get("comment").encode('utf-8', 'xmlcharrefreplace')
				if not comment:
					comment = "(none)"

				if lesson_date or lesson_time:
					# still send the message if either date or time was missed
					message.body = templates.get("change_all","txt","email").format(**locals())
	
				else:
					requested_action = self.request.get("requested_action").encode('utf-8', 'xmlcharrefreplace')
					message.body = templates.get("change_one","txt","email").format(**locals())

				messages["internal"].append(message)

		elif uri == "sendmail/policytosign":

			billto_firstandlast = self.request.get("billto_firstandlast").encode('utf-8', 'xmlcharrefreplace')
			billto_email = self.request.get("billto_email").encode('utf-8', 'xmlcharrefreplace')
			billto_mobilephone = self.request.get("billto_mobilephone").encode('utf-8', 'xmlcharrefreplace')
			billto_altphone = self.request.get("billto_altphone").encode('utf-8', 'xmlcharrefreplace')
			billto_address1 = self.request.get("billto_address1").encode('utf-8', 'xmlcharrefreplace')
			billto_address2 = self.request.get("billto_address2").encode('utf-8', 'xmlcharrefreplace')

			student_same_as_bill_to = self.request.get("student_same_as_bill_to").encode('utf-8', 'xmlcharrefreplace')

			if student_same_as_bill_to == "true":
				student_same_as_bill_to = "Yes"
				student_info = ""
			else:
				student_same_as_bill_to = "No"

				for n in range(3):
					n = n + 1
					if self.request.get("student%s_firstandlast" % n):
						student_firstandlast = self.request.get("student%s_firstandlast" % n).encode('utf-8', 'xmlcharrefreplace')
						student_email = self.request.get("student%s_email" % n).encode('utf-8', 'xmlcharrefreplace')
						student_mobilephone = self.request.get("student%s_mobilephone" % n).encode('utf-8', 'xmlcharrefreplace')
						student_altphone = self.request.get("student%s_altphone" % n).encode('utf-8', 'xmlcharrefreplace')
						student_school = self.request.get("student%s_school" % n).encode('utf-8', 'xmlcharrefreplace')
						student_grade = self.request.get("student%s_grade" % n).encode('utf-8', 'xmlcharrefreplace')
						try:
							student_info += templates.get("enroll_student_info","txt","email").format(**locals())
						except NameError:
							student_info = templates.get("enroll_student_info","txt","email").format(**locals())

				try:
					student_info
				except UnboundLocalError:
					student_info = "(no student info provided)"

			comment1 = self.request.get("comment1").encode('utf-8', 'xmlcharrefreplace')
			if not comment1:
				comment1 = "(none)"

			no_chargeaccount = self.request.get("no_chargeaccount").encode('utf-8', 'xmlcharrefreplace')

			if no_chargeaccount == "true":
				chargeaccount_text = "NO - Do not allow charges to account"
			else:
				chargeaccount_text = "OK [implicit]"

			no_media_release = self.request.get("no_media_release").encode('utf-8', 'xmlcharrefreplace')

			if no_media_release == "true":
				photo_release_text = "NO - Never use my likeness without explicit consent"
			else:
				photo_release_text = "OK [implicit]"

			digital_signature_name = self.request.get("digital_signature_name").encode('utf-8', 'xmlcharrefreplace')

			policy_content_text = self.request.get("policy_content_text").encode('utf-8', 'xmlcharrefreplace')

			policy_content_html = self.request.get("policy_content_html").encode('utf-8', 'xmlcharrefreplace')
			
			message.subject = "Policy Accepted: %s" % (digital_signature_name)
			message.body = templates.get("policyacceptance_internal","txt","email").format(**locals())

			messages["internal"].append(message)

			message_tocustomer = mail.EmailMessage()

			message_tocustomer.subject = "Rocketeria Music Lessons Policies"
			message_tocustomer.body = templates.get("policyacceptance_external","txt","email").format(**locals())
			message_tocustomer.html = templates.get("policyacceptance_external","html","email").format(**locals())
			message_tocustomer.to = billto_email

			messages["external"].append(message_tocustomer)


		elif uri == "sendmail/enroll":

			billto_firstandlast = self.request.get("billto_firstandlast").encode('utf-8', 'xmlcharrefreplace')
			billto_email = self.request.get("billto_email").encode('utf-8', 'xmlcharrefreplace')
			billto_mobilephone = self.request.get("billto_mobilephone").encode('utf-8', 'xmlcharrefreplace')
			billto_altphone = self.request.get("billto_altphone").encode('utf-8', 'xmlcharrefreplace')
			billto_address1 = self.request.get("billto_address1").encode('utf-8', 'xmlcharrefreplace')
			billto_address2 = self.request.get("billto_address2").encode('utf-8', 'xmlcharrefreplace')

			student_same_as_bill_to = self.request.get("student_same_as_bill_to").encode('utf-8', 'xmlcharrefreplace')

			if student_same_as_bill_to == "true":
				student_same_as_bill_to = "Yes"
				student_info = ""
			else:
				student_same_as_bill_to = "No"

				for n in range(3):
					n = n + 1
					if self.request.get("student%s_firstandlast" % n):
						student_firstandlast = self.request.get("student%s_firstandlast" % n).encode('utf-8', 'xmlcharrefreplace')
						student_email = self.request.get("student%s_email" % n).encode('utf-8', 'xmlcharrefreplace')
						student_mobilephone = self.request.get("student%s_mobilephone" % n).encode('utf-8', 'xmlcharrefreplace')
						student_altphone = self.request.get("student%s_altphone" % n).encode('utf-8', 'xmlcharrefreplace')
						student_school = self.request.get("student%s_school" % n).encode('utf-8', 'xmlcharrefreplace')
						student_grade = self.request.get("student%s_grade" % n).encode('utf-8', 'xmlcharrefreplace')
						try:
							student_info += templates.get("enroll_student_info","txt","email").format(**locals())
						except NameError:
							student_info = templates.get("enroll_student_info","txt","email").format(**locals())

				try:
					student_info
				except UnboundLocalError:
					student_info = "(no student info provided)"

			lesson_environment = self.request.get_all("lesson_environment")
			lesson_environment = ', '.join(lesson_environment)
			lesson_environment = lesson_environment.encode('utf-8', 'xmlcharrefreplace')

			instrument = self.request.get_all("instrument")
			instrument = ', '.join(instrument)
			instrument = instrument.encode('utf-8', 'xmlcharrefreplace')

			expertise = self.request.get_all("expertise")
			expertise = ', '.join(expertise)
			expertise = expertise.encode('utf-8', 'xmlcharrefreplace')

			teacher = self.request.get_all("teacher")
			teacher = ', '.join(teacher)
			teacher = teacher.encode('utf-8', 'xmlcharrefreplace')

			recurrence = self.request.get("recurrence").encode('utf-8', 'xmlcharrefreplace')

			day_of_week = self.request.get_all("day_of_week")
			day_of_week = ', '.join(day_of_week)
			day_of_week = day_of_week.encode('utf-8', 'xmlcharrefreplace')

			time_range = self.request.get_all("time_range")
			time_range = ', '.join(time_range)
			time_range.encode('utf-8', 'xmlcharrefreplace')

			comment1 = self.request.get("comment1").encode('utf-8', 'xmlcharrefreplace')
			if not comment1:
				comment1 = "(none)"

			no_chargeaccount = self.request.get("no_chargeaccount").encode('utf-8', 'xmlcharrefreplace')

			if no_chargeaccount == "true":
				chargeaccount_text = "NO - Do not allow charges to account"
			else:
				chargeaccount_text = "OK [implicit]"

			no_media_release = self.request.get("no_media_release").encode('utf-8', 'xmlcharrefreplace')

			if no_media_release == "true":
				photo_release_text = "NO - Never use my likeness without explicit consent"
			else:
				photo_release_text = "OK [implicit]"

			digital_signature_name = self.request.get("digital_signature_name").encode('utf-8', 'xmlcharrefreplace')

			message.subject = "Enroll Form Submission: %s" % (billto_firstandlast)

			message.body = templates.get("enroll","txt","email").format(**locals())

			messages["internal"].append(message)

		for m in messages["internal"]:
			try:
				message = templatify_internal(message = m, remote_addr = self.request.remote_addr, remote_ua = self.request.headers['User-Agent'])
			except AttributeError:
				self.error(400)
			else:
				self.response.set_status(200)
				message.send()
		
		for m in messages["external"]:
			try:
				message = templatify_external(message = m)
			except AttributeError:
				self.error(400)
			else:
				self.response.set_status(200)
				message.send()
		
		self.redirect("/") # just for noscript
 def get(self):
     template = templates.get('login.html')
     self.finish(template.render())
def run(year):
    print("Creating timeline/" + year + "/index")
    html = templates.get("timeline/year/index")
    html = templates.initial_replace(html, 1)
    yeardata = t_db_y[year]
    html = html.replace("__YEAR__", year)
    html = html.replace("__NUMBER__", yeardata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(yeardata["number"]))
    html = html.replace("__DATE__", yeardata["date"])
    html = html.replace("__CODE__", yeardata["code"])
    html = html.replace("__COUNTRY__", code_to_country[yeardata["code"]])
    
    if "code2" in yeardata:
        html = html.replace("__CODE2__", yeardata["code2"])
        html = html.replace("__COUNTRY2__", code_to_country[yeardata["code2"]])
        html = html.replace("__CODE2_STYLE__", "")
    else:
        html = html.replace("__CODE2_STYLE__", "display: none;")
        html = html.replace("__CODE2__", ".") # Google crawler fix
    
    if yeardata["city"] != "":
        html = html.replace("__CITY__", yeardata["city"] + ",")
    else:
        html = html.replace("__CITY__", "")
    
    if year in previous_year:
        html = html.replace("__PREVIOUS_YEAR__", previous_year[year])
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_YEAR__", ".") # Google crawler fix
        
    if year in next_year:
        html = html.replace("__NEXT_YEAR__", next_year[year])
        html = html.replace("__NEXT_YEAR_STYLE__", "")
    else:
        html = html.replace("__NEXT_YEAR_STYLE__", "display: none;")
        html = html.replace("__NEXT_YEAR__", ".") # Google crawler fix
    
    if yeardata["p_student"] != "":
        html = html.replace("__P_STUDENT_STYLE__", "")
        html = html.replace("__P_STUDENT__", yeardata["p_student"])
    else:
        html = html.replace("__P_STUDENT_STYLE__", "display: none;")
    
    if yeardata["p_country"] != "":
        html = html.replace("__P_COUNTRY_STYLE__", "")
        html = html.replace("__P_COUNTRY__", yeardata["p_country"])
    else:
        html = html.replace("__P_COUNTRY_STYLE__", "display: none;")
    
    if yeardata["homepage"] != "":
        html = html.replace("__HOMEPAGE_STYLE__", "")
        html = html.replace("__HOMEPAGE__", yeardata["homepage"])
    else:
        html = html.replace("__HOMEPAGE_STYLE__", "display: none;")
        html = html.replace("__HOMEPAGE__", ".") # Google crawler fix
    
    gold = 0
    silver = 0
    bronze = 0
    honourable = 0
    if year in s_db_y:
        for studentdata in s_db_y[year]:
            if studentdata["medal"] == "G":
                gold += 1
            elif studentdata["medal"] == "S":
                silver += 1
            elif studentdata["medal"] == "B":
                bronze += 1
            elif studentdata["medal"] == "H":
                honourable += 1
        html = html.replace("__AWARDS_STYLE__", "")
        html = html.replace("__GOLD__", str(gold))
        html = html.replace("__SILVER__", str(silver))
        html = html.replace("__BRONZE__", str(bronze))
        html = html.replace("__HONOURABLE__", str(honourable))
    else:
        html = html.replace("__AWARDS_STYLE__", "display: none;")
    
    html = templates.final_replace(html, "../..")
    util.writefile("../timeline/" + year + "/index.html", html)
Exemple #34
0
def run():
    print("Creating index")
    html = templates.get("index")
    html = templates.initial_replace(html, 0)
    html = templates.final_replace(html, ".")
    util.writefile("../dest/index.html", html)
Exemple #35
0
def run(year):
    print("Creating timeline/" + year + "/index")
    html = templates.get("timeline/year/index")
    html = templates.initial_replace(html, 1)
    yeardata = t_db_y[year]
    html = html.replace("__YEAR__", year)
    html = html.replace("__NUMBER__", yeardata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(yeardata["number"]))
    html = html.replace("__DATE__", yeardata["date"])
    html = html.replace("__CODE__", yeardata["code"])
    html = html.replace("__COUNTRY__", code_to_country[yeardata["code"]])

    if "code2" in yeardata:
        html = html.replace("__CODE2__", yeardata["code2"])
        html = html.replace("__COUNTRY2__", code_to_country[yeardata["code2"]])
        html = html.replace("__CODE2_STYLE__", "")
    else:
        html = html.replace("__CODE2_STYLE__", "display: none;")
        html = html.replace("__CODE2__", ".")  # Google crawler fix

    if yeardata["city"] != "":
        html = html.replace("__CITY__", yeardata["city"] + ",")
    else:
        html = html.replace("__CITY__", "")

    if year in previous_year:
        html = html.replace("__PREVIOUS_YEAR__", previous_year[year])
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_YEAR__", ".")  # Google crawler fix

    if year in next_year:
        html = html.replace("__NEXT_YEAR__", next_year[year])
        html = html.replace("__NEXT_YEAR_STYLE__", "")
    else:
        html = html.replace("__NEXT_YEAR_STYLE__", "display: none;")
        html = html.replace("__NEXT_YEAR__", ".")  # Google crawler fix

    if yeardata["p_student"] != "":
        html = html.replace("__P_STUDENT_STYLE__", "")
        html = html.replace("__P_STUDENT__", yeardata["p_student"])
    else:
        html = html.replace("__P_STUDENT_STYLE__", "display: none;")

    if yeardata["p_country"] != "":
        html = html.replace("__P_COUNTRY_STYLE__", "")
        html = html.replace("__P_COUNTRY__", yeardata["p_country"])
    else:
        html = html.replace("__P_COUNTRY_STYLE__", "display: none;")

    if yeardata["homepage"] != "":
        html = html.replace("__HOMEPAGE_STYLE__", "")
        html = html.replace("__HOMEPAGE__", yeardata["homepage"])
    else:
        html = html.replace("__HOMEPAGE_STYLE__", "display: none;")
        html = html.replace("__HOMEPAGE__", ".")  # Google crawler fix

    gold = 0
    silver = 0
    bronze = 0
    honourable = 0
    if year in s_db_y:
        for studentdata in s_db_y[year]:
            if studentdata["medal"] == "G":
                gold += 1
            elif studentdata["medal"] == "S":
                silver += 1
            elif studentdata["medal"] == "B":
                bronze += 1
            elif studentdata["medal"] == "H":
                honourable += 1
        html = html.replace("__AWARDS_STYLE__", "")
        html = html.replace("__GOLD__", str(gold))
        html = html.replace("__SILVER__", str(silver))
        html = html.replace("__BRONZE__", str(bronze))
        html = html.replace("__HONOURABLE__", str(honourable))
    else:
        html = html.replace("__AWARDS_STYLE__", "display: none;")

    html = templates.final_replace(html, "../..")
    util.writefile("../timeline/" + year + "/index.html", html)
Exemple #36
0
def run(month):
    print("Creating timeline/" + month + "/country")
    html = templates.get("timeline/month/country")
    html = templates.initial_replace(html, 1)
    monthdata = t_db_m[month]
    html = html.replace("__MONTH__", month)
    html = html.replace("__NUMBER__", monthdata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(monthdata["number"]))

    if month in previous_month:
        html = html.replace("__PREVIOUS_MONTH__", previous_month[month])
        html = html.replace("__PREVIOUS_MONTH_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_MONTH_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_MONTH__", ".")  # Google crawler fix

    if month in next_month:
        html = html.replace("__NEXT_MONTH__", next_month[month])
        html = html.replace("__NEXT_MONTH_STYLE__", "")
    else:
        html = html.replace("__NEXT_MONTH_STYLE__", "display: none;")
        html = html.replace("__NEXT_MONTH__", ".")  # Google crawler fix

    medals = {}
    if month in s_db_y:
        for row in s_db_y[month]:
            if row["name"] not in medals:
                medals[row["name"]] = {
                    "bestrank": int(row["rank"]),
                    "bestrank>=": "&ge;" if row["rank>="] else "",
                    "gold": 0,
                    "silver": 0,
                    "bronze": 0,
                    "honourable": 0
                }
            if row["medal"] == "G":
                medals[row["name"]]["gold"] += 1
            elif row["medal"] == "S":
                medals[row["name"]]["silver"] += 1
            elif row["medal"] == "B":
                medals[row["name"]]["bronze"] += 1
            elif row["medal"] == "H":
                medals[row["name"]]["honourable"] += 1

    def keyfn(code):
        m = medals[code]
        return (-m["gold"], -m["silver"], -m["bronze"], -m["honourable"],
                m["bestrank"], code)

    sortedcodes = sorted(medals, key=keyfn)

    tablehtml = ""
    prevcode = ""
    prevrank = 0
    for i, code in enumerate(sortedcodes):
        rowhtml = templates.get("timeline/month/country_row")
        rowhtml = rowhtml.replace("__CODE__", code)
        if prevcode != "" and keyfn(prevcode)[:-1] == keyfn(code)[:-1]:
            rowhtml = rowhtml.replace("__RANK__", prevrank)
        else:
            rowhtml = rowhtml.replace("__RANK__", str(i + 1))
            prevcode = code
            prevrank = str(i + 1)
        rowhtml = rowhtml.replace("__GOLD__", str(medals[code]["gold"]))
        rowhtml = rowhtml.replace("__SILVER__", str(medals[code]["silver"]))
        rowhtml = rowhtml.replace("__BRONZE__", str(medals[code]["bronze"]))
        rowhtml = rowhtml.replace("__HONOURABLE__",
                                  str(medals[code]["honourable"]))
        rowhtml = rowhtml.replace(
            "__BEST_RANK__",
            medals[code]["bestrank>="] + str(medals[code]["bestrank"]))
        tablehtml += rowhtml
    html = html.replace("__TABLE__", tablehtml)

    html = templates.final_replace(html, "../..")
    util.writefile("../dest/timeline/" + month + "/country.html", html)
def run(year):
    print("Creating timeline/" + year + "/country")
    html = templates.get("timeline/year/country")
    html = templates.initial_replace(html, 1)
    yeardata = t_db_y[year]
    html = html.replace("__YEAR__", year)
    html = html.replace("__NUMBER__", yeardata["number"])
    html = html.replace("__ORDINAL__", util.ordinal(yeardata["number"]))
    
    if year in previous_year:
        html = html.replace("__PREVIOUS_YEAR__", previous_year[year])
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "")
    else:
        html = html.replace("__PREVIOUS_YEAR_STYLE__", "display: none;")
        html = html.replace("__PREVIOUS_YEAR__", ".") # Google crawler fix
        
    if year in next_year:
        html = html.replace("__NEXT_YEAR__", next_year[year])
        html = html.replace("__NEXT_YEAR_STYLE__", "")
    else:
        html = html.replace("__NEXT_YEAR_STYLE__", "display: none;")
        html = html.replace("__NEXT_YEAR__", ".") # Google crawler fix
    
    medals = {}
    if year in s_db_y:
        for row in s_db_y[year]:
            if row["code"] == "":
                # Country unknown
                continue
            if row["code"] not in medals:
                medals[row["code"]] = {
                    "bestrank": int(row["rank"]),
                    "bestrank>=": "&ge;" if row["rank>="] else "",
                    "gold": 0,
                    "silver": 0,
                    "bronze": 0,
                    "honourable": 0
                    }
            if row["medal"] == "G":
                medals[row["code"]]["gold"] += 1
            elif row["medal"] == "S":
                medals[row["code"]]["silver"] += 1
            elif row["medal"] == "B":
                medals[row["code"]]["bronze"] += 1
            elif row["medal"] == "H":
                medals[row["code"]]["honourable"] += 1
    
    def keyfn(code):
        m = medals[code]
        return (m["gold"], m["silver"], m["bronze"], m["honourable"],
                -m["bestrank"])

    sortedcodes = reversed(sorted(medals, key = keyfn))
    
    tablehtml = ""
    prevcode = ""
    prevrank = 0
    for i, code in enumerate(sortedcodes):
        rowhtml = templates.get("timeline/year/country_row")
        rowhtml = rowhtml.replace("__CODE__", code)
        rowhtml = rowhtml.replace("__COUNTRY__", code_to_country[code])
        if prevcode != "" and keyfn(prevcode) == keyfn(code):
            rowhtml = rowhtml.replace("__RANK__", prevrank)
        else:
            rowhtml = rowhtml.replace("__RANK__", str(i + 1))
            prevcode = code
            prevrank = str(i + 1)
        rowhtml = rowhtml.replace("__GOLD__", str(medals[code]["gold"]))
        rowhtml = rowhtml.replace("__SILVER__", str(medals[code]["silver"]))
        rowhtml = rowhtml.replace("__BRONZE__", str(medals[code]["bronze"]))
        rowhtml = rowhtml.replace("__HONOURABLE__", str(medals[code]["honourable"]))
        rowhtml = rowhtml.replace("__BEST_RANK__", medals[code]["bestrank>="] + str(medals[code]["bestrank"]))
        tablehtml += rowhtml
    html = html.replace("__TABLE__", tablehtml)
    
    html = templates.final_replace(html, "../..")
    util.writefile("../timeline/" + year + "/country.html", html)
Exemple #38
0
	def post(self, *args, **kwargs):
		'''handle HTTP POSTs'''

		from google.appengine.api import users
		current_user = users.get_current_user()
		nickname = current_user.email()

		if not users.is_current_user_admin():
			logging.error("SECURITY: non-admin user %s requested %s" % (nickname, request_path))
			return

		self.response.headers['Content-Type'] = 'text/html'

		request_path = self.request.path.strip('/')

		logging.info("User %s sent POST request for %s" % (nickname, request_path))

		uri = self.request.get("resource")
		if uri:
			uri = uri.strip()
			uri = uri.strip("/")

		if request_path == "modify/publish":
			content = self.request.get("content")
			key = gae_db.add_or_update_page(uri, content)
			logging.info("User %s published %s" % (nickname, uri))
			self.redirect("/%s" % uri)

		elif request_path == "modify/delete":
			logging.info("User %s deleted %s" % (nickname, uri))
			gae_db.delete_page(uri)

		elif request_path == "modify/upload":
			import cloudstorage

			uploaded_file = self.request.params["file"]
			filename = uploaded_file.filename
			child_bin = self.request.get("child_bin")
			gcs_bin = "/dres/"

			if child_bin:
				child_bin = child_bin.strip("/")
				child_bin = child_bin
				gcs_bin = "%s%s/" % (gcs_bin, child_bin)

			logging.info("User %s uploaded file \"%s\", type \"%s\", to bin \"%s\"" % (nickname, filename, uploaded_file.type, gcs_bin))

			cloud_file = cloudstorage.open(
				"%s%s" % (gcs_bin, filename),
				mode = "w",
				content_type = uploaded_file.type,
				options = {
					"x-goog-acl" : "public-read" 
				}
			)
			cloud_file.write(uploaded_file.value)
			cloud_file.close()

			from urllib import quote
			uri = quote(uri.encode('utf-8'))

			absolute_uri = "%s%s%s" % (self.request.host_url, gcs_bin, filename)

			content = templates.get("upload_success").format(**locals())

			self.response.write(
				templates.get("upload_wrap").format(**locals())
			)

		elif request_path == "modify/banner":

			state = self.request.get("state")

			if state != "on":
				# clear banner
				logging.info("User %s removed the alert banner" % (nickname))
				gae_db.delete_page("banner")
				return

			banner_bg = self.request.get("banner_bg")
			text_color = self.request.get("text_color")
			message = self.request.get("message").strip()
			override_hours = self.request.get("override_hours").strip()

			# set expire date to 00:00 UTC of selected day
			# this prevents each cron job fron needing to convert time zone
			from datetime import datetime,timedelta
			expiry = self.request.get("expire").strip()

			if expiry:
				expiry = datetime.strptime(expiry,"%d/%m/%Y")
				offset = timedelta(hours = 5) # one hr off during DST is acceptable for this application
				expiry += offset
				expiry = expiry.strftime("%d/%m/%YT05:00:00")

			style_class = "%s %s" % (banner_bg, text_color)

			# we trust user input here. they're already admins...

			banner_content = templates.get("alert_banner").format(**locals())
			if override_hours:
				banner_content = "<script>var override_hours = '{override_hours}';</script>{banner_content}".format(**locals())

			logging.info("User %s published alert banner reading \"%s\"" % (nickname, message))
			gae_db.add_or_update_page("banner", banner_content)
Exemple #39
0
def run():
    print("Creating index")
    html = templates.get("index")
    html = templates.initial_replace(html, 0)
    html = templates.final_replace(html, ".")
    util.writefile("../index.html", html)