本文整理汇总了Python中models.News类的典型用法代码示例。如果您正苦于以下问题:Python News类的具体用法?Python News怎么用?Python News使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了News类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_news
def add_news(request):
if request.user.is_authenticated()==False:
return HttpResponse("<h2>Для виконання операції, авторизуйтесь</h2>")
a = News()
if request.method == 'POST':
form = NewsForm(request.POST, instance=a)
if form.is_valid():
title = form.cleaned_data['title']
text = form.cleaned_data['text']
# date = form.cleaned_data['date']
link = form.cleaned_data['link']
author = form.cleaned_data['author']
category = form.cleaned_data['category']
comm = form.cleaned_data['comments']
# user = form.cleaned_data['user']
n = News(title=title, text=text, date=datetime.datetime.now(), link=link, author=author, category=category, user=request.user)
#n.comments.add(comm)
n.save()
return HttpResponseRedirect('/')
else:
form = NewsForm(instance=a, initial={'author': request.user })
photo1 = Photo.objects.random()
photo2 = Photo.objects.random()
vars = {'weblink': 'news_add.html', 'sel_menu': 'main', 'photo1': photo1, 'photo2': photo2, 'entry': get_funn(), 'form': form}
calendar = embeded_calendar()
vars.update(calendar)
return render_to_response('index.html', vars, context_instance=RequestContext(request, processors=[custom_proc]))
示例2: addNewsArticle
def addNewsArticle(companyModel,newsSourceModel,url):
tree = html.fromstring(requests.get(url).text)
# Need the article title
title = tree.xpath('//h1/text()')[0]
# Need the text of the article
textElements = tree.xpath("//*[@id='articleText']//*/text()")
text = ""
for t in textElements:
text += t
# Need the date field
dateText = tree.xpath("//div[@id='articleInfo']//span[@class='timestamp']/text()")[0]
date = datetime.datetime.strptime(dateText[:-4], "%a %b %d, %Y %I:%M%p").date()
News.create(
company=companyModel,
newsSource=newsSourceModel,
title=title,
text=text,
url=url,
date = date
)
print "Added: "+title
示例3: create
def create(request, template="news/create.html"):
#if
def get_slug(text, numb=0):
"Create unique slug"
if numb:
text += "_%d" % numb
s = slugify(text)
try:
News.objects.get(slug=s)
return get_slug(text, numb + 1)
except News.DoesNotExist:
pass
return s
u = request.user
if request.POST:
n = News(author=u, show=False, slug=get_slug(request.POST['title']))
f = NewsForm(request.POST, instance=n)
if f.is_valid():
n = f.save()
return HttpResponseRedirect(n.get_absolute_url() + "show/")
else:
f = NewsForm()
return render_to_response(template, {
"form": f,
}, context_instance=RequestContext(request))
示例4: getNewsList
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)
示例5: get_news_search_queryset
def get_news_search_queryset(city, q):
try:
sphinx.SetFilter('city', [int(city)], exclude=0)
search_result = sphinx.Query(q, 'article', '')
sphinx.ResetFilters()
items = []
for match in search_result['matches']:
news = News()
news.id = match['id']
for key, value in match['attrs'].iteritems():
setattr(news, key, value)
items.append(news)
except:
error = sphinx.GetLastError()
raise Exception('search', error)
#queryset = News.objects.filter(is_displayed=True, city=city, title__icontains=q).order_by('-date_added')
if items and len(items) > 0:
photos = NewsPhoto.objects.filter(display_order=0, subnews_id__isnull=True)
photos_dict = {}
for p in photos:
photos_dict[p.news_id] = p
for item in items:
item.photo = photos_dict[item.id] if item.id in photos_dict.keys() else None
return items
else:
return []
示例6: createDB
def createDB():
print "Creating the initial db"
Company.create_table()
NewsSource.create_table()
News.create_table()
Price.create_table()
OpinionAPI.create_table()
OpinionAPIResponse.create_table()
示例7: project
def project(news_id):
news = News.select().where(
News.category == 'PROJECT'
).order_by(News.time.desc()).limit(10)
project = News.select().where(
News.id == news_id
).get()
return render_template('articles/project.html', news=project, project_list = news)
示例8: events
def events(news_id):
news = News.select().where(
News.id == news_id
).get()
#news_list
news_list = News.select().where(
News.category == 'ACTIVITY'
).order_by(News.time.desc()).limit(10)
#print news.title
return render_template('articles/events.html',
news = news, events_list = news_list)
示例9: notification
def notification():
news = News.select().where(
News.category == 'NEWS'
).order_by(News.time.desc()).limit(6)
events = News.select().where(
News.category == 'ACTIVITY'
).order_by(News.time.desc()).limit(6)
#展示最新的6个新闻摘要news_list和活动摘要events_list
return render_template('notification.html',
news_list = news, events_list = events)
示例10: news_post
def news_post():
form = NewsForm()
if form.validate_on_submit():
news = News(view = 0, title = form.title.data,url = form.url.data,hot = False)
try:
news.put()
flash(u'저장 성공', 'success')
return redirect(url_for('new_list'))
except CapabilityDisabledError:
flash(u'App Engine Datastore is currently in read-only mode.', 'failure')
return redirect(url_for('new_list'))
return render_template('news_post.html', form=form,title= request.args.get('title'), url= request.args.get('url'))
示例11: news
def news(news_id):
news = News.select().where(
News.id == news_id
).get()
#news_list
news_list = News.select().where(
News.category == 'NEWS'
).order_by(News.time.desc()).limit(10)
#最新的10个新闻news_list 及指定的新闻文章news
return render_template('articles/news.html',
news = news, news_list = news_list)
示例12: news_post
def news_post():
form = NewsForm()
if form.validate_on_submit():
news = News(view = 0, title = form.title.data,url = form.url.data,hot = False)
try:
news.put()
search.Index(name=_INDEX_NAME).add(create_doc(news.key.id(),news.title,news.url,news.post_time))
flash(u'저장 성공', 'success')
return redirect(url_for('new_list'))
except CapabilityDisabledError:
flash(u'App Engine Datastore is currently in read-only mode.', 'failure')
return redirect(url_for('new_list'))
return render_template('news_post.html', form=form,title= request.args.get('title'), url= request.args.get('url'),counter=counter.load_and_get_count("view"),acc=ACC)
示例13: post
def post(self):
news = News()
news.title = self.request.get("title")
news.slug_title = self.request.get("slug_title")
news.content = self.request.get("content")
news.when_published = datetime.utcnow()
news.put()
self.response.out.write(news.to_json("title", "is_deleted", "is_active", "is_starred"))
示例14: index
def index():
notifications = News.select().where(
News.category == 'NOTIFICATION'
).order_by(News.time.desc()).limit(5)
news = News.select().where(
News.category == 'NEWS'
).order_by(News.time.desc()).limit(6)
pics = News.select().where(
News.category == 'PICTURE'
)
pic_num = pics.count()
#通知与公告 notification 热门新闻 news
return render_template('index.html',
notification_list = notifications,
news_list = news, pics=pics, pic_num=pic_num)
示例15: news_list
def news_list():
#news_list
news_list = News.select().where(
News.category == 'NEWS'
).order_by(News.time.desc()).limit(20)
return render_template('articles/n_list.html', news_list = news_list)