def serve_add_word(self, request): msg_parts = utils.read_post_msg(request) course_id = utils.parse_id(request.path) w = self.db.add_word(course_id, msg_parts) ret_string = "word_id=%d&native=%s&phonetical=%s&romanized=%s&english=%s" % w return (200, 'text/plain', ret_string)
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 resume(req): conn = get_torrent_connection() value = parse_id(conn.torrents(), req['text']) if value is None: return create_incorrect_id_message(conn, req) torrent = conn.torrents()[value] conn.resume(torrent['hash']) return torrent['name'] + ' resumed'
def delete(req): conn = get_torrent_connection() value = parse_id(conn.torrents(), req['text']) if value is None: return create_incorrect_id_message(conn, req) torrent = conn.torrents()[value] conn.delete_permanently(torrent['hash']) return torrent['name'] + ' deleted'
def insert_or_update(cls, people_entry): """ 新建或者更新用户档案 """ profile = cls.get_by_douban_id(parse_id(people_entry)) if profile is None: profile = cls.insert(people_entry) else: profile.update(people_entry) return profile
def get_new_words(self, request): course_id = utils.parse_id(request.path) words = self.db.get_new_words(course_id, 5) print words wlstring = "|" sep = "@" for w in words: wlstring += ("%d" % w[0]) + sep + w[1] + sep + w[2] + sep + w[3] + "|" return (200, 'text/plain; charset=utf8', wlstring)
def insert(cls, people_entry): """ 新建用户档案 """ url, image_url, blog_url = parse_urls(people_entry) new_profile = DoubanProfile(douban_id=parse_id(people_entry), \ user_name=u(people_entry.uid.text), \ screen_name=u(people_entry.title.text), \ location=u(people_entry.location.text), \ content=u(people_entry.content.text), \ url=url, \ image_url=image_url, \ blog_url=blog_url) new_profile.put() return new_profile
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 search(self, request): lang_id = utils.parse_id(request.path) msg_parts = utils.read_post_msg(request) native = '' if msg_parts['native'] != '': native = msg_parts['native'] else: return (200, 'text/plain', 'none') words = self.db.search_words(lang_id, native) print words wlist = utils.two_level_list(words) print wlist wlstring = "|" for w in wlist: wlstring += w[0] + "," + w[1] + "," + w[2] + "|" return (200, 'text/plain; charset=utf8', wlstring)
def alternatives(self, request): course_id = utils.parse_id(request.path) lang_id = self.db.get_lang_from_course(course_id) eng_alts = self.db.get_eng_list(lang_id) nat_alts = self.db.get_nat_list(lang_id) phon_alts = self.db.get_phon_list(lang_id) alts_text = '|' for e in eng_alts: alts_text += e + '|' alts_text += '\r\n|' for p in phon_alts: alts_text += p + '|' alts_text += '\r\n|' for n in nat_alts: alts_text += n + '|' return (200, 'text/plain; charset=utf8', alts_text)
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)
def start_learning(self, request): course_id = utils.parse_id(request.path) self.db.start_learning(course_id) return self.serve_learning_center_page()
def erase_word(self, request): word_id = utils.parse_id(request.path) lang_id = self.db.erase_word(word_id) return self.serve_lang_info_page(lang_id)
def edit_word(self, request): word_id = utils.parse_id(request.path) msg_parts = utils.read_post_msg(request) print msg_parts self.db.update_word(word_id, msg_parts) return self.serve_word_info_page(word_id)
def serve_word_info(self, request): word_id = utils.parse_id(request.path) return self.serve_word_info_page(word_id)
def serve_course_info(self, request): course_id = utils.parse_id(request.path) print course_id return self.serve_course_info_page(course_id)
def serve_lang_info(self, request): lang_id = utils.parse_id(request.path) return self.serve_lang_info_page(lang_id)
def add_course(self, request): lang_id = utils.parse_id(request.path) msg_parts = utils.read_post_msg(request) self.db.add_new_course(lang_id, msg_parts['course_name'], msg_parts['course_type']) return (self.serve_lang_info_page(lang_id))