Added page numbers to articles.

master
Pacman Ghost 4 years ago
parent 662b2e0ea3
commit 47c0ae31ad
  1. 28
      alembic/versions/07ff815f36b7_added_page_numbers_to_articles.py
  2. 5
      asl_articles/articles.py
  3. 1
      asl_articles/models.py
  4. 27
      asl_articles/tests/test_articles.py
  5. 4
      web/src/ArticleSearchResult.css
  6. 1
      web/src/ArticleSearchResult2.js
  7. 2
      web/src/ModalForm.css
  8. 2
      web/src/PublicationSearchResult.css
  9. 2
      web/src/PublisherSearchResult.css

@ -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 ###

@ -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 ),

@ -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,

@ -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: <span> <b>bold</b> xxx <i>italic</i></span>"
@ -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

@ -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 ; }

@ -108,6 +108,7 @@ export class ArticleSearchResult2
defaultValue = {currPub}
ref = { r => refs.pub_id=r }
/>
<input className="pageno" type="text" defaultValue={vals.article_pageno} ref={r => refs.article_pageno=r} alt="Page number." />
</div>
<div className="row snippet"> <label> Snippet: </label>
<textarea defaultValue={vals.article_snippet} ref={r => refs.article_snippet=r} />

@ -1,7 +1,7 @@
.modal-form .MuiDialog-paper { width: 80% ; max-width: 50em !important ; height: 80% ; }
.modal-form .MuiPaper-rounded { border-top-right-radius: 15px ; }
.modal-form .row { display: flex ; margin-bottom: 0.25em ; }
.modal-form .row { display: flex ; align-items: center ; margin-bottom: 0.25em ; }
.modal-form .row label { margin-top: 3px ; }
.modal-form .row label.select { margin-top: 10px ; }
.modal-form .row input , .row textarea , .row .react-select { flex-grow: 1 ; }

@ -2,5 +2,5 @@
#publication-form .row label { width: 3.25em ; }
#publication-form .row.edition input { flex-grow: 0 ; width: 3em ; }
#publication-form .row.description { flex-direction: column ; margin-top: -0.5em ; }
#publication-form .row.description { flex-direction: column ; align-items: initial ; margin-top: -0.5em ; }
#publication-form .row.description textarea { min-height: 6em ; }

@ -1,5 +1,5 @@
#publisher-form .row label.top { width: 4em ; }
#publisher-form .row label { width: 3em ; }
#publisher-form .row.description { flex-direction: column ; margin-top: -0.25em ; }
#publisher-form .row.description { flex-direction: column ; align-items: initial ; margin-top: -0.25em ; }
#publisher-form .row.description textarea { min-height: 6em ; }

Loading…
Cancel
Save