def get(self): # OAth2 for douban KEY = conf['douban_app_key'] SECRET = conf['douban_app_secret'] CALLBACK = conf['url'] + '/dback' SCOPE = 'douban_basic_common,community_basic_user,community_basic_note' client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE) douban_login = client.authorize_url # OAth2 for sina_weibo APP_KEY = conf['weibo_app_key'] APP_SECRET = conf['weibo_app_secret'] CALLBACK_URL = conf['url'] + '/wback' weibo_client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) weibo_login = weibo_client.get_authorize_url() # statistics diary_count = Diary.get_diary_count() last_diary = Diary.get_last_diary() first_diary = Diary.get_first_diary() comment_count = Comment.get_comment_count() usr = tornado.escape.xhtml_escape(self.current_user) site_start = Admin.find_by_username(usr).get('site_start') self.render('Admin/dashboard.html', douban_login=douban_login, diary_count=diary_count, last_diary=last_diary, first_diary=first_diary, site_start=site_start, comment_count=comment_count, weibo_login=weibo_login )
def post(self, *args): try: did = self.get_argument('did') date = self.get_argument('date') except Exception as e: print str(e) try: Diary.set_date(did, date) self.write('success') except Exception as e: print str(e)
def get(self): try: rss = Diary.output_rss() except Exception as e: print str(e) self.render('rss.html', rss=rss)
def get(self, *args): try: profile = Account.get() categories = Category.get() except Exception as e: print str(e) if profile is None: self.redirect("/admin") return try: diaries = Diary.get() amount = diaries.count() except Exception as e: print str(e) return number = diaries.count(with_limit_and_skip=True) if number == 5: next_page = True elif number < 1: self.send_error(404) return else: next_page = False self.render("index.html", profile=profile, diaries=diaries, next_page=next_page, categories=categories)
def get(self, _id): try: detail = Diary.del_diary(_id) except Exception as e: print str(e) self.redirect('/admin/all-post/1')
def get(self, _id): try: detail = Diary.get_detail(_id) categories = Category.get() except: self.redirect('/admin') self.render('Admin/Diary/edit.html', detail=detail, categories=categories)
def get(self, *args): offset = int(self.get_argument('offset')) try: more = Diary.load_more(offset) except Exception as e: print str(e) self.write(json.dumps(more))
def post(self, *args): try: did = self.get_argument('did') title = self.get_argument('title') content = self.get_argument('content') c_name = self.get_argument('category_name') c_id = self.get_argument('c_id') except Exception as e: refer = self.request.headers.get('Referer') self.redirect(refer) try: tags = self.get_argument('tags') except: tags = None if tags: splited_tags = tags.split(',') else: splited_tags = None """" determin whether there is a exist undefine category if there is not, create it else use its c_id """ if c_id == 'none': detail = Category.find_by_name(c_name) try: c_id = detail.get('_id') except: c_id = Category.new(c_name) try: Diary.update(did, title, content, c_name, c_id, splited_tags) except Exception as e: print str(e) self.redirect('/admin/all-post/1')
def get(self, page): try: diaries = Diary.get_diary_list(page) except Exception as e: print str(e) number = diaries.count(with_limit_and_skip=True) if number == 5: next_page = True elif number < 1: self.send_error(404) return else: next_page = False self.render('Admin/Diary/list.html', diaries=diaries, page=page, next_page=next_page)
def get(self, _id): try: detail = Diary.get_detail(_id) categories = Category.get() except Exception as e: self.send_error(404) send_error_email('Diary Detail Error', str(e)) if detail is not None: profile = Account.get() try: guest_name = self.get_secure_cookie('guest_name') guest_email = self.get_secure_cookie('guest_email') except: guest_name = None guest_email = None self.render('Diary/detail.html', detail=detail, profile=profile, guest_name=guest_name, guest_email=guest_email, categories=categories) else: self.send_error(404)
def get(self, page): try: profile = Account.get() diaries = Diary.get_diary_list(page) categories = Category.get() except Exception as e: self.send_error(404) send_error_email('Diary List Error', str(e)) number = diaries.count(with_limit_and_skip=True) if number == 5: next_page = True elif number < 1: self.send_error(404) return else: next_page = False self.render('Diary/list.html', diaries=diaries, profile=profile, page=page, next_page=next_page, categories=categories)
def get(self, *args): KEY = "08e0dfb50c90b0991aa29f1f25b211cb" SECRET = "378ed0dadf96de47" CALLBACK = conf["url"] + "/dback" SCOPE = "douban_basic_common,community_basic_user,community_basic_note" client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE) code = self.get_argument("code") if code: client.auth_with_code(code) auth = client.user.me if auth: accounts = conf["db"].accounts account = { "_id": Kid.kid(), "id": auth.get("id"), "name": auth.get("name"), "avatar": auth.get("avatar"), "loc_name": auth.get("loc_name"), "desc": auth.get("desc"), } try: exist = Account.get_by_id(auth.get("id")) if exist is None: accounts.save(account) else: accounts.update({"id": auth.get("id")}, {"$set": account}) except Exception as e: print str(e) diary = client.note.list(auth.get("id"), 0, 20) diaries = conf["db"].diaries diary_notes = diary.get("notes") for i in diary_notes: # re-summary content from douban summary = i.get("content")[0:80] + "..." diary = { "_id": Kid.kid(), "update_time": i.get("update_time"), "publish_time": i.get("publish_time"), "photos": i.get("photos"), "comments_count": i.get("comments_count"), "liked_count": i.get("liked_count"), "recs_count": i.get("recs_count"), "id": i.get("id"), "alt": i.get("alt"), "can_reply": i.get("can_reply"), "title": i.get("title"), "privacy": i.get("privacy"), "summary": summary, "content": client.note.get(i.get("id"), format="html_full").get("content"), } try: exist = Diary.get_by_id(i.get("id")) if exist is None: diaries.save(diary) else: diaries.update({"id": i.get("id")}, {"$set": diary}) except Exception as e: print str(e) self.redirect("/") else: print "douban_callback code missing"