def serve_edit_word(self, request): word_id = utils.parse_id(request.path) word_info = self.db.get_word(word_id) page = utils.open_unicode_file('edit_word.html') page = page.replace('$$????native$$', word_info[2]) page = page.replace('$$????eng$$', word_info[5]) page = page.replace('$$????phon$$', word_info[3]) page = page.replace('$$????roman$$', word_info[4]) page = page.replace('$$????wid$$', "%s" % word_info[0]) pos = '' if word_info[8] != None: pos = word_info[8] page = page.replace('$$????pos$$', pos) alt_nat = '' if word_info[6] != None: alt_nat = word_info[6] page = page.replace('$$????alt_nat$$', alt_nat) alt_phon = '' if word_info[7] != None: alt_phon = word_info[7] page = page.replace('$$????alt_phon$$', alt_phon) return (200, 'text/html; charset=utf-8', page)
def serve_word_info_page(self, word_id): word_info = self.db.get_word(word_id) lang = self.db.get_language_name_from_id(word_info[1]) page = utils.open_unicode_file('word_info.html') page = page.replace('$$????native$$', word_info[2]) page = page.replace('$$????lang$$', lang) page = page.replace('$$????lid$$', u"%d" % word_info[1]) page = page.replace('$$????eng$$', word_info[5]) page = page.replace('$$????phon$$', word_info[3]) page = page.replace('$$????roman$$', word_info[4]) page = page.replace('$$????wid$$', "%s" % word_info[0]) pos = '' if word_info[8] != None: pos = word_info[8] else: pos = '-' page = page.replace('$$????pos$$', pos) alt_nat = '' if word_info[6] != None: alt_nat = word_info[6] else: alt_nat = '-' page = page.replace('$$????alt_nat$$', alt_nat) alt_phon = '' if word_info[7] != None: alt_phon = word_info[7] else: alt_phon = '-' page = page.replace('$$????alt_phon$$', alt_phon) return (200, 'text/html; charset=utf-8', page)
def serve_new_lang(self, request): languages = self.db.get_lang_names() lang_names = "'" + languages[0][0].lower() + "'" for l in languages[1:]: lang_names += ", '" + l[0].lower() + "'" page = utils.open_unicode_file('new_lang.html') page = page.replace(u"$$????$$", "[" + lang_names + "]", 1) return (200, 'text/html; charset=utf-8', page)
def serve_styles_and_scripts(self, request): page = utils.open_unicode_file(request.path[1:]) content_type = "" if request.path.endswith('.js'): content_type += "application/javascript; charset=utf-8" elif request.path.endswith('.css'): content_type += "text/css; charset=utf-8" return (200, content_type, page)
def serve_root_page(self, request): langs = self.db.get_languages() table_html = '' for l in langs: table_html += ''' <tr onclick=\"location.href='lang_info?%d';\"> <td>%s</td><td>%d</td><td>%d</td> </tr>''' % (l[0], l[1], l[2], l[3]) page = utils.open_unicode_file('languages.html') page = page.replace(u"$$????$$", table_html, 1) return (200, 'text/html; charset=utf-8', page)
def serve_learning_center_page(self): stats = self.db.collect_learning_stats() print stats stats_str = "[" stats_str += self.create_lang_stat_string(stats[0]) for s in stats[1:]: stats_str += "," + self.create_lang_stat_string(s) stats_str += "]" page = utils.open_unicode_file('learning_center.html') page = page.replace('$$????stats$$', stats_str) return (200, 'text/html; charset=utf-8', page)
def serve_add_course(self, request): lang_id = utils.parse_id(request.path) language = self.db.get_language_name_from_id(lang_id) courses = self.db.get_courses(lang_id) courses_names = "''" for c in courses: courses_names += ", '" + c[1] + "'" page = utils.open_unicode_file('new_course.html') page = page.replace('$$????lid$$', u"%d" % lang_id) page = page.replace('$$????lname$$', language) page = page.replace('$$????cnames$$', courses_names) return (200, 'text/html; charset=utf-8', page)
def serve_lang_info_page(self, lang_id): language = self.db.get_language_name_from_id(lang_id) courses = self.db.get_courses(lang_id) courses_table = "" for c in courses: courses_table += ''' <tr onclick=\"location.href='course_info?%d';\"> <td>%s</td><td>%d</td> </tr>''' % c page = utils.open_unicode_file('lang_info.html') page = page.replace('$$????lname$$', language) page = page.replace('$$????lid$$', u"%d" % lang_id) page = page.replace('$$????ncourse$$', len(courses).__str__()) page = page.replace('$$????clist$$', courses_table) return (200, 'text/html; charset=utf-8', page)
def serve_course_info_page(self, course_id): course_info = self.db.get_course(course_id) print course_info course_name = course_info[2] words = self.db.get_words(course_id) table_string = ''' <table id=\"wordsT\"> <tr> <th>Native</th> <th>Phonetical</th> <th>Romanized</th> <th>English</th> </tr>''' for w in words: table_string += self.word_row(w) table_string += "</table>" page = utils.open_unicode_file('course_info.html') page = page.replace('$$????cname$$', course_name) page = page.replace('$$????wtable$$', table_string) page = page.replace('$$????cid$$', "%d" % course_id) page = page.replace('$$????lid$$', u"%d" % self.db.get_lang_from_course(course_id)) page = page.replace('$$????lname$$', self.db.get_language_name(course_id)) print course_info[4] if course_info[4] == False: page = page.replace('$$????link$$', '''<a href=\"start_learning?%d\"> Start Learning This Course! </a>''' % course_info[0]) else: page = page.replace('$$????link$$', u'''<a href=\"learning_center\"> To Learning Center → </a>''') return (200, 'text/html; charset=utf-8', page)
def serve_learning_page(self, request): course_id = utils.parse_id(request.path) page = utils.open_unicode_file('learn_new_words.html') page = page.replace('$$????cid$$', "%d" % course_id) return (200, 'text/html; charset=utf8', page)