commit/galaxy-central: jgoecks: Create and use function for checking a slug's validity.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/b97bdb63115c/ changeset: b97bdb63115c user: jgoecks date: 2013-01-09 17:27:53 summary: Create and use function for checking a slug's validity. affected #: 3 files diff -r 757217fbae1981bc66d05076ab93dcbc92dca072 -r b97bdb63115cf50562e423ac165cffcdd5bb64e1 lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -28,8 +28,12 @@ # States for passing messages SUCCESS, INFO, WARNING, ERROR = "done", "info", "warning", "error" -# RE that tests for valid slug. -VALID_SLUG_RE = re.compile( "^[a-z0-9\-]+$" ) +def _is_valid_slug( slug ): + """ Returns true if slug is valid. """ + + VALID_SLUG_RE = re.compile( "^[a-z0-9\-]+$" ) + return VALID_SLUG_RE.match( slug ) + class BaseController( object ): """ @@ -186,6 +190,7 @@ self.type_extension = type_extension self.mimetype = mimetype self.display_in_upload = display_in_upload + # # -- Mixins for working with Galaxy objects. -- # @@ -210,6 +215,7 @@ raise ItemAccessibilityException( "%s is not accessible to the current user" % item.__class__.__name__, type='error' ) return item + class UsesHistoryDatasetAssociationMixin: """ Mixin for controllers that use HistoryDatasetAssociation objects. """ @@ -552,7 +558,7 @@ title_err = slug_err = "" if not title: title_err = "visualization name is required" - elif slug and not VALID_SLUG_RE.match( slug ): + elif slug and not _is_valid_slug( slug ): slug_err = "visualization identifier must consist of only lowercase letters, numbers, and the '-' character" elif slug and trans.sa_session.query( trans.model.Visualization ).filter_by( user=user, slug=slug, deleted=False ).first(): slug_err = "visualization identifier must be unique" @@ -1465,6 +1471,10 @@ """ Mixin for a controller that manages an item that can be shared. """ # -- Implemented methods. -- + + def _is_valid_slug( self, slug ): + """ Returns true if slug is valid. """ + return _is_valid_slug( slug ) @web.expose @web.require_login( "share Galaxy items" ) diff -r 757217fbae1981bc66d05076ab93dcbc92dca072 -r b97bdb63115cf50562e423ac165cffcdd5bb64e1 lib/galaxy/webapps/galaxy/controllers/page.py --- a/lib/galaxy/webapps/galaxy/controllers/page.py +++ b/lib/galaxy/webapps/galaxy/controllers/page.py @@ -2,7 +2,7 @@ from galaxy import model, web from galaxy.web import error, url_for from galaxy.model.item_attrs import UsesAnnotations, UsesItemRatings -from galaxy.web.base.controller import BaseUIController, SharableMixin, UsesHistoryMixin, UsesStoredWorkflowMixin, UsesVisualizationMixin, VALID_SLUG_RE +from galaxy.web.base.controller import BaseUIController, SharableMixin, UsesHistoryMixin, UsesStoredWorkflowMixin, UsesVisualizationMixin from galaxy.web.framework.helpers import time_ago, grids from galaxy import util from galaxy.util.sanitize_html import sanitize_html, _BaseHTMLProcessor @@ -342,7 +342,7 @@ page_title_err = "Page name is required" elif not page_slug: page_slug_err = "Page id is required" - elif not VALID_SLUG_RE.match( page_slug ): + elif not self._is_valid_slug( page_slug ): page_slug_err = "Page identifier must consist of only lowercase letters, numbers, and the '-' character" elif trans.sa_session.query( model.Page ).filter_by( user=user, slug=page_slug, deleted=False ).first(): page_slug_err = "Page id must be unique" @@ -398,7 +398,7 @@ page_title_err = "Page name is required" elif not page_slug: page_slug_err = "Page id is required" - elif not VALID_SLUG_RE.match( page_slug ): + elif not self._is_valid_slug( page_slug ): page_slug_err = "Page identifier must consist of only lowercase letters, numbers, and the '-' character" elif page_slug != page.slug and trans.sa_session.query( model.Page ).filter_by( user=user, slug=page_slug, deleted=False ).first(): page_slug_err = "Page id must be unique" diff -r 757217fbae1981bc66d05076ab93dcbc92dca072 -r b97bdb63115cf50562e423ac165cffcdd5bb64e1 lib/galaxy/webapps/galaxy/controllers/visualization.py --- a/lib/galaxy/webapps/galaxy/controllers/visualization.py +++ b/lib/galaxy/webapps/galaxy/controllers/visualization.py @@ -3,7 +3,7 @@ from sqlalchemy import desc, or_, and_ from galaxy import model, web from galaxy.model.item_attrs import UsesAnnotations, UsesItemRatings -from galaxy.web.base.controller import BaseUIController, SharableMixin, UsesVisualizationMixin, VALID_SLUG_RE +from galaxy.web.base.controller import BaseUIController, SharableMixin, UsesVisualizationMixin from galaxy.web.framework.helpers import time_ago, grids, iff from galaxy import util from galaxy.util.json import from_json_string @@ -636,7 +636,7 @@ visualization_title_err = "Visualization name is required" elif not visualization_slug: visualization_slug_err = "Visualization id is required" - elif not VALID_SLUG_RE.match( visualization_slug ): + elif not self._is_valid_slug( visualization_slug ): visualization_slug_err = "Visualization identifier must consist of only lowercase letters, numbers, and the '-' character" elif visualization_slug != visualization.slug and trans.sa_session.query( model.Visualization ).filter_by( user=visualization.user, slug=visualization_slug, deleted=False ).first(): visualization_slug_err = "Visualization id must be unique" 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