Exemplo n.º 1
0
def update_article():
  title = request.args.get('Title')
  author = request.args.get('Author')
  email = request.args.get('Email')
  date = request.args.get('Date')
  url = request.args.get('URL')
  content = request.args.get('Content')
  status = request.args.get('Status')
  article = Article()
  article.create(title, author, email, date, url, content, status)
  return redirect('/blog', code=302)
Exemplo n.º 2
0
def put_article():
    '''
    Add new article for a user.
    '''
    username = request.headers.get('x-koala-username')
    apikey = request.headers.get('x-koala-key')
    user = locate_user(username, apikey)

    reqjson = request.get_json()

    result = validators.url(reqjson['url'])
    if not result:
        # try again but with http://
        result = validators.url('http://' + reqjson['url'])
        if not result:
            logging.info("Bad URL: %s" % reqjson['url'])
            abort(400)
        else:
            reqjson['url'] = 'http://' + reqjson['url']

    title = reqjson.get('title', reqjson['url'])
    url = reqjson['url']
    date = str(datetime.now())
    read = False
    favorite = False
    owner = user.id

    article = Article.create(title=title, url=url, date=date, read=read, favorite=favorite, owner=owner)

    return jsonify({'id': article.id}), 201
Exemplo n.º 3
0
def put_article():
    '''
    Add new article for a user.
    '''
    username = request.headers.get('x-koala-username')
    apikey = request.headers.get('x-koala-key')
    user = locate_user(username, apikey)

    reqjson = request.get_json()

    result = validators.url(reqjson['url'])
    if not result:
        # try again but with http://
        result = validators.url('http://' + reqjson['url'])
        if not result:
            logging.info("Bad URL: %s" % reqjson['url'])
            abort(400)
        else:
            reqjson['url'] = 'http://' + reqjson['url']

    title = reqjson.get('title', reqjson['url'])
    url = reqjson['url']
    date = str(datetime.now())
    read = False
    favorite = False
    owner = user.id

    article = Article.create(title=title,
                             url=url,
                             date=date,
                             read=read,
                             favorite=favorite,
                             owner=owner)

    return jsonify({'id': article.id}), 201
Exemplo n.º 4
0
    def post(self):
        title = self.get_argument('title')
        content_md = self.get_argument('content')
        pattern = r'\[[^\[\]]+\]'
        labels = re.findall(pattern, self.get_argument('labels'))
        content_html = markdown.markdown(content_md, ['codehilite'])

        try:
            article_id = Article.create(self.db, title, content_md, content_html)
            for label in labels:
                detail = label[1:-1].strip()
                Label.create(self.db, article_id, detail)

            self.redirect('/', permanent=True)
        except:
            error = "The post data invalid"
            self.render('error.html', error=error, home_title=options.home_title)