Esempio n. 1
0
def article_Manager():
    date = request.form["date"]
    name = request.form["name"].strip()
    if name == '':
        articles = Article.select().where(Article.time % (date + '%'))
        return render_template("admin_article_manager.html", articles=articles)
    if name != '':
        articles = Article.select().where((Article.time % (date + '%'))
                                          & (Article.detail_source == name))
        return render_template("admin_article_manager.html", articles=articles)
Esempio n. 2
0
def deleteArticle(id=None):
    if id is None:
        resultDict = returnNoneMsg("please article id!")
        return jsonify(resultDict)
    article_id = id
    article = Article()
    try:
        article.get(id=article_id).delete()
        resultDict = returnMsg("delete success")
    except Exception, e:
        resultDict = returnNoneMsg("id not exists,delete error")
Esempio n. 3
0
def updateArticle():
    if not request.json:
        resultDict = returnNoneMsg("failed!")
        return jsonify(resultDict)
    jsonData = request.get_data()
    dataDict = json.loads(jsonData)
    id = dataDict.get('id', None)
    dataDict.pop("id")
    article = Article()
    try:
        article.get(id=id).update(**dataDict)
        resultDict = returnMsg("update success")
    except Exception, e:
        resultDict = returnNoneMsg("id not exists,update error")
Esempio n. 4
0
    def add_record(self,
                   search_terms: str,
                   url: str,
                   content: str,
                   lang: str = '') -> List[Article]:
        """
        Adds a Document to the db
        :param lang:
        :param search_terms:
        :param url:
        :param content:
        :return:
        """

        url_hash = self.get_hash(url)
        try:
            # check if article is already archived
            if self.coll.find({"url_hash": url_hash}).count() > 0:
                print("article {} already present in db, skipping".format(url))
            elif len(content) == 0:
                print("no content found on {}, skipping".format(url))
            else:
                new_record = Article(search_terms,
                                     url,
                                     content,
                                     url_hash=url_hash,
                                     lang=lang)
                print('adding article {}, length {}'.format(url, len(content)))
                self.coll.insert_one(new_record.json_value)
        except ServerSelectionTimeoutError as sst:
            print("pymongo couldn't connect to mongodb server")
Esempio n. 5
0
def articleDetail():
    id = request.args.get("id")
    art = Article.get(Article.id == id)
    comments = Comment.select().where(Comment.articleId == id)
    return render_template("article_detail.html",
                           article=art,
                           comments=comments)
Esempio n. 6
0
def articleUpdateDo():
    title = request.form["title"]
    content = request.form["content"]

    id = request.args.get("id")
    art = Article.get(Article.id == id)
    art.title = title
    art.content = content
    art.save()
    return render_template("article_update_success.html")
Esempio n. 7
0
 def build_doc(self, data):
     return Article(search_term=data['search_term'],
                    current_search_term=data['current_search_term'],
                    article_url=data['article_url'],
                    article_content=data['article_content'],
                    lang=data['lang'],
                    timestamp=data['timestamp'],
                    weight=data['weight'],
                    blob=data['blob'],
                    url_hash=data['url_hash'],
                    wordcount=data['wordcount'],
                    tokenified=data['tokenified'],
                    mongo_id=data['_id'])
Esempio n. 8
0
def articleUploadDo():
    id = session.get("id")
    title = request.form["title"]
    content = request.form["content"]
    img = re.compile(pattn).search(content)
    if img != None:
        img = img.group(1)
    if img != None:
        img_url = img
    else:
        img_url = '/static/upload/new.jpg'
    tag = classify(content)
    detail_source = session.get('username')
    time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    art = Article(title=title,
                  content=content,
                  detail_source=detail_source,
                  img_url=img_url,
                  tag=tag,
                  time=time)
    art.save()
    return render_template("article_upload_success.html")
Esempio n. 9
0
def searchArticle(k=None):
    if not request.json:
        resultDict = returnNoneMsg("failed!")
        return jsonify(resultDict)
    jsonData = request.get_data()
    dataDict = json.loads(jsonData)

    title = dataDict.get('title', None)
    author = dataDict.get('author', None)
    article = Article()
    a = article.search()
    if title:
        a = a.filter('term', published=True).query('match', title=title)

    else:
        a = a.filter('term', published=True).query('match', author=author)
    results = a.execute()
    if results:
        infoList = []
        for messageTable in results:

            dictInfo = {
                "id": messageTable._id,
                "title": messageTable.title,
                "author": messageTable.author,
                "content": messageTable.content,
                "add_ip": messageTable.add_ip,
                "category": messageTable.category,
                "point_num": messageTable.point_num,
                "commont_num": messageTable.commont_num,
                "fav_num": messageTable.fav_num,
            }
            infoList.append(dictInfo)
        resultDict = returnMsg(infoList)
    else:
        resultDict = returnNoneMsg("the message not exit!")
    return jsonify(resultDict)
Esempio n. 10
0
def articleDelete():
    id = request.args.get("id")
    art = Article.get(Article.id == id)
    art.delete_instance()
    return redirect("/admin_article_manager")
Esempio n. 11
0
def articleManager():
    articles = Article.select()
    return render_template("admin_article_manager.html", articles=articles)
Esempio n. 12
0
def articleManager():
    username = session.get("username")
    arts = Article.select().where(Article.detail_source == username)
    return render_template("reporter_article_manager.html", atricles=arts)
Esempio n. 13
0
def articleUpdate():
    id = request.args.get("id")
    art = Article.get(Article.id == id)
    return render_template("reporter_article_update.html", article=art)
Esempio n. 14
0
def indexRoute():
    articles = Article.select().order_by(fn.Rand()).limit(20)
    return render_template("index.html", articles=articles)
Esempio n. 15
0
def articleDelete():
    id = request.args.get("id")
    art = Article.get(Article.id == id)
    art.delete_instance()
    return render_template("article_delete_success.html")
Esempio n. 16
0
def select_article(tag):
    articles = Article.select().where(Article.tag.contains(tag)).order_by(
        Article.time.desc())
    return articles
Esempio n. 17
0
 def add_article():
     te = Article(title='xixi', content='ininininininin')
     db.session.add(te)
     db.session.commit()
     return "add article"
Esempio n. 18
0
def article_Manager():
    username = session.get("username")
    date = request.form["date"]
    arts = Article.select().where((Article.detail_source == username)
                                  & (Article.time % (date + '%')))
    return render_template("reporter_article_manager.html", atricles=arts)
Esempio n. 19
0
def addArticle():
    if not request.json:
        resultDict = returnNoneMsg("failed!")
        return jsonify(resultDict)
    jsonData = request.get_data()
    dataDict = json.loads(jsonData)
    article = Article()

    article.title = dataDict.get('title', None)
    article.author = dataDict.get('author', None)
    article.content = dataDict.get('content', None)
    article.category = dataDict.get('category', None)
    article.point_num = dataDict.get('point_num', None)
    article.commont_num = dataDict.get('commont_num', None)
    article.fav_num = dataDict.get('fav_num', None)
    article.add_ip = request.remote_addr
    article.published = True

    res = article.save()
    if res:
        returnId = {
            'id': article.meta.id,
        }
        resultDict = returnMsg(returnId)
        return jsonify(resultDict)
    else:
        resultDict = returnNoneMsg("add failed!")
        return jsonify(resultDict)