• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.News类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了News类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]))
开发者ID:rivelo,项目名称:portal,代码行数:28,代码来源:views.py


示例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
开发者ID:Aaronmyster,项目名称:newtsocks,代码行数:25,代码来源:reuters.py


示例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))
开发者ID:mughrabi,项目名称:arch-pl,代码行数:25,代码来源:views.py


示例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)
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:27,代码来源:views.py


示例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 []
开发者ID:DimitriyNikolaev,项目名称:fiesta,代码行数:29,代码来源:views.py


示例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()
开发者ID:Aaronmyster,项目名称:newtsocks,代码行数:8,代码来源:createDatabase.py


示例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)
开发者ID:sparkmorry,项目名称:zaec,代码行数:9,代码来源:views.py


示例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)
开发者ID:sparkmorry,项目名称:zaec,代码行数:12,代码来源:views.py


示例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)
开发者ID:sparkmorry,项目名称:zaec,代码行数:12,代码来源:views.py


示例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'))
开发者ID:slowcall,项目名称:lo9,代码行数:12,代码来源:views.py


示例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)
开发者ID:sparkmorry,项目名称:zaec,代码行数:13,代码来源:views.py


示例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)
开发者ID:happydeveloper,项目名称:lo9,代码行数:13,代码来源:views.py


示例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"))
开发者ID:aswadrangnekar,项目名称:tiss-secure,代码行数:8,代码来源:api.py


示例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)
开发者ID:sparkmorry,项目名称:zaec,代码行数:15,代码来源:views.py


示例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)
开发者ID:sparkmorry,项目名称:zaec,代码行数:7,代码来源:views.py


示例16: admin_news_uploads

def admin_news_uploads():
	form = UploadNewsForm()
	if form.validate_on_submit():
		news = News()
		db.session.add(news)
		db.session.commit()
		news.title = form.title.data
		news.content = form.content.data
		news.author = current_user.username

		file_name = secure_filename(form.image.data.filename)
		extension = file_name.split('.')[-1]
		file_name = '.'.join([str(news.id), extension])
		path = upload_s3(file_name, form.image.data, app.config['S3_NEWS_IMAGE_DIR'])
		news.image = path
		db.session.commit()
	return redirect(url_for('news_and_resources'))
开发者ID:berc-web,项目名称:berc_web,代码行数:17,代码来源:__init__.py


示例17: get

    def get(self, **kwargs):
        context = {
            'all_news': News.all().order('-date'),
            }

        context = request_context(context)

        return render_response('news.html', **context)
开发者ID:humitos,项目名称:bus-stopped,代码行数:8,代码来源:handlers.py


示例18: get

 def get(self):
     if users.get_current_user():
         logout_url = users.create_logout_url('/')
     else:
         logout_url = None
     news = News.get_latest(10)
     response = render_template('index.html', logout_url=logout_url, news=news)
     self.response.out.write(response)
开发者ID:yesudeep,项目名称:tiss-secure,代码行数:8,代码来源:handlers.py


示例19: add_news

def add_news(req):
    check = News.objects.filter(link=req.POST['link'])
    mnews = ""
    if check.count() != 0:
        # record already exist
        if check[0].time > int(req.POST['time']):
            return HttpResponse(json.dumps({'status':'OK'},indent=4),content_type='application/json')
        mnews = check[0]
    else:
        mnews = News()
    mnews.title = req.POST['title']
    mnews.content = req.POST['content']
    mnews.link = req.POST['link']
    mnews.time = int(req.POST['time'])
    mnews.save()
    keywords = json.loads(req.POST['keywords'])
    refers = json.loads(req.POST['refers'])
    for word in keywords:
        mkeywords = Keywords()
        mkeywords.news = mnews
        mkeywords.words = word
        mkeywords.save()
    for refer in refers:
        mrefer = Refers()
        mrefer.news = mnews
        mrefer.refer = refer
        mrefer.save()
    return HttpResponse(json.dumps({'status':'OK'}),content_type='application/json')
开发者ID:randoms,项目名称:prophet,代码行数:28,代码来源:views.py


示例20: getNewsDetail

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))
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:18,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Node类代码示例发布时间:2022-05-27
下一篇:
Python models.Movie类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap