Esempio n. 1
0
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')
Esempio n. 2
0
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')
Esempio n. 3
0
 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"))
Esempio n. 4
0
def save_base(dic,):
    LIST_SAVE = []
    global COUNT

    for d in dic:

        QUERY = News.query.filter(News.date_cont==d['date_cont']).filter(News.title==d['title']).first()

        if QUERY:
            if QUERY.date_cont and QUERY.title:

                if COUNT >= 5: break

                COUNT += 1
                print(f'{COUNT} - совпадение')
                continue

        print(d['image'])

        new = News()
        new.title=d['title']
        new.slug=d['slug']
        new.date_cont=d['date_cont']
        new.date_sort=d['date_sort']
        new.image=d['image']
        new.content=d['content']
        new.category=d['category']

        db.session.add(new)
        db.session.commit()

        dir = {
            'date_cont': d['date_cont'],
            'date_sort': d['date_sort'],
            'title': d['title'],
            'slug': d['slug'],
            'image': d['image'],
            'content': d['content'],
            'category': d['category'],
        }

        LIST_SAVE.append(dir)

        print(dir)

    return LIST_SAVE
Esempio n. 5
0
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'))