def create_publication(): """Create a publication.""" # parse the input vals = get_request_args(request.json, _FIELD_NAMES, log=(_logger, "Create publication:")) warnings = [] clean_request_args(vals, _FIELD_NAMES, warnings, _logger) # NOTE: Tags are stored in the database using \n as a separator, so we need to encode *after* cleaning them. cleaned_tags = clean_tags(vals.get("pub_tags"), warnings) vals["pub_tags"] = encode_tags(cleaned_tags) # create the new publication vals["time_created"] = datetime.datetime.now() pub = Publication(**vals) db.session.add(pub) _set_seqno(pub, pub.publ_id) _save_image(pub) db.session.commit() _logger.debug("- New ID: %d", pub.pub_id) search.add_or_update_publication(None, pub, None) # generate the response vals = get_publication_vals(pub, False, True) return make_ok_response(record=vals, warnings=warnings)
def create_article(): """Create an article.""" # parse the input vals = get_request_args(request.json, _FIELD_NAMES, log=(_logger, "Create article:")) warnings = [] clean_request_args(vals, _FIELD_NAMES, warnings, _logger) # NOTE: Tags are stored in the database using \n as a separator, so we need to encode *after* cleaning them. cleaned_tags = clean_tags(vals.get("article_tags"), warnings) vals["article_tags"] = encode_tags(cleaned_tags) # create the new article vals["time_created"] = datetime.datetime.now() if not vals.get("publ_id"): vals.pop("article_date", None) article = Article(**vals) db.session.add(article) db.session.flush() new_article_id = article.article_id _set_seqno(article, article.pub_id) _save_authors(article) _save_scenarios(article) _save_image(article) db.session.commit() _logger.debug("- New ID: %d", new_article_id) search.add_or_update_article(None, article, None) # generate the response vals = get_article_vals(article, True) return make_ok_response(record=vals, warnings=warnings)
def update_article(): """Update an article.""" # parse the input article_id = request.json["article_id"] vals = get_request_args(request.json, _FIELD_NAMES, log=(_logger, "Update article: id={}".format(article_id))) warnings = [] clean_request_args(vals, _FIELD_NAMES, warnings, _logger) # NOTE: Tags are stored in the database using \n as a separator, so we need to encode *after* cleaning them. cleaned_tags = clean_tags(vals.get("article_tags"), warnings) vals["article_tags"] = encode_tags(cleaned_tags) # update the article article = Article.query.get(article_id) if not article: abort(404) if vals["pub_id"] != article.pub_id: _set_seqno(article, vals["pub_id"]) vals["time_updated"] = datetime.datetime.now() apply_attrs(article, vals) if not vals.get("publ_id"): article.article_date = None _save_authors(article) _save_scenarios(article) _save_image(article) db.session.commit() search.add_or_update_article(None, article, None) # generate the response vals = get_article_vals(article, True) return make_ok_response(record=vals, warnings=warnings)
def update_publisher(): """Update a publisher.""" # parse the input publ_id = request.json[ "publ_id" ] vals = get_request_args( request.json, _FIELD_NAMES, log = ( _logger, "Update publisher: id={}".format( publ_id ) ) ) warnings = [] updated = clean_request_args( vals, _FIELD_NAMES, warnings, _logger ) # update the publisher publ = Publisher.query.get( publ_id ) if not publ: abort( 404 ) _save_image( publ, updated ) vals[ "time_updated" ] = datetime.datetime.now() apply_attrs( publ, vals ) db.session.commit() search.add_or_update_publisher( None, publ, None ) # generate the response extras = {} if request.args.get( "list" ): extras[ "publishers" ] = _do_get_publishers() return make_ok_response( updated=updated, extras=extras, warnings=warnings )
def update_publication(): """Update a publication.""" # parse the input pub_id = request.json["pub_id"] vals = get_request_args(request.json, _FIELD_NAMES, log=(_logger, "Update publication: id={}".format(pub_id))) warnings = [] clean_request_args(vals, _FIELD_NAMES, warnings, _logger) article_order = request.json.get("article_order") # NOTE: Tags are stored in the database using \n as a separator, so we need to encode *after* cleaning them. cleaned_tags = clean_tags(vals.get("pub_tags"), warnings) vals["pub_tags"] = encode_tags(cleaned_tags) # update the publication pub = Publication.query.get(pub_id) if not pub: abort(404) if vals["publ_id"] != pub.publ_id: _set_seqno(pub, vals["publ_id"]) vals["time_updated"] = datetime.datetime.now() apply_attrs(pub, vals) _save_image(pub) if article_order: query = Article.query.filter(Article.pub_id == pub_id) articles = {int(a.article_id): a for a in query} for n, article_id in enumerate(article_order): if article_id not in articles: _logger.warning( "Can't set seq# for article %d, not in publication %d: %s", article_id, pub_id, article_order) continue articles[article_id].article_seqno = n del articles[article_id] if articles: _logger.warning( "seq# was not set for some articles in publication %d: %s", pub_id, ", ".join(str(k) for k in articles)) db.session.commit() search.add_or_update_publication(None, pub, None) # generate the response vals = get_publication_vals(pub, False, True) return make_ok_response(record=vals, warnings=warnings)
def create_publisher(): """Create a publisher.""" # parse the input vals = get_request_args( request.json, _FIELD_NAMES, log = ( _logger, "Create publisher:" ) ) warnings = [] clean_request_args( vals, _FIELD_NAMES, warnings, _logger ) # create the new publisher vals[ "time_created" ] = datetime.datetime.now() publ = Publisher( **vals ) db.session.add( publ ) _save_image( publ ) db.session.commit() _logger.debug( "- New ID: %d", publ.publ_id ) search.add_or_update_publisher( None, publ, None ) # generate the response vals = get_publisher_vals( publ, True, True ) return make_ok_response( record=vals, warnings=warnings )
def update_article(): """Update an article.""" # parse the input article_id = request.json["article_id"] vals = get_request_args(request.json, _FIELD_NAMES, log=(_logger, "Update article: id={}".format(article_id))) warnings = [] updated = clean_request_args(vals, _FIELD_NAMES, warnings, _logger) # NOTE: Tags are stored in the database using \n as a separator, so we need to encode *after* cleaning them. cleaned_tags = clean_tags(vals.get("article_tags"), warnings) vals["article_tags"] = encode_tags(cleaned_tags) if cleaned_tags != vals.get("article_tags"): updated["article_tags"] = decode_tags(vals["article_tags"]) # update the article article = Article.query.get(article_id) if not article: abort(404) orig_pub = Publication.query.get( article.pub_id) if article.pub_id else None if vals["pub_id"] != article.pub_id: _set_seqno(article, vals["pub_id"]) vals["time_updated"] = datetime.datetime.now() apply_attrs(article, vals) _save_authors(article, updated) _save_scenarios(article, updated) _save_image(article, updated) db.session.commit() search.add_or_update_article(None, article, None) # generate the response extras = {} if request.args.get("list"): extras["authors"] = do_get_authors() extras["scenarios"] = do_get_scenarios() extras["tags"] = do_get_tags() pubs = [] if orig_pub and orig_pub.pub_id != article.pub_id: pubs.append( asl_articles.publications.get_publication_vals(orig_pub, True)) if article.pub_id: pub = Publication.query.get(article.pub_id) pubs.append( asl_articles.publications.get_publication_vals(pub, True)) if pubs: extras["_publications"] = pubs return make_ok_response(updated=updated, extras=extras, warnings=warnings)
def create_article(): """Create an article.""" # parse the input vals = get_request_args(request.json, _FIELD_NAMES, log=(_logger, "Create article:")) warnings = [] updated = clean_request_args(vals, _FIELD_NAMES, warnings, _logger) # NOTE: Tags are stored in the database using \n as a separator, so we need to encode *after* cleaning them. cleaned_tags = clean_tags(vals.get("article_tags"), warnings) vals["article_tags"] = encode_tags(cleaned_tags) if cleaned_tags != vals.get("article_tags"): updated["article_tags"] = decode_tags(vals["article_tags"]) # create the new article vals["time_created"] = datetime.datetime.now() article = Article(**vals) db.session.add(article) db.session.flush() new_article_id = article.article_id _set_seqno(article, article.pub_id) _save_authors(article, updated) _save_scenarios(article, updated) _save_image(article, updated) db.session.commit() _logger.debug("- New ID: %d", new_article_id) search.add_or_update_article(None, article, None) # generate the response extras = {"article_id": new_article_id} if request.args.get("list"): extras["authors"] = do_get_authors() extras["scenarios"] = do_get_scenarios() extras["tags"] = do_get_tags() if article.pub_id: pub = Publication.query.get(article.pub_id) extras[ "_publication"] = asl_articles.publications.get_publication_vals( pub, True) return make_ok_response(updated=updated, extras=extras, warnings=warnings)
def create_publisher(): """Create a publisher.""" # parse the input vals = get_request_args( request.json, _FIELD_NAMES, log = ( _logger, "Create publisher:" ) ) warnings = [] updated = clean_request_args( vals, _FIELD_NAMES, warnings, _logger ) # create the new publisher vals[ "time_created" ] = datetime.datetime.now() publ = Publisher( **vals ) db.session.add( publ ) _save_image( publ, updated ) db.session.commit() _logger.debug( "- New ID: %d", publ.publ_id ) search.add_or_update_publisher( None, publ, None ) # generate the response extras = { "publ_id": publ.publ_id } if request.args.get( "list" ): extras[ "publishers" ] = _do_get_publishers() return make_ok_response( updated=updated, extras=extras, warnings=warnings )