diff --git a/alembic/versions/07ff815f36b7_added_page_numbers_to_articles.py b/alembic/versions/07ff815f36b7_added_page_numbers_to_articles.py new file mode 100644 index 0000000..e378d3d --- /dev/null +++ b/alembic/versions/07ff815f36b7_added_page_numbers_to_articles.py @@ -0,0 +1,28 @@ +"""Added page numbers to articles. + +Revision ID: 07ff815f36b7 +Revises: e77d4e8d37f3 +Create Date: 2020-01-23 05:36:12.405233 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '07ff815f36b7' +down_revision = 'e77d4e8d37f3' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('article', sa.Column('article_pageno', sa.String(length=20), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('article', 'article_pageno') + # ### end Alembic commands ### diff --git a/asl_articles/articles.py b/asl_articles/articles.py index 3d07052..4ba7aa1 100644 --- a/asl_articles/articles.py +++ b/asl_articles/articles.py @@ -17,7 +17,9 @@ from asl_articles.utils import get_request_args, clean_request_args, clean_tags, _logger = logging.getLogger( "db" ) -_FIELD_NAMES = [ "*article_title", "article_subtitle", "article_snippet", "article_url", "article_tags", "pub_id" ] +_FIELD_NAMES = [ "*article_title", "article_subtitle", "article_snippet", "article_pageno", + "article_url", "article_tags", "pub_id" +] # --------------------------------------------------------------------- @@ -46,6 +48,7 @@ def get_article_vals( article, add_type=False ): "article_image_id": article.article_id if article.article_image else None, "article_authors": [ a.author_id for a in authors ], "article_snippet": article.article_snippet, + "article_pageno": article.article_pageno, "article_url": article.article_url, "article_scenarios": [ s.scenario_id for s in scenarios ], "article_tags": decode_tags( article.article_tags ), diff --git a/asl_articles/models.py b/asl_articles/models.py index 9813a25..3bfc344 100644 --- a/asl_articles/models.py +++ b/asl_articles/models.py @@ -61,6 +61,7 @@ class Article( db.Model ): article_title = db.Column( db.String(200), nullable=False ) article_subtitle = db.Column( db.String(200) ) article_snippet = db.Column( db.String(5000) ) + article_pageno = db.Column( db.String(20) ) article_url = db.Column( db.String(500) ) article_tags = db.Column( db.String(1000) ) pub_id = db.Column( db.Integer, diff --git a/asl_articles/tests/test_articles.py b/asl_articles/tests/test_articles.py index 67edb0a..0e070f1 100644 --- a/asl_articles/tests/test_articles.py +++ b/asl_articles/tests/test_articles.py @@ -29,13 +29,14 @@ def test_edit_article( webdriver, flask_app, dbconn ): "title": " Updated title ", "subtitle": " Updated subtitle ", "snippet": " Updated snippet. ", + "pageno": " p123 ", "tags": [ "+abc", "+xyz" ], "url": " http://updated-article.com ", } ) # check that the search result was updated in the UI sr = check_search_result( "Updated title", _check_sr, [ - "Updated title", "Updated subtitle", "Updated snippet.", ["abc","xyz"], "http://updated-article.com/" + "Updated title", "Updated subtitle", "Updated snippet.", "p123", ["abc","xyz"], "http://updated-article.com/" ] ) # try to remove all fields from the article (should fail) @@ -50,7 +51,7 @@ def test_edit_article( webdriver, flask_app, dbconn ): find_child( "button.ok", dlg ).click() # check that the search result was updated in the UI - expected = [ "Tin Cans Rock!", None, "", [], None ] + expected = [ "Tin Cans Rock!", None, "", "", [], None ] check_search_result( expected[0], _check_sr, expected ) # check that the article was updated in the database @@ -75,12 +76,13 @@ def test_create_article( webdriver, flask_app, dbconn ): "title": "New article", "subtitle": "New subtitle", "snippet": "New snippet.", + "pageno": "99", "tags": [ "+111", "+222", "+333" ], "url": "http://new-snippet.com" } ) # check that the new article appears in the UI - expected = [ "New article", "New subtitle", "New snippet.", ["111","222","333"], "http://new-snippet.com/" ] + expected = [ "New article", "New subtitle", "New snippet.", "99", ["111","222","333"], "http://new-snippet.com/" ] check_search_result( expected[0], _check_sr, expected ) # check that the new article has been saved in the database @@ -290,6 +292,7 @@ def test_unicode( webdriver, flask_app, dbconn ): "japan = \u65e5\u672c", "s.korea = \ud55c\uad6d", "greece = \u0395\u03bb\u03bb\u03ac\u03b4\u03b1", + "", [ "\u0e51", "\u0e52", "\u0e53" ], "http://xn--3e0b707e.com/" ] ) @@ -311,7 +314,7 @@ def test_clean_html( webdriver, flask_app, dbconn ): # check that the HTML was cleaned sr = check_search_result( None, _check_sr, [ - "title: bold xxx italic", "italicized subtitle", "bad stuff here:", [], None + "title: bold xxx italic", "italicized subtitle", "bad stuff here:", "", [], None ] ) assert find_child( ".title", sr ).get_attribute( "innerHTML" ) \ == "title: bold xxx italic" @@ -384,7 +387,7 @@ def create_article( vals, toast_type="info" ): # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -def edit_article( sr, vals, toast_type="info", expected_error=None ): +def edit_article( sr, vals, toast_type="info", expected_error=None ): #pylint: disable=too-many-branches """Edit a article's details.""" # initialize @@ -410,7 +413,13 @@ def edit_article( sr, vals, toast_type="info", expected_error=None ): select = ReactSelect( find_child( ".row.{} .react-select".format(key), dlg ) ) select.update_multiselect_values( *val ) else: - sel = ".row.{} {}".format( key , "textarea" if key == "snippet" else "input" ) + if key == "snippet": + sel = ".row.{} textarea".format( key ) + elif key == "pageno": + sel = "input.pageno" + else: + sel = ".row.{} input".format( key ) + print( "@@@",sel) set_elem_text( find_child( sel, dlg ), val ) set_toast_marker( toast_type ) find_child( "button.ok", dlg ).click() @@ -450,14 +459,14 @@ def _check_sr( sr, expected ): #pylint: disable=too-many-return-statements # check the tags tags = [ t.text for t in find_children( ".tag", sr ) ] - if tags != expected[3]: + if tags != expected[4]: return False # check the article's link elem = find_child( "a.open-link", sr ) - if expected[4]: + if expected[5]: assert elem - if elem.get_attribute( "href" ) != expected[4]: + if elem.get_attribute( "href" ) != expected[5]: return False else: assert elem is None diff --git a/web/src/ArticleSearchResult.css b/web/src/ArticleSearchResult.css index 609e5f4..5fc84ec 100644 --- a/web/src/ArticleSearchResult.css +++ b/web/src/ArticleSearchResult.css @@ -1,5 +1,7 @@ #article-form .row label.top { width: 6.5em ; } #article-form .row label { width: 5.75em ; } -#article-form .row.snippet { flex-direction: column ; margin-top: -0.5em ; } +#article-form .row.snippet { flex-direction: column ; align-items: initial ; margin-top: -0.5em ; } #article-form .row.snippet textarea { min-height: 6em ; } + +#article-form .pageno { flex-grow: 0 ; margin-left: 0.25em ; width: 3em ; } diff --git a/web/src/ArticleSearchResult2.js b/web/src/ArticleSearchResult2.js index 1add1cc..6809c3a 100644 --- a/web/src/ArticleSearchResult2.js +++ b/web/src/ArticleSearchResult2.js @@ -108,6 +108,7 @@ export class ArticleSearchResult2 defaultValue = {currPub} ref = { r => refs.pub_id=r } /> + refs.article_pageno=r} alt="Page number." />