Added publication dates.

master
Pacman Ghost 4 years ago
parent 666ea2be57
commit b4571800ad
  1. 28
      alembic/versions/41cfc117c809_added_publication_dates.py
  2. 1
      asl_articles/models.py
  3. 3
      asl_articles/publications.py
  4. 45
      asl_articles/tests/test_articles.py
  5. 80
      asl_articles/tests/test_publications.py
  6. 30
      asl_articles/tests/test_publishers.py
  7. 2
      web/src/PublicationSearchResult.css
  8. 1
      web/src/PublicationSearchResult.js
  9. 5
      web/src/PublicationSearchResult2.js

@ -0,0 +1,28 @@
"""Added publication dates.
Revision ID: 41cfc117c809
Revises: 064497c51f2d
Create Date: 2020-01-31 15:02:57.126183
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '41cfc117c809'
down_revision = '064497c51f2d'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('publication', sa.Column('pub_date', sa.String(length=100), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('publication', 'pub_date')
# ### end Alembic commands ###

@ -35,6 +35,7 @@ class Publication( db.Model ):
pub_id = db.Column( db.Integer, primary_key=True )
pub_name = db.Column( db.String(100), nullable=False )
pub_edition = db.Column( db.String(100) )
pub_date = db.Column( db.String(100) ) # nb: this is just a display string
pub_description = db.Column( db.String(1000) )
pub_url = db.Column( db.String(500) )
pub_tags = db.Column( db.String(1000) )

@ -16,7 +16,7 @@ from asl_articles.utils import get_request_args, clean_request_args, clean_tags,
_logger = logging.getLogger( "db" )
_FIELD_NAMES = [ "*pub_name", "pub_edition", "pub_description", "pub_url", "pub_tags", "publ_id" ]
_FIELD_NAMES = [ "*pub_name", "pub_edition", "pub_description", "pub_date", "pub_url", "pub_tags", "publ_id" ]
# ---------------------------------------------------------------------
@ -54,6 +54,7 @@ def get_publication_vals( pub, add_type=False ):
"pub_id": pub.pub_id,
"pub_name": pub.pub_name,
"pub_edition": pub.pub_edition,
"pub_date": pub.pub_date,
"pub_description": pub.pub_description,
"pub_url": pub.pub_url,
"pub_image_id": pub.pub_id if pub.pub_image else None,

@ -376,16 +376,7 @@ def create_article( vals, toast_type="info" ):
# create the new article
select_main_menu_option( "new-article" )
dlg = wait_for_elem( 2, "#article-form" )
for key,val in vals.items():
if key in ["authors","scenarios","tags"]:
select = ReactSelect( find_child( ".row.{} .react-select".format(key), dlg ) )
select.update_multiselect_values( *val )
elif key == "publication":
select = ReactSelect( find_child( ".row.publication .react-select", dlg ) )
select.select_by_name( val )
else:
sel = ".row.{} {}".format( key , "textarea" if key == "snippet" else "input" )
set_elem_text( find_child( sel, dlg ), val )
_update_values( dlg, vals )
find_child( "button.ok", dlg ).click()
if toast_type:
@ -408,6 +399,24 @@ def edit_article( sr, vals, toast_type="info", expected_error=None ): #pylint: d
dlg = wait_for_elem( 2, "#article-form" )
# update the specified article's details
_update_values( dlg, vals )
set_toast_marker( toast_type )
find_child( "button.ok", dlg ).click()
# check what happened
if expected_error:
# we were expecting an error, confirm the error message
check_error_msg( expected_error )
else:
# we were expecting the update to work, confirm this
expected = "updated OK" if sr else "created OK"
wait_for( 2,
lambda: check_toast( toast_type, expected, contains=True )
)
wait_for_not_elem( 2, "#article-form" )
def _update_values( dlg, vals ):
"""Update an article's values in the form."""
for key,val in vals.items():
if key == "image":
if val:
@ -424,26 +433,12 @@ def edit_article( sr, vals, toast_type="info", expected_error=None ): #pylint: d
select.update_multiselect_values( *val )
else:
if key == "snippet":
sel = ".row.{} textarea".format( key )
sel = ".row.snippet textarea"
elif key == "pageno":
sel = "input.pageno"
else:
sel = ".row.{} input".format( key )
set_elem_text( find_child( sel, dlg ), val )
set_toast_marker( toast_type )
find_child( "button.ok", dlg ).click()
# check what happened
if expected_error:
# we were expecting an error, confirm the error message
check_error_msg( expected_error )
else:
# we were expecting the update to work, confirm this
expected = "updated OK" if sr else "created OK"
wait_for( 2,
lambda: check_toast( toast_type, expected, contains=True )
)
wait_for_not_elem( 2, "#article-form" )
# ---------------------------------------------------------------------

