当前位置: 首页>>代码示例>>Python>>正文


Python Article.objects方法代码示例

本文整理汇总了Python中models.Article.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Article.objects方法的具体用法?Python Article.objects怎么用?Python Article.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Article的用法示例。


在下文中一共展示了Article.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sec_list

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def sec_list(request,domain=None):
    """.. :py:method::
    webanan的各下属分类的views方法
    """
    domains_list = []
    domain_list = Domain.objects().all()
    for do in domain_list:
        domains_list.append(do.name)
    title = u'{}分类文章数量'.format(domain)
    per_dict = {}
    domain_obj = Domain.objects(name=domain).first()
    if domain_obj:
        categories = Category.objects(belong_Domain=domain_obj).all()
        article_all = 0
        for cate in categories:
            article_all = article_all + Article.objects(belong_cate=cate).count()
        for cate in categories:
            article_num = Article.objects(belong_cate=cate).count()
            per_dict[cate.name] = float(u"%.2f" % (float(article_num)/article_all))
        per_dict = OrderedDict(sorted(per_dict.items(), key=lambda t: t[1]))
    else:
        raise Http404
    return render_to_response('webanan_list.html',{
                'title': title,
                'per_dict':per_dict,
                'domains':domains_list,
                })
开发者ID:seraph0017,项目名称:maxblog,代码行数:29,代码来源:views.py

示例2: all_list

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def all_list(request):
    """.. :py:method::
    webanan的主页views方法
    """
    domains_list = []
    domain_list = Domain.objects().all()
    for do in domain_list:
        domains_list.append(do.name)
    title = u'各主机文章数量'
    per_dict = {}
    domains = Domain.objects().all()
    article_all = Article.objects().count()
    for domain in domains:
        categories = Category.objects(belong_Domain=domain).all()
        domain_count = 0
        
        for cate in categories:
            article_num = Article.objects(belong_cate=cate).count()
            domain_count = domain_count + article_num
        per_dict[domain.name] = float(u"%.2f" % (float(domain_count)/article_all))
    per_dict = OrderedDict(sorted(per_dict.items(), key=lambda t: t[1]))
    return render_to_response('webanan_list.html',{
        'title': title,
        'per_dict':per_dict,
        'domains':domains_list,
        })
开发者ID:seraph0017,项目名称:maxblog,代码行数:28,代码来源:views.py

示例3: unsubscribe

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def unsubscribe(rss_id):
    '''Logic to unsubscribe a user from an rss feed, and all articles from that feed'''
    try:
        feed_to_be_removed = Feed.objects.get(id = rss_id)
        #atomically remove feed subscription from current user
        User.objects(id = current_user.id).update_one(pull__subscriptions__feed_id = feed_to_be_removed.id)
        #atomically remove articles from unsubscribed feed for current user
        Article.objects(feed_id = feed_to_be_removed.id).update(pull__readers__user_id = current_user.id)
        return jsonify(dict(status = 'Success'))
    except DoesNotExist:
        return jsonify(dict(status = 'Error', message = 'Given feed does not exist'))
开发者ID:AkarshES,项目名称:Readless,代码行数:13,代码来源:routes_logic.py

示例4: markRead

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def markRead(article_id, interest):
    '''Logic to atomically mark an article as being read by the logged in user'''
    #TODO: test it
    #atomically remove current user from readers of given article, add them to the interested/uninterested list
    if interest is 0:
        Article.objects(id = article_id).update_one(\
                pull__readers__user_id = current_user.id\
                , add_to_set__uninterested_users = current_user.id\
                )
    else:
        Article.objects(id = article_id).update_one(\
                pull__readers__user_id = current_user.id\
                , add_to_set__interested_users = current_user.id\
                )
    return jsonify(dict(status = 'Success'))
开发者ID:AkarshES,项目名称:Readless,代码行数:17,代码来源:routes_logic.py

示例5: go

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def go(request):
	user = request.user
				
	articles = None
	#articles = Article.objects(reported=True)
	articles = Article.objects(isvisible=True)
	s_articles = []
	for art in articles:
		s_articles.append(art)		
		
	ideas = None
	ideas = Idea.objects(isvisible=True)
	s_ideas = []
	for idea in ideas:		
		s_ideas.append(idea)



	

	
	template_values = {
		'articles': s_articles,
		'ideas': s_ideas,
		'user' : user,
	}

	path = os.path.join(os.path.dirname(__file__), 'templates/ideas/managebulk.html')
	return render_to_response(path, template_values)
