예제 #1
0
파일: blog.py 프로젝트: cash2one/cms4p
    def get(self, list_type='', direction='next', page='1', name=''):
        catobj = None
        if list_type == 'cat':
            #objs = Category.get_posts_by_name(name, page)
            catobj = Categories.get_by_category_name(name)
            show_type = catobj.showtype
        elif list_type == 'tag':
            objs = Tags.get_page_posts_by_tag_name(name, page)
            catobj = Tags.get_tag_by_name(name)
            show_type = "list"
        elif list_type == 'archive':
            objs = Archives.get_page_posts_by_archive_name(name, page)
            catobj = Archives.get_by_name(name)
            show_type = "list"

        if catobj:
            pass
        else:
            self.redirect(BASE_URL)
            return

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = catobj.id_num
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1

        output = self.render(show_type + '.html', {
            'title':
            "%s - %s | Part %s" % (catobj.name, getAttr('SITE_TITLE'), page),
            'keywords':
            catobj.name,
            'description':
            getAttr('SITE_DECR'),
            'objs':
            objs,
            'cats':
            Categories.get_all_category_name(),
            'tags':
            Tags.get_hot_tag(),
            'archives':
            Archives.get_by_name(),
            'page':
            int(page),
            'allpage':
            all_page,
            'listtype':
            list_type,
            'name':
            name,
            'namemd5':
            md5(name.encode('utf-8')).hexdigest(),
            'comments':
            Comments.get_recent_comments(),
            'links':
            Links.get_all(),
        },
                             layout='_layout.html')
        self.write(output)
        return output
예제 #2
0
    def tags_skip_list(self):
        key = 'tags_skip_list'

        if Options().caching and DataCacher().cached_already(key):
            return DataCacher().get_cached(key)

        tags_list = Tags().skip_tags()

        if Options().caching:
            DataCacher().cache(key, tags_list)

        return tags_list
예제 #3
0
파일: blog.py 프로젝트: cash2one/cms4p
    def get(self, direction='next', page='2', base_id='1'):
        if page == '1':
            self.redirect(BASE_URL)
            return
        objs = Posts.get_paged(direction, page, base_id)
        if objs:
            if direction == 'prev':
                objs.reverse()
            fromid = objs[0].id
            endid = objs[-1].id
        else:
            fromid = endid = ''

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = Posts.count_all()
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1
        output = self.render('default.html', {
            'title':
            "%s - %s | Part %s" %
            (getAttr('SITE_TITLE'), getAttr('SITE_SUB_TITLE'), page),
            'keywords':
            getAttr('KEYWORDS'),
            'description':
            getAttr('SITE_DECR'),
            'objs':
            objs,
            'cats':
            Categories.get_all_category_name(),
            'tags':
            Tags.get_hot_tag(),
            'archives':
            Archives.get_by_name(),
            'page':
            int(page),
            'allpage':
            all_page,
            'listtype':
            'index',
            'fromid':
            fromid,
            'endid':
            endid,
            'comments':
            Comments.get_recent_comments(),
            'links':
            Links.get_all(),
        },
                             layout='_layout.html')
        self.write(output)
        return output
예제 #4
0
파일: blog.py 프로젝트: cash2one/cms4p
    def get(self, name=''):
        objs = Tags.get_page_posts_by_tag_name(name, 1)

        catobj = Tags.get_tag_by_name(name)
        if catobj:
            pass
        else:
            self.redirect(BASE_URL)
            return

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = catobj.id_num
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1

        output = self.render(
            'list.html', {
                'title': "%s - %s" % (catobj.name, getAttr('SITE_TITLE')),
                'keywords': catobj.name,
                'description': getAttr('SITE_DECR'),
                'objs': objs,
                'cats': Categories.get_all_category_name(),
                'tags': Tags.get_hot_tag(),
                'archives': Archives.get_by_name(),
                'page': 1,
                'allpage': all_page,
                'listtype': 'tag',
                'name': name,
                'namemd5': md5(name.encode('utf-8')).hexdigest(),
                'recent_article': Posts.get_last_post(8),
                'comments': Comments.get_recent_comments(),
                'links': Links.get_all(),
            },
            layout='_layout.html')
        self.write(output)
        return output
예제 #5
0
    def tags_list(self):
        key = 'tags_list'

        if Options().caching and DataCacher().cached_already(key):
            return DataCacher().get_cached(key)

        if Options().include_drafts:
            posts = self.posts_files
        else:
            posts = self.posts_published

        tags_list = Tags().list(posts)

        if Options().caching:
            DataCacher().cache(key, tags_list)

        return tags_list
