示例#1
0
    def get(self, cid, page):
        try:
            categories = Category.get()
            detail = Category.find_by_id(cid, page)
        except Exception as e:
            self.send_error(404)
            send_error_email('Category List Error', str(e))

        L = detail['diaries']
        sorted_diaries = sorted(L, key=itemgetter('did'), reverse=True) 

        number = len(sorted_diaries)

        if number == 15:
            next_page = True
        elif number < 1:
            self.send_error(404)
            return 
        else:
            next_page = False

        if detail is not None:
            profile = Account.get()
            self.render('Category/list.html', detail=detail, categories=categories, profile=profile, sorted_diaries=sorted_diaries, page=page, next_page=next_page, cid=cid)
        else:
            self.send_error(404)
示例#2
0
    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)
示例#3
0
    def get(self, *args):
        try:
            albums = Gallary.get_all()
            profile = Account.get()
        except Exception as e:
            self.send_error(404)
            send_error_email('Gallary get Error', str(e))

        self.render('Gallary/index.html', albums=albums, profile=profile)
示例#4
0
文件: search.py 项目: RTNelo/dev_blog
    def post(self, *args):
        try:
            keywords = self.get_argument('keywords')
        except:
            keywords = None

        if keywords is not None:
            Calculate.search_add_keyword(keywords)
            try:
                categories = Category.get()
                cate_result = Category.find_by_name(keywords)
                tag_result = Tag.find_by_name(keywords)
            except Exception as e:
                self.send_error(404)
                send_error_email('Search Error', str(e))

            try:
                C = cate_result['diaries']
            except:
                C = []

            try:
                T = tag_result['diaries']
            except:
                T = []

            real_result = list(C+T)

            """
                To combine tag_result and category_result
                first make an empty list to save filtered_result
                and to make faster, make another empty list to save diary_id to ensure not append repeat diary
            """

            filtered_result = []
            cache_did = []

            for i in real_result:
                if cache_did == []:
                    cache_did.append(i['did'])
                    filtered_result.append(i)
                else:
                    if i['did'] not in cache_did:
                        cache_did.append(i['did'])
                        filtered_result.append(i)

            profile = Account.get()

            if filtered_result != []:
                self.render('Search/result.html', detail=filtered_result, categories=categories, profile=profile)
            else:
                filtered_result = None
                self.render('Search/result.html', detail=filtered_result, categories=categories, profile=profile)
        else:
            self.redirect('/')
示例#5
0
    def get(self, name):
        try:
            categories = Category.get()
            detail = Tag.find_by_name(name)
        except Exception as e:
            self.send_error(404)
            send_error_email('Tag List Error', str(e))

        L = detail['diaries']
        sorted_diaries = sorted(L, key=itemgetter('did'), reverse=True)
        if detail is not None:
            profile = Account.get()
            self.render('Tag/list.html', detail=detail, categories=categories, profile=profile, sorted_diaries=sorted_diaries)
        else:
            self.send_error(404)
示例#6
0
def generateHtml(content, did, username):
    avatar = Account.get().get('avatar')
    html = '<table style="width: 100%;"><thead style=" width: 100%;color: #FFF; height: 75px; background-color: #bdcadf; -webkit-box-shadow: 0 1px 1px rgba(255,255,255,.5), inset 0 1px 3px #183357; -moz-box-shadow: 0 1px 1px rgba(255,255,255,.5), inset 0 1px 3px #183357; box-shadow: 0 1px 1px rgba(255,255,255,.5), inset 0 1px 3px #183357; background-image: -webkit-linear-gradient(bottom, #647792, #8d9baf); background-image: -moz-linear-gradient(bottom, #647792, #8d9baf); background-image: -o-linear-gradient(bottom, #647792, #8d9baf); background-image: -ms-linear-gradient(bottom, #647792, #8d9baf); background-image: linear-gradient(to top, #647792, #8d9baf);"><tr><td colspan="2" style="padding: 5px 0 5px 2%;">'
    html += conf['title']
    html += '</td></tr></thead><tbody><tr>'
    html += '<td style="width: 25%;padding:10px 0;"><img src="'+ str(avatar) +'"></td><td><b>'
    html += username.encode("utf-8")
    html += '</b>:<br />'
    html += content.encode("utf-8")
    html += '</td></tr><tr style="background: #F2F2F2"><td colspan="2" style="padding: 10px 0 10px 25%; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;">'
    html += '<a style="-webkit-transform: translateY(0); -webkit-transition: -webkit-transform .2s ease-out; -moz-transform: translateY(0); -moz-transition: -moz-transform .2s ease-out; transform: translateY(0); transition: -moz-transform .2s ease-out; position: relative; top: 0; background-image: -webkit-linear-gradient(#6389C1, #4369A1); background-image: -moz-linear-gradient(#6389C1, #4369A1); background-image: -linear-gradient(#6389C1, #4369A1); height: 24px; box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 5px 1px; border: 1px solid rgba(53, 85, 131, 0.9); border-radius: 2px; text-shadow: 0 1px rgba(0, 0, 0, 0.5); margin-top: 0px; cursor: pointer; font-size: 13px; font-family: Vavont, Helvetica, sans-serif; text-align: center; line-height: 20px; color: rgba(255, 255, 255, 0.99); box-sizing: border-box; margin-bottom: 5px; display: block; padding: 2px 6px 3px; overflow: hidden; text-decoration: none;width:70px;" href="'
    html += conf['url']
    html += '/diary/detail/'
    html += str(did)
    html += '">返回原文</a></td></tr></tbody>'
    html += '<tfoot><tr><td colspan="2" style="font-size:11px;color:#999;padding-top:20px;">Copyright &copy; 2012-2013 Dev_Blog 博客评论邮件提醒。 Written By Scen([email protected])</td></tr></tfoot></table>'
    return html
示例#7
0
    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)
示例#8
0
    def get(self, *args):
        # OAth2 for sina_weibo
        APP_KEY =  conf['weibo_app_key']
        APP_SECRET = conf['weibo_app_secret']
        CALLBACK_URL = conf['url'] + '/wback'

        client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)

        code = self.get_argument('code')
        r = client.request_access_token(code)
        access_token = r.access_token
        expires_in = r.expires_in
        client.set_access_token(access_token, expires_in)

        _id = client.account.get_uid.get().get('uid')
        auth = client.users.show.get(uid=_id)
        
        if auth:
            accounts = conf['db'].accounts
            account = {
                    "_id": Kid.kid(),
                    "id": auth.get('id'),
                    "name": auth.get('screen_name'),
                    "avatar": auth.get('profile_image_url'),
                    "loc_name": auth.get('location'),
                    "desc": auth.get('description'),
                    }

            try:
                exist = Account.get_by_id(auth.get('id'))

                if exist is None:
                    accounts.save(account)
                else:
                    accounts.update({'id': int(auth.get('id'))}, {'$set': account})

                    self.set_secure_cookie("user", account.get('name'))
            except Exception as e:
                print str(e)

            self.redirect('/')
示例#9
0
    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)
示例#10
0
    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"