@ -33,13 +33,16 @@ def test_edit_publication( webdriver, flask_app, dbconn ):
edit_publication( sr, {
"name": " ASL Journal (updated) ",
"edition": " 2a ",
"pub_date": "Jan 2020",
"description": " Updated ASLJ description. ",
"tags": [ "+abc", "+xyz" ],
"url": " http://aslj-updated.com ",
} )
# check that the search result was updated in the UI
expected = [ "ASL Journal (updated)", "2a", "Updated ASLJ description.", ["abc","xyz"], "http://aslj-updated.com/" ]
expected = [ "ASL Journal (updated)", "2a", "Jan 2020",
"Updated ASLJ description.", ["abc","xyz"], "http://aslj-updated.com/"
]
sr = find_search_result( "ASL Journal (updated) (2a)" )
check_search_result( sr, _check_sr, expected )
@ -69,14 +72,15 @@ def test_create_publication( webdriver, flask_app, dbconn ):
edit_publication( None, { # nb: the form is still on-screen
"name": "New publication",
"edition": "#1",
"pub_date": "1st January, 1900",
"description": "New publication description.",
"tags": [ "+111", "+222", "+333" ],
"url": "http://new-publication.com"
} )
# check that the new publication appears in the UI
expected = [ "New publication", "#1", "New publication description.",
["111","222","333"], "http://new-publication.com/"
expected = [ "New publication", "#1", "1st January, 1900",
"New publication description.", ["111","222","333"], "http://new-publication.com/"
]
check_search_result( "New publication (#1)", _check_sr, expected )
@ -337,6 +341,7 @@ def test_unicode( webdriver, flask_app, dbconn ):
assert len( results ) == 1
check_search_result( results[0], _check_sr, [
"japan = \u65e5\u672c", "\u263a",
None,
"greece = \u0395\u03bb\u03bb\u03ac\u03b4\u03b1",
[ "\u0e51", "\u0e52", "\u0e53" ],
"http://xn--3e0b707e.com/"
@ -365,6 +370,7 @@ def test_clean_html( webdriver, flask_app, dbconn ):
sr = check_search_result( None, _check_sr, [
"name: bold xxx italic {}".format( replace[1] ),
"2",
None,
"bad stuff here: {}".format( replace[1] ),
[], None
] )
@ -509,17 +515,7 @@ def create_publication( vals, toast_type="info" ):
# create the new publication
select_main_menu_option( "new-publication" )
dlg = wait_for_elem( 2, "#publication-form" )
for key,val in vals.items():
if key == "name":
elem = find_child( ".row.name .react-select input", dlg )
set_elem_text( elem, val )
elem.send_keys( Keys.RETURN )
elif key == "tags":
select = ReactSelect( find_child( ".row.tags .react-select", dlg ) )
select.update_multiselect_values( *val )
else:
sel = ".row.{} {}".format( key , "textarea" if key == "description" else "input" )
set_elem_text( find_child( sel, dlg ), val )
_update_values( dlg, vals )
find_child( "button.ok", dlg ).click()
if toast_type:
@ -540,6 +536,24 @@ def edit_publication( sr, vals, toast_type="info", expected_error=None ):
dlg = wait_for_elem( 2, "#publication-form" )
# update the specified publication's details
_update_values( dlg, vals )
set_toast_marker( toast_type )
find_child( "button.ok", dlg ).click()
# check what happened
if expected_error:
# we were expecting an error, confirm the error message
check_error_msg( expected_error )
else:
# we were expecting the update to work, confirm this
expected = "updated OK" if sr else "created OK"
wait_for( 2,
lambda: check_toast( toast_type, expected, contains=True )
)
wait_for_not_elem( 2, "#publication-form" )
def _update_values( dlg, vals ):
"""Update a publication's values in the form."""
for key,val in vals.items():
if key == "image":
if val:
@ -559,22 +573,13 @@ def edit_publication( sr, vals, toast_type="info", expected_error=None ):
select = ReactSelect( find_child( ".row.tags .react-select", dlg ) )
select.update_multiselect_values( *val )
else:
sel = ".row.{} {}".format( key , "textarea" if key == "description" else "input" )
if key == "edition":
sel = "input.edition"
elif key == "description":
sel = ".row.description textarea"
else:
sel = ".row.{} input".format( key )
set_elem_text( find_child( sel, dlg ), val )
set_toast_marker( toast_type )
find_child( "button.ok", dlg ).click()
# check what happened
if expected_error:
# we were expecting an error, confirm the error message
check_error_msg( expected_error )
else:
# we were expecting the update to work, confirm this
expected = "updated OK" if sr else "created OK"
wait_for( 2,
lambda: check_toast( toast_type, expected, contains=True )
)
wait_for_not_elem( 2, "#publication-form" )
# ---------------------------------------------------------------------
@ -588,20 +593,29 @@ def _check_sr( sr, expected ):
if find_child( ".name", sr ).text != expected_name:
return False
# check the publication date
elem = find_child( ".pub_date", sr )
if expected[2]:
assert elem
if elem.text != expected[2]:
return False
else:
assert elem is None
# check the description
if find_child( ".description", sr ).text != expected[2]:
if find_child( ".description", sr ).text != expected[3]:
return False
# 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 publication'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

@ -394,9 +394,7 @@ def create_publisher( vals, toast_type="info" ):
# create the new publisher
select_main_menu_option( "new-publisher" )
dlg = wait_for_elem( 2, "#publisher-form" )
for key,val in vals.items():
sel = ".row.{} {}".format( key , "textarea" if key == "description" else "input" )
set_elem_text( find_child( sel, dlg ), val )
_update_values( dlg, vals )
find_child( "button.ok", dlg ).click()
if toast_type:
@ -419,17 +417,7 @@ def edit_publisher( sr, vals, toast_type="info", expected_error=None ):
dlg = wait_for_elem( 2, "#publisher-form" )
# update the specified publisher's details
for key,val in vals.items():
if key == "image":
if val:
data = base64.b64encode( open( val, "rb" ).read() )
data = "{}|{}".format( os.path.split(val)[1], data.decode("ascii") )
change_image( find_child( ".row.image img.image", dlg ), data )
else:
find_child( ".row.image .remove-image", dlg ).click()
else:
sel = ".row.{} {}".format( key , "textarea" if key == "description" else "input" )
set_elem_text( find_child( sel, dlg ), val )
_update_values( dlg, vals )
set_toast_marker( toast_type )
find_child( "button.ok", dlg ).click()
@ -445,6 +433,20 @@ def edit_publisher( sr, vals, toast_type="info", expected_error=None ):
)
wait_for_not_elem( 2, "#publisher-form" )
def _update_values( dlg, vals ):
"""Update a publishers's values in the form."""
for key,val in vals.items():
if key == "image":
if val:
data = base64.b64encode( open( val, "rb" ).read() )
data = "{}|{}".format( os.path.split(val)[1], data.decode("ascii") )
change_image( find_child( ".row.image img.image", dlg ), data )
else:
find_child( ".row.image .remove-image", dlg ).click()
else:
sel = ".row.{} {}".format( key , "textarea" if key == "description" else "input" )
set_elem_text( find_child( sel, dlg ), val )
# ---------------------------------------------------------------------
def _check_sr( sr, expected ):

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

@ -57,6 +57,7 @@ export class PublicationSearchResult extends React.Component
<div className="description" dangerouslySetInnerHTML={{__html: display_description}} />
</div>
<div className="footer">
{ this.props.data.pub_date && <div> <label>Published:</label> <span className="pub_date"> {this.props.data.pub_date} </span> </div> }
{ tags.length > 0 && <div className="tags"> <label>Tags:</label> {tags} </div> }
</div>
</div> ) ;

@ -117,9 +117,10 @@ export class PublicationSearchResult2
defaultValue = {currPub}
ref = { r => refs.pub_name=r }
/>
<input className="edition" type="text" defaultValue={vals.pub_edition} ref={r => refs.pub_edition=r} title="Publication edition." />
</div>
<div className="row edition"> <label className="top"> Edition: </label>
<input type="text" defaultValue={vals.pub_edition} ref={r => refs.pub_edition=r} />
<div className="row pub_date"> <label className="select top"> Date: </label>
<input className="pub_date" type="text" defaultValue={vals.pub_date} ref={r => refs.pub_date=r} />
</div>
<div className="row publisher"> <label className="select top"> Publisher: </label>
<Select className="react-select" classNamePrefix="react-select" options={publishers} isSearchable={true}

Loading…
Cancel
Save