def post(self): method = self.request.get('method') name = self.request.get('name') if method == 'add': if Category.all().filter('name =', name).fetch(1) == []: cat = Category() cat.name = name cat.count = 0 cat.put() elif method == 'del': victim = Category.all().filter('name =', name).get() for art in victim.articles: art.category = None art.has_category = False art.put() victim.delete() # Categories of related articles become unsorted #group = Article.all().filter('category =', name).fetch(1000) #while group != []: # for art in group: # art.category = None # art.put() # group = Article.all().filter('category =', name).fetch(1000) else: (new_name, old_name) = name.split('$') target = Category.all().filter('name =', old_name).get() target.name = new_name target.put() self.redirect('/atf-category')
def get(self): urls = [] host = 'http://blog-pj.appspot.com' urls.append(Url(host + '/archive', 'monthly', '1.00')) urls.append(Url(host + '/guestbook', 'monthly', '1.00')) urls.append(Url(host + '/about', 'monthly', '1.00')) urls.append(Url(host + '/feed', 'monthly', '1.00')) cats = Category.all() for cat in cats: urls.append(Url(host + '/category/' + cat.name, 'monthly', '0.8')) urls.append(Url(host + '/category/unsorted', 'monthly', '0.8')) tags = Tag.all() for tag in tags: urls.append(Url(host + '/tag/' + tag.name, 'monthly', '0.8')) arcs = Archive.all() for arc in arcs: urls.append(Url(host + '/date/' + str(arc.year) + \ '/' + str(arc.month), 'monthly', '0.8')) arts = Article.all() for art in arts: urls.append(Url(host + '/article/' + art.permalink, 'monthly', '0.6')) template_values = { 'urls': urls } path = os.path.join(os.path.dirname(__file__), 'sitemap.xml') self.response.out.write(template.render(path, template_values))
def get(self): cats = Category.all().order('-name').fetch(1000) path = os.path.join(os.path.dirname(__file__), 'pages/categoryAdmin.html') template_values = { 'logout_url': users.create_logout_url('/'), 'page_name': 'categoryAdmin', 'cats': cats } self.response.out.write(template.render(path, template_values))
def post(self): content = self.request.get('content') method = self.request.get('method') if method == 'preview': self.do_preview(self, content) elif method == 'publish': link = self.request.get('permalink') target = db.GqlQuery('''select * from Article where permalink = :1''', link).get() if target != None: self.save_title = self.request.get('thetitle') self.save_content = content self.save_permalink = link self.save_permit_comment = self.request.get('permitComment') self.save_category = self.request.get('cat') self.save_tags = self.request.get('tags') self.get() else: article = Article() article.thetitle = self.request.get('thetitle') article.content = content article.thumbnail = self.request.get('thumbnail') article.permalink = self.request.get('permalink') article.permit_comment = True if self.request.get('permitComment') == 'permit' else False cat = self.request.get('cat') if cat == 'unsorted': article.has_category = False else: article.has_category = True cat_item = Category.all().filter('name = ', cat).get() article.category = cat_item cat_item.count = cat_item.count + 1 cat_item.put() mod_archive(article) article.year = article.time_stamp.year article.month = article.time_stamp.month article.day = article.time_stamp.day article.id = str(article.time_stamp.year) + '-' + str(article.time_stamp.month) + '-' + str(article.time_stamp.day) + '-' + \ str(article.time_stamp.hour) + '-' + str(article.time_stamp.minute) + '-' + str(article.time_stamp.second) + '-' + \ str(article.time_stamp.microsecond) query = Article.all().order('-time_stamp').fetch(1) record = None if query == [] else query[0] if record != None: record.link_next = article.permalink record.year_next = article.year record.month_next = article.month record.day_next = article.day record.title_next = article.thetitle record.put() article.link_prev = record.permalink article.year_prev = record.year article.month_prev = record.month article.day_prev = record.day article.title_prev = record.thetitle else: article.link_prev = '' article.year_prev = -1 article.month_prev = -1 article.day_prev = -1 article.title_prev = '' article.link_next = '' article.year_next = -1 article.month_next = -1 article.day_next = -1 article.title_next = '' article.put(); mod_article_tag(article, self.request.get('tags').split(' '), False) self.redirect('/atf-articles'); # Modify an article else: # Article to be modified target = Article.all().filter('id =', self.request.get('articleId')).get() link = self.request.get('permalink') # If there exists an article with that link name suspect = db.GqlQuery('''select * from Article where permalink = :1''', link).get() if suspect != None and target.id != suspect.id: self.save_title = self.request.get('thetitle') self.save_content = content self.save_permalink = link self.save_permit_comment = self.request.get('permitComment') self.save_category = self.request.get('cat') self.save_tags = self.request.get('tags') self.get() else: if target.has_category: target.category.count = target.category.count - 1 target.category.put() target.thetitle = self.request.get('thetitle') target.content = content target.thumbnail = self.request.get('thumbnail') target.permalink = self.request.get('permalink') target.permit_comment = True if self.request.get('permitComment') == 'permit' else False cat = self.request.get('cat') if cat == 'unsorted': target.category = None target.has_category = False else: target.has_category = True target.category = Category.all().filter('name =', self.request.get('cat')).get() target.category.count = target.category.count + 1 target.category.put() target.put() mod_article_tag(target, self.request.get('tags').split(' '), True) self.redirect('/atf-articles');
def add_change(self, line_number, line): if len(self.changes) == self.maxchanges: self.changes = self.changes[1:] self.offset += 1 self.changes.append(( self.next_idx, line_number, line, )) self.next_idx += 1 def changes_after(self, change_number): return self.changes[change_number - self.offset:] appstate = Category() class AppState(object): def __init__(self): self.session = None self.changes = ChangeTable(MAX_CHANGES) self.subscribers = [] self.chat = Chat(self, ApiNamespace) self.owner = None @synchronized(appstate) def start(self): if self.session: return self.session = TerminalSession(COMMAND,
def get(self): temp = self.request.path.split('/') key = temp[1] try: pageno = int(temp[-1]) except ValueError: pageno = 1 if key == 'category': if len(temp) == 4 or len(temp) > 3 and temp[3] != 'page': path = os.path.join(os.path.dirname(__file__), 'pages/error.html') self.response.out.write(template.render(path, None)) return name = unicode(urllib.unquote(temp[2]), 'utf-8') if name == 'unsorted': query = Article.all().filter('has_category =', False).order('-time_stamp') else: query = Category.all().filter('name =', name) if query.get() != None: query = query.get().articles.order('-time_stamp') elif key == 'tag': if len(temp) == 4 or len(temp) > 3 and temp[3] != 'page': path = os.path.join(os.path.dirname(__file__), 'pages/error.html') self.response.out.write(template.render(path, None)) return name = unicode(urllib.unquote(temp[2]), 'utf-8') query = Tag.all().filter('name =', name) if query.get() != None: query = query.get().ref_tag.order('-time_stamp') else: year = int(temp[2]) month = int(temp[3]) pageno = 1 if len(temp) > 4: try: pageno = int(temp[-1]) except ValueError: pageno = 1 name = str(year) + '/' + str(month) query = db.GqlQuery('select * from Archive where year = :1 and month = :2', year, month) if query.get() != None: query = query.get().articles.order('-time_stamp') group = query.fetch(1000) article_list = [] pagei = 0 start = 0 length = len(group) while group != [] and article_list == []: # Pick out each page while start + self.article_per_page - 1 < length: pagei = pagei + 1 if pagei == pageno: article_list = group[start : start + self.article_per_page] start = start + self.article_per_page if len(group[start : start + self.article_per_page]) > 0: pagei = pagei + 1 if pagei == pageno: article_list = group[start : start + self.article_per_page] last_time = group[-1].time_stamp query.filter('time_stamp <', last_time) group = query.fetch(1000) show_left_arrow = 1 if pageno > 1 else 0 show_right_arrow = 1 if pageno < pagei else 0 show_left_dot = 1 if pageno >= 5 else 0 show_right_dot = 1 if pageno <= pagei - 4 else 0 pageno_list = [i for i in range(max(1, pageno - 3), min(pagei + 1, pageno + 4))] if key == 'tag': article_set = [] for item in article_list: article_set.append(item.article) template_values = { 'articles': article_list if key != 'tag' else article_set, 'pagename': 'articles', 'page_current': pageno, 'page_total': pagei, 'pageno_list': pageno_list, 'show_left_arrow': show_left_arrow, 'show_right_arrow': show_right_arrow, 'show_left_dot': show_left_dot, 'show_right_dot': show_right_dot, 'colno': len(pageno_list) + show_left_arrow + show_right_arrow + show_left_dot + show_right_dot, 'page_prev': max(1, pageno - 1), 'page_next': min(pagei, pageno + 1), 'categories': get_all_categories(), 'tags': get_all_tags(), 'name': name, 'key': key, 'unsorted_count': count_unsorted(), } path = os.path.join(os.path.dirname(__file__), 'pages/articles.html') self.response.headers['Content-Type'] = 'text/html;charset=utf-8' self.response.out.write(template.render(path, template_values))