예제 #6
0
    def tags_posts_count(self, tag):
        key = 'tags_posts_count/{0}'.format(tag)

        if Options().caching and DataCacher().cached_already(key):
            return DataCacher().get_cached(key)

        if Options().include_drafts:
            posts = self.posts_files
        else:
            posts = self.posts_published

        data = Tags().count_posts(posts, tag)

        if Options().caching:
            DataCacher().cache(key, data)

        return data
예제 #7
0
    def tags_data(self, tag, page_index):
        key = 'tags_data/{0}/{1}'.format(tag, page_index)

        if Options().caching and DataCacher().cached_already(key):
            return DataCacher().get_cached(key)

        if Options().include_drafts:
            posts = self.posts_files
        else:
            posts = self.posts_published

        common = self.common_data
        data = Tags().data(posts, tag, page_index, self.index_max_posts,
                           self.tags_posts_count(tag))
        combined = self.__combine(common, data)

        if Options().caching:
            DataCacher().cache(key, combined)

        return combined
예제 #8
0
파일: blog.py 프로젝트: cash2one/cms4p
    def get(self):
        try:
            news1 = Categories.get_posts_by_category_id(category_id=7, limit=8)
            news2 = Categories.get_posts_by_category_id(category_id=9, limit=8)
            prods = Categories.get_posts_by_category_id(category_id=3, limit=8)
        except:
            self.redirect('/install')
            return

        each_page_post_num = int(getAttr('EACH_PAGE_POST_NUM'))
        all_post = Posts.count_all()
        all_page = all_post / each_page_post_num
        if all_post % each_page_post_num:
            all_page += 1

        output = self.render('index.html', {
            'title':
            "%s - %s" % (getAttr('SITE_TITLE'), getAttr('SITE_SUB_TITLE')),
            'keywords':
            getAttr('KEYWORDS'),
            'description':
            getAttr('SITE_DECR'),
            'news1':
            news1,
            'news2':
            news2,
            'prods':
            prods,
            'cats':
            Categories.get_all_category_name(),
            'tags':
            Tags.get_hot_tag(),
            'archives':
            Archives.get_top_n(),
        },
                             layout='_layout.html')
        self.write(output)
        return output
예제 #9
0
    def from_json(cls, json):
        if json is None:
            return Poi()

        if type(json) is list:
            return [Poi.from_json(poi) for poi in json]

        try:
            eventsHistory = [
                EventsHistory.from_json(_eventsHistory)
                for _eventsHistory in json.get('eventsHistory')
            ]
        except TypeError:
            eventsHistory = []

        try:
            images = [
                Images.from_json(_images) for _images in json.get('images')
            ]
        except TypeError:
            images = []

        return Poi(json.get('id'),
                   LocationPoint.from_json(json.get('locationPoint')),
                   json.get('type'), json.get('firstTimeSeen'),
                   AddressDetails.from_json(json.get('addressDetails')),
                   json.get('dealType'), json.get('address'),
                   json.get('matchScore'), json.get('beds'), json.get('baths'),
                   json.get('buildingYear'), json.get('area'),
                   json.get('price'), json.get('virtualTours'),
                   json.get('rentalBrokerFee'), eventsHistory,
                   Status.from_json(json.get('status')),
                   Poc.from_json(json.get('poc')),
                   Tags.from_json(json.get('tags')), json.get('openHouses'),
                   json.get('commuteTime'), json.get('dogsParkWalkTime'),
                   json.get('parkWalkTime'), json.get('buildingClass'), images,
                   json.get('__typename'),
                   Insights.from_json(json.get('insights')))
