commit/galaxy-central: 3 new changesets
3 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6aef91d12890/ changeset: 6aef91d12890 user: kellrott date: 2012-12-27 20:40:20 summary: The start of the API based annotation system affected #: 3 files diff -r c8f0ea550d51b2c203f5f60568817164c62220fd -r 6aef91d128904c405356e9fa2f3afa43368c8e8a lib/galaxy/model/item_attrs.py --- a/lib/galaxy/model/item_attrs.py +++ b/lib/galaxy/model/item_attrs.py @@ -137,6 +137,12 @@ # Set annotation. annotation_assoc.annotation = annotation return annotation_assoc + + def delete_item_annotation( self, db_session, user, item): + annotation_assoc = self.get_item_annotation_obj( db_session, user, item ) + if annotation_assoc: + db_session.delete(annotation_assoc) + db_session.flush() def copy_item_annotation( self, db_session, source_user, source_item, target_user, target_item ): """ Copy an annotation from a user/item source to a user/item target. """ diff -r c8f0ea550d51b2c203f5f60568817164c62220fd -r 6aef91d128904c405356e9fa2f3afa43368c8e8a lib/galaxy/webapps/galaxy/api/annotations.py --- /dev/null +++ b/lib/galaxy/webapps/galaxy/api/annotations.py @@ -0,0 +1,76 @@ +""" +API operations on annotations. +""" +import logging, os, string, shutil, urllib, re, socket +from cgi import escape, FieldStorage +from galaxy import util, datatypes, jobs, web, util +from galaxy.web.base.controller import * +from galaxy.model.item_attrs import * +from galaxy.util.sanitize_html import sanitize_html +from galaxy.model.orm import * +import galaxy.datatypes +from galaxy.util.bunch import Bunch + +import pkg_resources +pkg_resources.require( "Routes" ) +import routes + +log = logging.getLogger( __name__ ) + +class BaseAnnotationsController( BaseAPIController, UsesAnnotations, UsesHistoryMixin, UsesHistoryDatasetAssociationMixin, UsesStoredWorkflowMixin ): + + @web.expose_api + def index( self, trans, **kwd ): + idnum = kwd[self.tagged_item_id] + item = self._get_item_from_id(trans, idnum) + if item is not None: + return self.get_item_annotation_str( trans.sa_session, trans.get_user(), item ) + + + @web.expose_api + def create( self, trans, payload, **kwd ): + if "text" not in payload: + return "" + idnum = kwd[self.tagged_item_id] + item = self._get_item_from_id(trans, idnum) + if item is not None: + new_annotation = payload.get("text") + # Sanitize annotation before adding it. + new_annotation = sanitize_html( new_annotation, 'utf-8', 'text/html' ) + + self.add_item_annotation( trans.sa_session, trans.get_user(), item, new_annotation ) + trans.sa_session.flush() + return new_annotation + return "" + + @web.expose_api + def delete( self, trans, **kwd ): + idnum = kwd[self.tagged_item_id] + item = self._get_item_from_id(trans, idnum) + if item is not None: + return self.delete_item_annotation( trans.sa_session, trans.get_user(), item ) + + @web.expose_api + def undelete( self, trans, **kwd ): + raise HTTPNotImplemented() + +class HistoryAnnotationsController(BaseAnnotationsController): + controller_name = "history_annotations" + tagged_item_id = "history_id" + def _get_item_from_id(self, trans, idstr): + hist = self.get_history( trans, idstr ) + return hist + +class HistoryContentAnnotationsController(BaseAnnotationsController): + controller_name = "history_content_annotations" + tagged_item_id = "history_content_id" + def _get_item_from_id(self, trans, idstr): + hda = self.get_dataset(trans, idstr) + return hda + +class WorkflowAnnotationsController(BaseAnnotationsController): + controller_name = "workflow_annotations" + tagged_item_id = "workflow_id" + def _get_item_from_id(self, trans, idstr): + hda = self.get_stored_workflow(trans, idstr) + return hda diff -r c8f0ea550d51b2c203f5f60568817164c62220fd -r 6aef91d128904c405356e9fa2f3afa43368c8e8a lib/galaxy/webapps/galaxy/buildapp.py --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -105,6 +105,17 @@ _add_item_tags_controller( webapp, name_prefix="workflow_", path_prefix='/api/workflows/:workflow_id' ) + + _add_item_annotation_controller( webapp, + name_prefix="history_content_", + path_prefix='/api/histories/:history_id/contents/:history_content_id' ) + _add_item_annotation_controller( webapp, + name_prefix="history_", + path_prefix='/api/histories/:history_id' ) + _add_item_annotation_controller( webapp, + name_prefix="workflow_", + path_prefix='/api/workflows/:workflow_id' ) + webapp.api_mapper.resource( 'dataset', 'datasets', path_prefix='/api' ) webapp.api_mapper.resource_with_deleted( 'library', 'libraries', path_prefix='/api' ) webapp.api_mapper.resource( 'sample', 'samples', path_prefix='/api' ) @@ -185,6 +196,12 @@ conditions=dict(method=["GET"])) + +def _add_item_annotation_controller( webapp, name_prefix, path_prefix, **kwd ): + controller = "%sannotations" % name_prefix + name = "%sannotation" % name_prefix + webapp.api_mapper.resource(name, "annotation", path_prefix=path_prefix, controller=controller) + def wrap_in_middleware( app, global_conf, **local_conf ): """ Based on the configuration wrap `app` in a set of common and useful https://bitbucket.org/galaxy/galaxy-central/commits/f8fac0ad9808/ changeset: f8fac0ad9808 user: kellrott date: 2013-01-18 17:52:33 summary: Removing '*' imports from annotations API module affected #: 1 file diff -r 6aef91d128904c405356e9fa2f3afa43368c8e8a -r f8fac0ad9808825e4ac7228a9da5e0f8d8a3ca48 lib/galaxy/webapps/galaxy/api/annotations.py --- a/lib/galaxy/webapps/galaxy/api/annotations.py +++ b/lib/galaxy/webapps/galaxy/api/annotations.py @@ -4,10 +4,9 @@ import logging, os, string, shutil, urllib, re, socket from cgi import escape, FieldStorage from galaxy import util, datatypes, jobs, web, util -from galaxy.web.base.controller import * -from galaxy.model.item_attrs import * +from galaxy.web.base.controller import BaseAPIController, UsesHistoryMixin, UsesHistoryDatasetAssociationMixin, UsesStoredWorkflowMixin +from galaxy.model.item_attrs import UsesAnnotations from galaxy.util.sanitize_html import sanitize_html -from galaxy.model.orm import * import galaxy.datatypes from galaxy.util.bunch import Bunch https://bitbucket.org/galaxy/galaxy-central/commits/98f724202d9d/ changeset: 98f724202d9d user: jgoecks date: 2013-01-18 18:02:51 summary: Merged in kellrott/galaxy-central (pull request #101) The start of the API based annotation system affected #: 3 files diff -r 666d744054ded20d79e3d2c6eb65012455de96b5 -r 98f724202d9d3cea035d7de04d89465bcf3092b1 lib/galaxy/model/item_attrs.py --- a/lib/galaxy/model/item_attrs.py +++ b/lib/galaxy/model/item_attrs.py @@ -137,6 +137,12 @@ # Set annotation. annotation_assoc.annotation = annotation return annotation_assoc + + def delete_item_annotation( self, db_session, user, item): + annotation_assoc = self.get_item_annotation_obj( db_session, user, item ) + if annotation_assoc: + db_session.delete(annotation_assoc) + db_session.flush() def copy_item_annotation( self, db_session, source_user, source_item, target_user, target_item ): """ Copy an annotation from a user/item source to a user/item target. """ diff -r 666d744054ded20d79e3d2c6eb65012455de96b5 -r 98f724202d9d3cea035d7de04d89465bcf3092b1 lib/galaxy/webapps/galaxy/api/annotations.py --- /dev/null +++ b/lib/galaxy/webapps/galaxy/api/annotations.py @@ -0,0 +1,75 @@ +""" +API operations on annotations. +""" +import logging, os, string, shutil, urllib, re, socket +from cgi import escape, FieldStorage +from galaxy import util, datatypes, jobs, web, util +from galaxy.web.base.controller import BaseAPIController, UsesHistoryMixin, UsesHistoryDatasetAssociationMixin, UsesStoredWorkflowMixin +from galaxy.model.item_attrs import UsesAnnotations +from galaxy.util.sanitize_html import sanitize_html +import galaxy.datatypes +from galaxy.util.bunch import Bunch + +import pkg_resources +pkg_resources.require( "Routes" ) +import routes + +log = logging.getLogger( __name__ ) + +class BaseAnnotationsController( BaseAPIController, UsesAnnotations, UsesHistoryMixin, UsesHistoryDatasetAssociationMixin, UsesStoredWorkflowMixin ): + + @web.expose_api + def index( self, trans, **kwd ): + idnum = kwd[self.tagged_item_id] + item = self._get_item_from_id(trans, idnum) + if item is not None: + return self.get_item_annotation_str( trans.sa_session, trans.get_user(), item ) + + + @web.expose_api + def create( self, trans, payload, **kwd ): + if "text" not in payload: + return "" + idnum = kwd[self.tagged_item_id] + item = self._get_item_from_id(trans, idnum) + if item is not None: + new_annotation = payload.get("text") + # Sanitize annotation before adding it. + new_annotation = sanitize_html( new_annotation, 'utf-8', 'text/html' ) + + self.add_item_annotation( trans.sa_session, trans.get_user(), item, new_annotation ) + trans.sa_session.flush() + return new_annotation + return "" + + @web.expose_api + def delete( self, trans, **kwd ): + idnum = kwd[self.tagged_item_id] + item = self._get_item_from_id(trans, idnum) + if item is not None: + return self.delete_item_annotation( trans.sa_session, trans.get_user(), item ) + + @web.expose_api + def undelete( self, trans, **kwd ): + raise HTTPNotImplemented() + +class HistoryAnnotationsController(BaseAnnotationsController): + controller_name = "history_annotations" + tagged_item_id = "history_id" + def _get_item_from_id(self, trans, idstr): + hist = self.get_history( trans, idstr ) + return hist + +class HistoryContentAnnotationsController(BaseAnnotationsController): + controller_name = "history_content_annotations" + tagged_item_id = "history_content_id" + def _get_item_from_id(self, trans, idstr): + hda = self.get_dataset(trans, idstr) + return hda + +class WorkflowAnnotationsController(BaseAnnotationsController): + controller_name = "workflow_annotations" + tagged_item_id = "workflow_id" + def _get_item_from_id(self, trans, idstr): + hda = self.get_stored_workflow(trans, idstr) + return hda diff -r 666d744054ded20d79e3d2c6eb65012455de96b5 -r 98f724202d9d3cea035d7de04d89465bcf3092b1 lib/galaxy/webapps/galaxy/buildapp.py --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -107,6 +107,17 @@ _add_item_tags_controller( webapp, name_prefix="workflow_", path_prefix='/api/workflows/:workflow_id' ) + + _add_item_annotation_controller( webapp, + name_prefix="history_content_", + path_prefix='/api/histories/:history_id/contents/:history_content_id' ) + _add_item_annotation_controller( webapp, + name_prefix="history_", + path_prefix='/api/histories/:history_id' ) + _add_item_annotation_controller( webapp, + name_prefix="workflow_", + path_prefix='/api/workflows/:workflow_id' ) + webapp.api_mapper.resource( 'dataset', 'datasets', path_prefix='/api' ) webapp.api_mapper.resource_with_deleted( 'library', 'libraries', path_prefix='/api' ) webapp.api_mapper.resource( 'sample', 'samples', path_prefix='/api' ) @@ -193,6 +204,12 @@ conditions=dict(method=["GET"])) + +def _add_item_annotation_controller( webapp, name_prefix, path_prefix, **kwd ): + controller = "%sannotations" % name_prefix + name = "%sannotation" % name_prefix + webapp.api_mapper.resource(name, "annotation", path_prefix=path_prefix, controller=controller) + def wrap_in_middleware( app, global_conf, **local_conf ): """ Based on the configuration wrap `app` in a set of common and useful Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket