示例#1
0
文件: article.py 项目: wyx0914/yxBlog
def get_article_list(index, type=''):
    try:
        index = int(index)
    except ValueError:
        index = 1
    type = str(type)

    query = {}
    if type != '' and type != 'all':
        tt = article_dao.get_article_type_by_name(str(type))
        if tt:
            query = {'type': str(tt['_id'])}
        else:
            return [], Page()

    item_limit = constants.item_limit * constants.item_limit_rate
    total_count = article_dao.get_article_count(query)
    page_count = int(math.ceil(total_count * 1.0 / item_limit))

    if index > page_count or index < 1:
        offset = 0
        index = 1
    else:
        offset = (index - 1) * item_limit

    page = Page()
    page.index = index
    page.count = constants.page_count if page_count > constants.page_count else page_count

    if page.index <= page.count / 2:
        page.start = 1
    else:
        page.start = page.index - int(page.count / 2)
        if page.start > page_count - page.count:
            page.start = page_count - page.count + 1

    result = list(article_dao.get_article_list(offset, item_limit, query))

    article_list = []
    for art in result:
        model = Article()
        model._id = art['_id']
        model.title = art['title']
        model.tag = art['tag']
        model.time = art['time']
        model.content = art['content']
        model.description = art['description']
        model.visit_count = art['visit_count']
        tt = article_dao.get_article_type_by_id(art['type'])
        if tt:
            model.type = tt['_id']
            model.type_name = tt['type']

        article_list.append(model)
    return article_list, page
示例#2
0
文件: admin.py 项目: wyx0914/yxBlog
    def post(self, title=''):
        art = Article()
        art._id = self.get_argument('_id', '')
        art.title = self.get_argument('title', '')
        art.type = self.get_argument('type', '')
        art.tag = self.get_argument('tag', '')
        art.description = self.get_argument('description', '')
        art.content = self.get_argument('content', '')

        article_service.add_or_update_article(art)

        self.redirect('/system/article/list/1')
示例#3
0
文件: article.py 项目: wyx0914/yxBlog
def get_article(title):
    model = Article()
    if title != '':
        art = article_dao.get_article_by_title(str(title))
        if art:
            model._id = art['_id']
            model.title = art['title']
            model.tag = art['tag']
            model.time = art['time']
            model.content = art['content']
            model.description = art['description']
            model.visit_count = art['visit_count']
            tt = article_dao.get_article_type_by_id(art['type'])
            if tt:
                model.type = tt['_id']
                model.type_name = tt['type']

    return model
示例#4
0
文件: article.py 项目: wyx0914/yxBlog
def get_latest_article():
    result = list(article_dao.get_latest_article(constants.item_limit))
    latest_articles = []
    for art in result:
        model = Article()
        model._id = art['_id']
        model.title = art['title']
        model.tag = art['tag']
        model.time = art['time']
        model.content = art['content']
        model.description = art['description']
        model.visit_count = art['visit_count']
        tt = article_dao.get_article_type_by_id(art['type'])
        if tt:
            model.type = tt['_id']
            model.type_name = tt['type']

        latest_articles.append(model)

    return latest_articles
示例#5
0
#列表目录到数组
root_dir = r'D:\python\sharejs\vectors\d1'

dirs = os.listdir(root_dir)
print(dirs)

i=0;
#dirs =['blue', 'cantya', 'creative-media', 'green', 'happy-print-shop', 'indeziner-form-templates', 'one-page-cv', 'product-landing-page', 'sindromk', 'violet', 'write-to-santa']
for dir in dirs:
    i+=1
    if i<=100000:
        article = Article()
        article.title = u'矢量素材'
        article.short_description=u'矢量图格式为EPS,含JPG预览图,关键词:'
        article.compatibility = u''
        #article.demo_url = '/vectors/d1/%s/index.html'%dir
        article.root_category_id = 700
        article.category_id = 751
        article.full_download_url = '/vectors/d1/%s/%s.zip'%(dir,dir)
        article.pic = '/vectors/d1/%s/demo.jpg'%dir
        img_description = ''
        for file in os.listdir(root_dir + '\\' + dir):
            if file.endswith('.jpg') and file != 'demo.jpg':
                img_description += '[img]%s[/img]\r\n'%('/vectors/d1/'+dir+'/'+file)
        article.description = img_description
        #article.source = ''
        article_facade = factory.create_article_facade()
        article_facade.post_data(article)
        print(dir + '  finished')
示例#6
0
def article_edit(request):
    '文章编辑'
    article_facade = facade.factory.create_article_facade()
    topic_facade = facade.factory.create_topic_facade()
    category_facade = facade.factory.create_category_facade()
    tag_facade = facade.factory.create_tag_facade()

    #如果是提交信息
    if request.method =="POST":
        article = Article()
        id = func.get_int_param_from_post(request,'id')
        article.id=id
        article.title = func.get_str_param_from_post(request,'title')
        article.root_category_id = func.get_int_param_from_post(request,'root_category')
        article.category_id = func.get_int_param_from_post(request,'category1')
        article.category_id2 = func.get_int_param_from_post(request,'category2')
        article.category_id3 = func.get_int_param_from_post(request,'category3')
        article.author = func.get_str_param_from_post(request,'author')
        article.source = func.get_str_param_from_post(request,'source')
        article.short_description = func.get_str_param_from_post(request,'short_description')
        article.description = func.get_str_param_from_post(request,'description')
        article.demo_code = func.get_str_param_from_post(request,'demo_code')
        article.demo_url = func.get_str_param_from_post(request,'demo_url')
        article.dev_view_code = func.get_str_param_from_post(request,'dev_view_code')
        article.full_download_url = func.get_str_param_from_post(request,'full_download_url')
        article.head_code = func.get_str_param_from_post(request,'head_code')
        article.body_code = func.get_str_param_from_post(request,'body_code')
        article.compatibility = func.get_str_param_from_post(request,'compatibility')
        article.pic = func.get_str_param_from_post(request,'pic')
        article.small_pic = func.get_str_param_from_post(request,'small_pic')
        article.recommend = func.get_str_param_from_post(request,'recommend')=='on'
        article.topic_id = func.get_str_param_from_post(request,'topic_id')
        article.state = 0
        article.isrtdate = func.format_date_time(func.str_to_datetime(func.get_str_param_from_post(request,'isrtdate')))
        article.last_hit_date=func.format_date_time(func.str_to_datetime(func.get_str_param_from_post(request,'last_hit_date')))
        article.hits = func.get_int_param_from_post(request,'hits')

        id = article_facade.post_data(article)
        #添加Tags
        tag_facade.insert_tags(id,func.get_str_param_from_post(request,'tags'))

        refer_url = func.get_str_param_from_post(request,'refer_url')
        if not refer_url:
            refer_url = "article_list"

        return HttpResponseRedirect(refer_url)
        

    id = func.get_int_param_from_get(request,'id')
    output = {}

    if id>0:
        article = article_facade.get_data(id)
        article.tags = tag_facade.get_tags_str(id)
        output['article'] = article

    topic_list = topic_facade.get_all_topic()
    root_category_list = category_facade.get_child_category_list(0)
    output['topic_list'] = topic_list
    output['root_category_list'] = root_category_list
    output['refer_url'] = func.get_referer(request,'article_list')
    

    return render_to_response('admin/article_edit.html',output)