예제 #10
0
파일: posts.py 프로젝트: dreambt/cms4p
def post_detail_formate(obj):
    if obj:
        slug = slugfy(obj.title)
        obj.slug = slug
        obj.absolute_url = '%s/topic/%d/%s' % (BASE_URL, obj.id, slug)
        obj.shorten_url = '%s/t/%s' % (BASE_URL, obj.id)
        if '[/code]' in obj.content:
            obj.highlight = True
        else:
            obj.highlight = False
        obj.content = tran_content(obj.content, obj.highlight)
        obj.taglist = ', '.join(
            ["""<a href="%s/tag/%s/" rel="tag">%s</a>""" % (BASE_URL, tag, tag) for tag in obj.tags.split(',')])
        obj.add_time_fn = time_from_now(int(obj.add_time))
        obj.last_modified = timestamp_to_datetime(obj.edit_time)
        obj.keywords = obj.tags
        obj.description = HTML_REG.sub('', obj.content[:DESCRIPTION_CUT_WORDS])
        #get prev and next obj
        obj.prev_obj = sdb.get('SELECT `id`,`title` FROM `cms_posts` WHERE `id` > %s LIMIT 1' % str(obj.id))
        if obj.prev_obj:
            obj.prev_obj.slug = slugfy(obj.prev_obj.title)
        obj.next_obj = sdb.get(
            'SELECT `id`,`title` FROM `cms_posts` WHERE `id` < %s ORDER BY `id` DESC LIMIT 1' % str(obj.id))
        if obj.next_obj:
            obj.next_obj.slug = slugfy(obj.next_obj.title)
        #get relative obj base tags
        obj.relative = []
        if obj.tags:
            idlist = []
            getit = False
            for tag in obj.tags.split(','):
                from model.tags import Tags

                tagobj = Tags.get_tag_by_name(tag)
                if tagobj and tagobj.content:
                    pids = tagobj.content.split(',')
                    for pid in pids:
                        if pid != str(obj.id) and pid not in idlist:
                            idlist.append(pid)
                            if len(idlist) >= RELATIVE_POST_NUM:
                                getit = True
                                break
                if getit:
                    break
                #
            if idlist:
                obj.relative = sdb.query('SELECT `id`,`title` FROM `cms_posts` WHERE `id` in(%s) LIMIT %s' % (
                ','.join(idlist), str(len(idlist))))
                if obj.relative:
                    for robj in obj.relative:
                        robj.slug = slugfy(robj.title)
                    #get comment
        obj.coms = []
        if obj.comment_num > 0:
            if obj.comment_num >= EACH_PAGE_COMMENT_NUM:
                first_limit = EACH_PAGE_COMMENT_NUM
            else:
                first_limit = obj.comment_num
            from model.comments import Comments

            obj.coms = Comments.get_post_page_comments_by_id(obj.id, 0, first_limit)
    return obj
예제 #11
0
파일: blog.py 프로젝트: cash2one/cms4p
    def get(self, post_id='', title=''):
        tmpl = ''
        obj = Posts.get_post_detail(post_id)
        if not obj:
            self.redirect(BASE_URL)
            return
            #redirect to right title
        try:
            title = unquote(title).decode('utf-8')
        except:
            pass
        if title != obj.slug:
            self.redirect(obj.absolute_url, 301)
            return
            #
        if obj.password and THEME == 'default':
            rp = self.get_secure_cookie("rp%s" % post_id, '')
            if rp != obj.password:
                tmpl = '_pw'
        elif obj.password and getAttr('BLOG_PSW_SUPPORT'):
            rp = self.get_secure_cookie("rp%s" % post_id, '')
            print 'rp===%s' % (str(rp))
            if rp != obj.password:
                tmpl = '_pw'

        keyname = 'pv_%s' % (str(post_id))
        increment(keyname)
        self.set_secure_cookie(keyname, '1', expires_days=1)
        self.set_header("Last-Modified", obj.last_modified)

        template_prefix = 'post'
        if obj.category == '-':
            template_prefix = 'page'

        output = self.render(
            template_prefix + '%s.html' % tmpl, {
                'title': "%s - %s" % (obj.title, getAttr('SITE_TITLE')),
                'keywords': obj.keywords,
                'description': obj.description,
                'obj': obj,
                'cobjs': obj.coms,
                'postdetail': 'postdetail',
                'cats': Categories.get_all_category_name(),
                'tags': Tags.get_hot_tag(),
                'archives': Archives.get_by_name(),
                'page': 1,
                'allpage': 10,
                'comments': Comments.get_recent_comments(),
                'links': Links.get_all(),
                'hits': get_count(keyname),
                'recent_article': Posts.get_last_post(8),
                'listtype': '',
            },
            layout='_layout.html')
        self.write(output)

        if obj.password and getAttr('BLOG_PSW_SUPPORT'):
            return output
        elif obj.password and THEME == 'default':
            return
        else:
            return output