开发者ID:jamesmwhite,项目名称:innuvate,代码行数:31,代码来源:managebulk.py

示例6: unpublish

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def unpublish(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		if post.has_key('id') and post.has_key('type'):
			try:
				iid = post['id']
				type = post['type']
				if type =='idea':
					ideas = Idea.objects(id=iid)
					if(len(ideas) >0):
						idea = ideas[0]
						idea.isvisible = False						
						idea.save()
						try:
							t = ThreadClass("Idea Unpublished", "Your idea '"+idea.title +"' has been unpublished.",[idea.email]+"'")
							t.start()					
						except Exception as inst:
							print 'exception sending email '+str(inst)
				else:
					articles = Article.objects(id=iid)
					if(len(articles) >0):
						art = articles[0]
						art.isvisible = False						
						art.save()
				return HttpResponseRedirect('/')
			except Exception as inst:
				return HttpResponseServerError('wowza! an error occurred, sorry!</br>'+str(inst))
		else:
			error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"
	return HttpResponseServerError(error_msg)
开发者ID:naughtond,项目名称:innuvate,代码行数:33,代码来源:views.py

示例7: voteart

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def voteart(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		if post.has_key('id') and post.has_key('vote'):
			try:
				iid = post['id']
				articles = Article.objects(id=iid)
				if(len(articles) >0):
					art = articles[0]
					curcount = art.votecount
					if post['vote']=='1':
						art.votecount = curcount + 1
					elif post['vote']=='3':
						art.votecount = curcount + 3
					elif post['vote']=='5':
						art.votecount = curcount + 5	
					art.voters.append(str(request.user))
					incrementStat('unique_article_votes',1)
					art.save()
				return HttpResponseRedirect('/')
			except Exception as inst:
				return HttpResponseServerError('wowza! an error occurred, sorry!</br>'+str(inst))
		else:
			error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"
	return HttpResponseServerError(error_msg)
开发者ID:naughtond,项目名称:innuvate,代码行数:28,代码来源:views.py

示例8: approve

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def approve(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		if post.has_key('id') and post.has_key('type'):
			try:
				iid = post['id']
				type = post['type']
				if type =='idea':
					ideas = Idea.objects(id=iid)
					if(len(ideas) >0):
						idea = ideas[0]
						idea.reported = False
						idea.save()
				else:
					articles = Article.objects(id=iid)
					if(len(articles) >0):
						art = articles[0]
						art.reported = False						
						art.save()
				return HttpResponseRedirect('/')
			except Exception as inst:
				return HttpResponseServerError('wowza! an error occurred, sorry!</br>'+str(inst))
		else:
			error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"
	return HttpResponseServerError(error_msg)
开发者ID:naughtond,项目名称:innuvate,代码行数:28,代码来源:views.py

示例9: subscribe

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def subscribe(rss_url):
    '''Logic to add a given rss feed to the db, if required, and subscribe the current user to this feed'''
    try:
        feed = Feed.get_or_construct(rss_url)
    except NotAFeed:
        return jsonify(dict(status = 'Error', message='The given url is not an rss feed url'))
    new_subscription = Subscription(feed_id = feed.id)
    #atomically add new feed subscription to current user
    number_of_items_affected = User.objects(id = current_user.id).update_one(add_to_set__subscriptions = new_subscription)
    new_reader = Reader(user_id = current_user.id)
    #atomically add current user to readers of all articles in subscribed feed
    Article.objects(feed_id = feed.id).update(add_to_set__readers = new_reader)
    if number_of_items_affected is 1:
        return jsonify(dict(status = 'Success'))
    else:
        return jsonify(dict(\
                status = 'Error'\
                , message = 'Unable to subscribe'\
                ))
开发者ID:AkarshES,项目名称:Readless,代码行数:21,代码来源:routes_logic.py

示例10: markUnread

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def markUnread(article_id):
    '''Logic to atomically mark an article as being unread by the logged in user'''
    #TODO: test it
    new_reader = Reader(user_id = current_user.id)
    #atomically add current user to readers of given article
    number_of_items_affected = Article.objects(id = article_id).update_one(add_to_set__readers = new_reader)
    if number_of_items_affected is 1:
        return jsonify(dict(status = 'Success'))
    else:
        return jsonify(dict(\
                status = 'Error'\
                , message = 'No articles matched the given id'\
                ))
开发者ID:AkarshES,项目名称:Readless,代码行数:15,代码来源:routes_logic.py

示例11: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
    def get(self, request, *args, **kwargs):
        year = int(kwargs['id'])
        d = request.GET.dict()
        page_num = int(d.get('page_num', 1))
        if page_num < 1:
            page_num = 1 
        

        try:
            item_num = 10
           
            page_start = (page_num -1 )* item_num
            page_end = page_num * item_num 

            start = datetime(year, 1, 1)
            end = datetime(year, 12, 31)
            
            total_num = Article.objects(Q(status=1) & Q(create_time__gte=start) & Q(create_time__lte=end)).count()  

            total_page = math.ceil(total_num*1.0/item_num)
            last_page = page_num-1
            next_page = page_num+1


            a_list = list(Article.objects(Q(status=1) & Q(create_time__gte=start)& Q(create_time__lte=end)).order_by('-create_time'))[page_start:page_end]

            for i in a_list:
                i.content = markdown(i.content)
            para = {'article_list': a_list}
            para.update({"page_num": page_num,
                     "last_page": last_page,
                     "next_page": next_page,
                     'total_page': total_page,})

        except DoesNotExist:
            para = {'article_list': None}

        t = TemplateResponse(request, 'list.html', para)
        return t
开发者ID:waynetian,项目名称:guqintai,代码行数:41,代码来源:views.py

示例12: reportarticle

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def reportarticle(request):
	tag =  request.path_info
	tag = tag.split('/')[2]
	articles = Article.objects(id=tag)
	if len(articles)>0:
		art = articles[0]
		art.reported = True
		incrementStat('articlesreported',1)
		person = getPerson(request)
		if person:
			person.timesReport = person.timesReport +1
			rating = Score.objects(type='report')[0].value
			person.currentRating = person.currentRating + rating
			person.save()
		art.save()
	return HttpResponseRedirect('/')
开发者ID:naughtond,项目名称:innuvate,代码行数:18,代码来源:views.py

示例13: getUnreadArticles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def getUnreadArticles(feedId):
    '''Logic to get unread articles for a particular subscribed feed for the current user'''
    items = []
    for article in Article.objects(feed_id = feedId, readers__user_id = current_user.id):
        for reader in article.readers:
            if reader.user_id == current_user.id: 
                user_score = reader.score
        item = dict(\
                article_id = str( article.id )\
                , title = article.features.title\
                , content_snippet = article.features.content_snippet\
                , source_link = article.source_url\
                , time_stamp = time.mktime(article.time_stamp.timetuple())\
                , score = user_score\
                )
        items.append(item)
    return jsonify(dict(\
            articles = items\
            ))
开发者ID:AkarshES,项目名称:Readless,代码行数:21,代码来源:routes_logic.py

示例14: getUserInfo

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def getUserInfo():
    '''Logic to get all required information about a user '''
    items = []
    for subscription in current_user.subscriptions:
        feed = Feed.objects.get(id = subscription.feed_id)
        UnreadArticleCount = Article.objects(feed_id = subscription.feed_id, readers__user_id = current_user.id).count()
        item = dict(\
                    #feed_id is encoded as string to allow it to be sent as JSON
                    feed_id = str( subscription.feed_id )\
                    , feed_name = feed.name\
                    , site_url = feed.site_url\
                    , UnreadCount = UnreadArticleCount\
                    )
        items.append(item)
    return jsonify(dict(\
            name = current_user.name\
            , email = current_user.email\
            , subscriptions = items\
            ))
开发者ID:AkarshES,项目名称:Readless,代码行数:21,代码来源:routes_logic.py

示例15: go

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import objects [as 别名]
def go(request):
	user = request.user
		
	articles = None
	articles = Article.objects(isvisible=True).order_by('-votecount')
	s_articles = []
	for art in articles:
		if str(request.user) in art.voters:
			art.hasvoted = True
		s_articles.append(art)

	
	template_values = {
		'articles': s_articles,
		'user' : user,
	}

	path = os.path.join(os.path.dirname(__file__), 'templates/ideas/articles.html')
	return render_to_response(path, template_values)
开发者ID:jamesmwhite,项目名称:innuvate,代码行数:21,代码来源:articles.py


注:本文中的models.Article.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。