本文整理汇总了Python中models.News.objects方法的典型用法代码示例。如果您正苦于以下问题:Python News.objects方法的具体用法?Python News.objects怎么用?Python News.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.News
的用法示例。
在下文中一共展示了News.objects方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getNewsList
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getNewsList(request):
# depend on the friends depart
num = request.GET['num']
allFriends = Account.objects(pk__in=request.user.friends).all()
number = News.objects(author__in=allFriends).count()
if int(num)*15>number:
result=[]
return HttpResponse(dumps(result))
result = News.objects(author__in=allFriends)[int(num)*15:int(num)*15 + 15].order_by("-time").as_pymongo()
result = list(result)
for news in result:
del(news['_types'])
del(news['_cls'])
news['picture'] = endpoint + "news/getPicture?id=" + str(news['_id'])
news['voice'] = endpoint + "news/getVoice?id=" + str(news['_id'])
uid = news['author']
user = News.objects(author=uid).first().author
gid = news['good']
good = News.objects(good=gid).first().good
news['good'] = endpoint + "goods/getGoods?id=" + str(good.pk)
news['author'] = {"portrait": endpoint + "users/getPortrait?id=" + str(user.pk), "name": user.username}
news['comments'] = endpoint + "news/getComments?id=" + str(news['_id'])
# news['_id'] = endpoint + "news/getNewsDetail?id=" + str(news['_id'])
del(news['_id'])
news['time']=str(news['time'])
result = dumps(result)
return HttpResponse(result)
示例2: getNewsDetail
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getNewsDetail(request):
nid=request.GET['id']
news=News.objects(pk=nid).first().to_mongo()
del(news['_types'])
del(news['_cls'])
news['picture'] = endpoint + "news/getPicture?id=" + str(news['_id'])
news['voice'] = endpoint + "news/getVoice?id=" + str(news['_id'])
uid = news['author']
user = News.objects(author=uid).first().author
gid = news['good']
good = News.objects(good=gid).first().good
news['good'] = endpoint + "goods/getGoods?id=" + str(good.pk)
news['author'] = {"portrait": endpoint + "users/getPortrait?id=" + str(user.pk), "name": user.username}
news['comments'] = endpoint + "news/getComments?id=" + str(news['_id'])
# news['_id'] = endpoint + "news/getNewsDetail?id=" + str(news['_id'])
del(news['_id'])
news['time']=str(news['time'])
return HttpResponse(dumps(news))
示例3: getCommentVoice
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getCommentVoice(request):
vid=request.GET['vid']
a=News.objects(comments__voice=ObjectId(str(vid))).first()
comments=a.comments
voice=None
for comment in comments:
mongo=comment.to_mongo()
if str(mongo['voice'])==str(vid):
voice=comment.voice
return HttpResponse(voice.read(),mimetype="audio/mpeg")
示例4: post
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def post(self, request):
try:
api_news_ids = request.data
top_news_id_list = []
for news_id in api_news_ids:
row = News.objects(news_id=news_id).first()
if not row:
top_news_id_list.append(news_id)
return Response({"data": top_news_id_list, "statusCode" : 200})
except Exception, e:
log.debug(str(e) + " IN TopNewsIdApi ")
return Response({"data": "failure", "statusCode" : 404})
示例5: getComments
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getComments(request):
nid=request.GET['id']
news=News.objects(pk=nid).as_pymongo()
comments=list(news)[0]["comments"]
for comment in comments:
del(comment["_types"])
del(comment["_cls"])
uid=comment["author"]
user = Account.objects(pk=uid.id).first()
if comment["voice"]!=None:
comment["voice"]=endpoint + "news/getCommentVoice?vid="+str(comment["voice"])
else:
comment["voice"]=""
comment["username"]=user.username
comment["portrait"]=endpoint+"users/getPortrait?id="+str(user.pk)
del(comment["author"])
return HttpResponse(dumps(comments))
示例6: addComment
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def addComment(request):
result=urlparse.urlparse(request.POST['comment_url'])
params=urlparse.parse_qs(result.query,True)
nid=params['id']
comment = Comment()
comment.content =""
if request.POST.has_key("content"):
content = request.POST['content']
comment.content = content
if request.FILES.has_key("voice"):
voice =open(request.FILES['voice'].temporary_file_path(), "rb") # change to data from request
comment.voice = voice
comment.author = request.user
news = News.objects(pk=nid[0]).first()
news.comments = news.comments + [comment]
news.save()
return HttpResponse("success")
示例7: post
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def post(self, request):
try:
top_news_ids = request.data
top_news_ids = json.dumps(top_news_ids)
top_news_ids = ast.literal_eval(top_news_ids)
top_news_ids = top_news_ids.keys()[0]
top_news_ids = ast.literal_eval(top_news_ids)
top_new_news_id_list = []
for news_id in top_news_ids:
news_id = long(news_id)
a = News.objects(news_id=news_id).first()
# News.objects(news_id=news_id).delete()
if not a:
top_new_news_id_list.append(news_id)
return Response({"new_news_id": top_new_news_id_list})
except Exception, e:
log.debug(str(e) + " IN TopNewsIdApi ")
return Response({"status": "failure"})
示例8: connect
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
import time
from mongoengine import connect
connect('newsclient')
from models import News
#for news in News.objects(facebook_count__gte=800).limit(1000):
for news in News.objects(hatebu_count__exists=0).limit(1000):
if "rssad" in news.url:
continue
if news.twitter_count is None:
news.get_twitter_count()
if news.facebook_count is None:
news.get_facebook_count()
if news.hatebu_count is None:
news.get_hatebu_count()
if news.hatebu_count > 100 or\
news.facebook_count > 800 or\
news.twitter_count > 1200:
print "tw", news.twitter_count
print "fb", news.facebook_count
print "hatebu", news.hatebu_count
print news.og_title
print news.url
news.save()
time.sleep(1)
示例9: getVoice
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getVoice(request):
nid = request.GET['id']
result = News.objects(pk=nid).first()
voice = result.voice.read()
return HttpResponse(voice, mimetype="audio/mpeg")
示例10: getPicture
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getPicture(request):
nid = request.GET['id']
result = News.objects(pk=nid).first()
image = result.picture.read()
return HttpResponse(image, mimetype="image/jpeg")
示例11: deleteNews
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def deleteNews(request):
News.objects(author=request.user).delete()
return HttpResponse("delete all")
示例12: connect
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
import time
from mongoengine import connect
from mongoengine import Q
from models import News
connect('newsclient')
queryset = News.objects(\
Q(generated_summary__exists=0) &\
Q(url__not__contains="rssad") )# &\
#Q(url__not__contains="nhk") ).limit(50)
for news in queryset:
print ">>>>>>>>>>-------------------"
print news.url
print news.og_title
news.extract_content_()
news.generate_summary()
print news.generated_summary
news.save()
#time.sleep(5)
print "-------------------<<<<<<<<<<\n"