예제 #12
0
파일: post.py 프로젝트: cash2one/cms4p
    def get(self):
        act = self.get_argument("act", '')
        post_id = self.get_argument("post_id", '')

        obj = None
        if act == 'add':
            obj = Posts
            obj.post_id = ''
            obj.category_id = ''
            obj.category_name = ''
            obj.title = ''
            obj.content = ''
            obj.tags = ''
            obj.allow_comment = 1
            obj.top = 0
            obj.password = ''
            self.echo('admin_post_edit.html', {
                'title': "添加文章",
                'method': "/admin/posts?act=add",
                'categories': Categories.get_all_kv(),
                'tags': Tags.get_all_tag_name(),
                'obj': obj,
            },
                      layout='_layout_admin.html')
            return
        elif act == 'edit':
            if post_id:
                obj = Posts.get(post_id)
                self.echo('admin_post_edit.html', {
                    'title': "编辑文章",
                    'method': "/admin/posts?act=edit",
                    'categories': Categories.get_all_kv(),
                    'tags': Tags.get_all_tag_name(),
                    'obj': obj,
                },
                          layout='_layout_admin.html')
                return
        elif act == 'del':
            if post_id:
                oldobj = Posts.get(post_id)
                Archives.remove_post_from_archive(post_id=post_id)
                Posts.delete(post_id)
                cache_key_list = [
                    '/',
                    'post:%s' % post_id,
                    'cat:%s' % quoted_string(oldobj.category)
                ]
                clear_cache_by_pathlist(cache_key_list)
                clear_cache_by_pathlist(['post:%s' % post_id])

                Posts.delete(post_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 文章列表
        page = self.get_argument("page", 1)
        posts = Posts.get_paged(page, getAttr('ADMIN_POST_NUM'))
        categories = Categories.get_all_kv()
        total = math.ceil(Posts.count_all() / int(getAttr('ADMIN_POST_NUM')))
        if page == 1:
            self.echo('admin_post_list.html', {
                'title': "文章链接",
                'objs': posts,
                'categories': categories,
                'total': total,
            },
                      layout='_layout_admin.html')
        else:
            result = {
                'list': posts,
                'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return
예제 #13
0
def get_article_tags(article_id) :
  tag_list = []
  v_list = db_session.query(TagedArticle.tag_id, TagedArticle.tag_name).filter(TagedArticle.article_id == article_id).all()
  for v in v_list :
    tag_list.append(Tags(v[0], v[1]))
  return tag_list
예제 #14
0
파일: post.py 프로젝트: dreambt/cms4p
    def get(self):
        act = self.get_argument("act", '')
        post_id = self.get_argument("post_id", '')

        obj = None
        if act == 'add':
            obj = Posts
            obj.post_id = ''
            obj.category_id = ''
            obj.category_name = ''
            obj.title = ''
            obj.content = ''
            obj.tags = ''
            obj.allow_comment = 1
            obj.top = 0
            obj.password = ''
            self.echo('admin_post_edit.html', {
            'title': "添加文章",
            'method': "/admin/posts?act=add",
            'categories': Categories.get_all_kv(),
            'tags': Tags.get_all_tag_name(),
            'obj': obj,
            }, layout='_layout_admin.html')
            return
        elif act == 'edit':
            if post_id:
                obj = Posts.get(post_id)
                self.echo('admin_post_edit.html', {
                'title': "编辑文章",
                'method': "/admin/posts?act=edit",
                'categories': Categories.get_all_kv(),
                'tags': Tags.get_all_tag_name(),
                'obj': obj,
                }, layout='_layout_admin.html')
                return
        elif act == 'del':
            if post_id:
                oldobj = Posts.get(post_id)
                Archives.remove_post_from_archive(post_id=post_id)
                Posts.delete(post_id)
                cache_key_list = ['/', 'post:%s' % post_id, 'cat:%s' % quoted_string(oldobj.category)]
                clear_cache_by_pathlist(cache_key_list)
                clear_cache_by_pathlist(['post:%s' % post_id])

                Posts.delete(post_id)
                clear_cache_by_pathlist(['/'])
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps("OK"))
            return

        # 文章列表
        page = self.get_argument("page", 1)
        posts = Posts.get_paged(page, getAttr('ADMIN_POST_NUM'))
        categories = Categories.get_all_kv()
        total = math.ceil(Posts.count_all() / int(getAttr('ADMIN_POST_NUM')))
        if page == 1:
            self.echo('admin_post_list.html', {
            'title': "文章链接",
            'objs': posts,
            'categories': categories,
            'total': total,
            }, layout='_layout_admin.html')
        else:
            result = {
            'list': posts,
            'total': total,
            }
            self.set_header("Content-Type", "application/json")
            self.write(json.dumps(result))
            return