Esempio n. 1
0
def article_add_post():
    try:
        article_date = datetime.strptime(request.form.get('date'), '%m/%d/%Y %I:%M %p')
        new_article = None
        if request.form.get('publication') is "":
            new_article = Article(request.form.get('title'), request.form.get('summary'), article_date,
                                  uuid.UUID(request.form.get('page_id')), )
        else:
            new_article = Article(request.form.get('title'), request.form.get('summary'), article_date,
                                  uuid.UUID(request.form.get('page_id')),
                                  request.form.get('publication'))
        if not new_article.is_valid_model():
            abort(500)
        new_article.save_to_db()
        return jsonify({"message": "Done"}), 200
    except ValueError:
        abort(500)
Esempio n. 2
0
def article_edit_put():
    try:
        article_date = datetime.strptime(request.form.get('date'),
                                         '%m/%d/%Y %I:%M %p')
        if request.form.get('publication') is "":
            new_article = Article(request.form.get('title'),
                                  request.form.get('summary'), article_date,
                                  uuid.UUID(request.form.get('page_id')), None,
                                  uuid.UUID(request.form.get('id')))
        else:
            new_article = Article(request.form.get('title'),
                                  request.form.get('summary'), article_date,
                                  uuid.UUID(request.form.get('page_id')),
                                  request.form.get('publication'),
                                  uuid.UUID(request.form.get('id')))
        if not new_article.is_valid_model():
            abort(500)
        new_article.sync_to_db()
        return jsonify({"message": "Done"}), 200
    except ValueError:
        abort(500)
Esempio n. 3
0
 def test_is_not_valid_model(self):
     article = Article(12, 12, "hello", "sd",  uuid.uuid4())
     self.assertFalse(article.is_valid_model(),"Invalid model is valid")
Esempio n. 4
0
 def test_is_valid_model(self):
     article = Article("Test", "lk", datetime.now(), uuid.uuid4(), None, uuid.uuid4())
     self.assertTrue(article.is_valid_model(),"Valid model is invalid")