Publications show their parent publisher's image by default.

master
Pacman Ghost 4 years ago
parent 3c57ea22e8
commit ff69969028
  1. 11
      asl_articles/tests/fixtures/default-publication-image.json
  2. 62
      asl_articles/tests/test_publications.py
  3. 6
      web/src/App.js
  4. 15
      web/src/PublicationSearchResult.js

@ -0,0 +1,11 @@
{
"publisher": [
{ "publ_id": 1, "publ_name": "Joe Publisher" }
],
"publication": [
{ "pub_name": "My Publication", "publ_id": 1}
]
}

@ -658,6 +658,68 @@ def test_article_order( webdriver, flask_app, dbconn ):
# ---------------------------------------------------------------------
def test_default_image( webdriver, flask_app, dbconn ):
"""Test displaying a publication's default image."""
# initialize
init_tests( webdriver, flask_app, dbconn, fixtures="default-publication-image.json" )
# initialize
from asl_articles.tests.test_publishers import edit_publisher #pylint: disable=import-outside-toplevel
images = [ "1.gif", "2.gif", "3.gif" ]
image_fnames = {
f: os.path.join( os.path.split(__file__)[0], "fixtures/images/"+f )
for f in images
}
image_data = {
f: open( image_fnames[f], "rb" ).read()
for f in images
}
# show the test publisher/publication
results = do_search( SEARCH_ALL )
publ_sr = find_search_result( "Joe Publisher", results )
pub_sr = find_search_result( "My Publication", results )
def check_images( publ_expected, pub_expected ):
do_check_image( publ_sr, publ_expected )
do_check_image( pub_sr, pub_expected )
def do_check_image( sr, expected ):
img = find_child( "img.image", sr )
if img:
assert expected
image_url = img.get_attribute( "src" )
resp = urllib.request.urlopen( image_url ).read()
assert resp == image_data[ expected ]
else:
assert not expected
# add an image to the publisher
edit_publisher( publ_sr, { "image": image_fnames["1.gif"] } )
check_images( "1.gif", "1.gif" )
# add an image to the publication
edit_publication( pub_sr, { "image": image_fnames["2.gif"] } )
check_images( "1.gif", "2.gif" )
# remove the publisher's image
edit_publisher( publ_sr, { "image": None } )
check_images( None, "2.gif" )
# add a different image to the publisher
edit_publisher( publ_sr, { "image": image_fnames["3.gif"] } )
check_images( "3.gif", "2.gif" )
# remove the publication's image
edit_publication( pub_sr, { "image": None } )
check_images( "3.gif", "3.gif" )
# detach the publication from the publisher
edit_publication( pub_sr, { "publisher": "(none)" } )
check_images( "3.gif", None)
# ---------------------------------------------------------------------
def create_publication( vals, toast_type="info", expected_error=None, expected_constraints=None, dlg=None ):
"""Create a new publication."""

@ -349,11 +349,11 @@ export default class App extends React.Component
}
return url ;
}
makeFlaskImageUrl( type, image_id, force ) {
makeFlaskImageUrl( type, imageId, force ) {
// generate an image URL for the Flask backend server
if ( ! image_id )
if ( ! imageId )
return null ;
let url = this.makeFlaskUrl( "/images/" + type + "/" + image_id ) ;
let url = this.makeFlaskUrl( "/images/" + type + "/" + imageId ) ;
if ( force )
url += "?foo=" + Math.random() ; // FUDGE! To bypass the cache :-/
return url ;

@ -18,7 +18,7 @@ export class PublicationSearchResult extends React.Component
// prepare the basic details
const display_description = this.props.data[ "pub_description!" ] || this.props.data.pub_description ;
const publ = gAppRef.caches.publishers[ this.props.data.publ_id ] ;
const image_url = gAppRef.makeFlaskImageUrl( "publication", this.props.data.pub_image_id, true ) ;
const image_url = PublicationSearchResult.makeImageUrl( this.props.data ) ;
// prepare the tags
let tags = [] ;
@ -201,4 +201,17 @@ export class PublicationSearchResult extends React.Component
}
_makeDisplayName( allowAlternateContent ) { return PublicationSearchResult.makeDisplayName( this.props.data, allowAlternateContent ) ; }
static makeImageUrl( vals ) {
let image_url = gAppRef.makeFlaskImageUrl( "publication", vals.pub_image_id, true ) ;
if ( ! image_url ) {
// check if the parent publisher has an image
if ( vals.publ_id ) {
const publ = gAppRef.caches.publishers[ vals.publ_id ] ;
if ( publ )
image_url = gAppRef.makeFlaskImageUrl( "publisher", publ.publ_image_id ) ;
}
}
return image_url ;
}
}

Loading…
Cancel
Save