Пример #1
0
 def undelete_category( self, trans, **kwd ):
     params = util.Params( kwd )
     message = util.restore_text( params.get( 'message', ''  ) )
     status = params.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category( trans, category_id )
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add( category )
                 trans.sa_session.flush()
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % ( count, undeleted_categories )
     else:
         message = "No category ids received for undeleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Пример #2
0
 def undelete_category(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         undeleted_categories = ""
         for category_id in ids:
             category = suc.get_category(trans, category_id)
             if category.deleted:
                 category.deleted = False
                 trans.sa_session.add(category)
                 trans.sa_session.flush()
                 count += 1
                 undeleted_categories += " %s" % category.name
         message = "Undeleted %d categories: %s" % (count,
                                                    undeleted_categories)
     else:
         message = "No category ids received for undeleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #3
0
 def purge_category( self, trans, **kwd ):
     # This method should only be called for a Category that has previously been deleted.
     # Purging a deleted Category deletes all of the following from the database:
     # - RepoitoryCategoryAssociations where category_id == Category.id
     params = util.Params( kwd )
     message = util.restore_text( params.get( 'message', ''  ) )
     status = params.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         count = 0
         purged_categories = ""
         message = "Purged %d categories: " % len( ids )
         for category_id in ids:
             category = suc.get_category( trans, category_id )
             if category.deleted:
                 # Delete RepositoryCategoryAssociations
                 for rca in category.repositories:
                     trans.sa_session.delete( rca )
                 trans.sa_session.flush()
                 purged_categories += " %s " % category.name
         message = "Purged %d categories: %s" % ( count, purged_categories )
     else:
         message = "No category ids received for purging."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Пример #4
0
 def purge_category(self, trans, **kwd):
     # This method should only be called for a Category that has previously been deleted.
     # Purging a deleted Category deletes all of the following from the database:
     # - RepoitoryCategoryAssociations where category_id == Category.id
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         count = 0
         purged_categories = ""
         message = "Purged %d categories: " % len(ids)
         for category_id in ids:
             category = suc.get_category(trans, category_id)
             if category.deleted:
                 # Delete RepositoryCategoryAssociations
                 for rca in category.repositories:
                     trans.sa_session.delete(rca)
                 trans.sa_session.flush()
                 purged_categories += " %s " % category.name
         message = "Purged %d categories: %s" % (count, purged_categories)
     else:
         message = "No category ids received for purging."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #5
0
 def mark_category_deleted(self, trans, **kwd):
     # TODO: We should probably eliminate the Category.deleted column since it really makes no
     # sense to mark a category as deleted (category names and descriptions can be changed instead).
     # If we do this, and the following 2 methods can be eliminated.
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     id = kwd.get('id', None)
     if id:
         ids = util.listify(id)
         message = "Deleted %d categories: " % len(ids)
         for category_id in ids:
             category = suc.get_category(trans, category_id)
             category.deleted = True
             trans.sa_session.add(category)
             trans.sa_session.flush()
             message += " %s " % category.name
     else:
         message = "No category ids received for deleting."
         status = 'error'
     trans.response.send_redirect(
         web.url_for(controller='admin',
                     action='manage_categories',
                     message=util.sanitize_text(message),
                     status='done'))
Пример #6
0
 def edit_category(self, trans, **kwd):
     params = util.Params(kwd)
     message = util.restore_text(params.get('message', ''))
     status = params.get('status', 'done')
     id = params.get('id', None)
     if not id:
         message = "No category ids received for editing"
         trans.response.send_redirect(
             web.url_for(controller='admin',
                         action='manage_categories',
                         message=message,
                         status='error'))
     category = suc.get_category(trans, id)
     if params.get('edit_category_button', False):
         new_name = util.restore_text(params.get('name', '')).strip()
         new_description = util.restore_text(params.get('description',
                                                        '')).strip()
         if category.name != new_name or category.description != new_description:
             if not new_name:
                 message = 'Enter a valid name'
                 status = 'error'
             elif category.name != new_name and suc.get_category_by_name(
                     trans, name):
                 message = 'A category with that name already exists'
                 status = 'error'
             else:
                 category.name = new_name
                 category.description = new_description
                 trans.sa_session.add(category)
                 trans.sa_session.flush()
                 message = "The information has been saved for category '%s'" % (
                     category.name)
                 status = 'done'
                 return trans.response.send_redirect(
                     web.url_for(controller='admin',
                                 action='manage_categories',
                                 message=message,
                                 status=status))
     return trans.fill_template(
         '/webapps/community/category/edit_category.mako',
         category=category,
         message=message,
         status=status)
Пример #7
0
 def edit_category( self, trans, **kwd ):
     params = util.Params( kwd )
     message = util.restore_text( params.get( 'message', ''  ) )
     status = params.get( 'status', 'done' )
     id = params.get( 'id', None )
     if not id:
         message = "No category ids received for editing"
         trans.response.send_redirect( web.url_for( controller='admin',
                                                    action='manage_categories',
                                                    message=message,
                                                    status='error' ) )
     category = suc.get_category( trans, id )
     if params.get( 'edit_category_button', False ):
         new_name = util.restore_text( params.get( 'name', '' ) ).strip()
         new_description = util.restore_text( params.get( 'description', '' ) ).strip()
         if category.name != new_name or category.description != new_description:
             if not new_name:
                 message = 'Enter a valid name'
                 status = 'error'
             elif category.name != new_name and suc.get_category_by_name( trans, name ):
                 message = 'A category with that name already exists'
                 status = 'error'
             else:
                 category.name = new_name
                 category.description = new_description
                 trans.sa_session.add( category )
                 trans.sa_session.flush()
                 message = "The information has been saved for category '%s'" % ( category.name )
                 status = 'done'
                 return trans.response.send_redirect( web.url_for( controller='admin',
                                                                   action='manage_categories',
                                                                   message=message,
                                                                   status=status ) )
     return trans.fill_template( '/webapps/community/category/edit_category.mako',
                                 category=category,
                                 message=message,
                                 status=status )
Пример #8
0
 def mark_category_deleted( self, trans, **kwd ):
     # TODO: We should probably eliminate the Category.deleted column since it really makes no
     # sense to mark a category as deleted (category names and descriptions can be changed instead).
     # If we do this, and the following 2 methods can be eliminated.
     params = util.Params( kwd )
     message = util.restore_text( params.get( 'message', ''  ) )
     status = params.get( 'status', 'done' )
     id = kwd.get( 'id', None )
     if id:
         ids = util.listify( id )
         message = "Deleted %d categories: " % len( ids )
         for category_id in ids:
             category = suc.get_category( trans, category_id )
             category.deleted = True
             trans.sa_session.add( category )
             trans.sa_session.flush()
             message += " %s " % category.name
     else:
         message = "No category ids received for deleting."
         status = 'error'
     trans.response.send_redirect( web.url_for( controller='admin',
                                                action='manage_categories',
                                                message=util.sanitize_text( message ),
                                                status='done' ) )
Пример #9
0
 def browse_repositories( self, trans, **kwd ):
     # We add params to the keyword dict in this method in order to rename the param
     # with an "f-" prefix, simulating filtering by clicking a search link.  We have
     # to take this approach because the "-" character is illegal in HTTP requests.
     if 'operation' in kwd:
         operation = kwd['operation'].lower()
         if operation == "view_or_manage_repository":
             return trans.response.send_redirect( web.url_for( controller='repository',
                                                               action='browse_repositories',
                                                               **kwd ) )
         elif operation == "edit_repository":
             return trans.response.send_redirect( web.url_for( controller='repository',
                                                               action='edit_repository',
                                                               **kwd ) )
         elif operation == "repositories_by_user":
             # Eliminate the current filters if any exist.
             for k, v in kwd.items():
                 if k.startswith( 'f-' ):
                     del kwd[ k ]
             if 'user_id' in kwd:
                 user = suc.get_user( trans, kwd[ 'user_id' ] )
                 kwd[ 'f-email' ] = user.email
                 del kwd[ 'user_id' ]
             else:
                 # The received id is the repository id, so we need to get the id of the user
                 # that uploaded the repository.
                 repository_id = kwd.get( 'id', None )
                 repository = suc.get_repository_in_tool_shed( trans, repository_id )
                 kwd[ 'f-email' ] = repository.user.email
         elif operation == "repositories_by_category":
             # Eliminate the current filters if any exist.
             for k, v in kwd.items():
                 if k.startswith( 'f-' ):
                     del kwd[ k ]
             category_id = kwd.get( 'id', None )
             category = suc.get_category( trans, category_id )
             kwd[ 'f-Category.name' ] = category.name
         elif operation == "receive email alerts":
             if kwd[ 'id' ]:
                 kwd[ 'caller' ] = 'browse_repositories'
                 return trans.response.send_redirect( web.url_for( controller='repository',
                                                                   action='set_email_alerts',
                                                                   **kwd ) )
             else:
                 del kwd[ 'operation' ]
         elif operation == 'delete':
             return self.delete_repository( trans, **kwd )
         elif operation == "undelete":
             return self.undelete_repository( trans, **kwd )
     # The changeset_revision_select_field in the RepositoryGrid performs a refresh_on_change
     # which sends in request parameters like changeset_revison_1, changeset_revision_2, etc.  One
     # of the many select fields on the grid performed the refresh_on_change, so we loop through 
     # all of the received values to see which value is not the repository tip.  If we find it, we
     # know the refresh_on_change occurred, and we have the necessary repository id and change set
     # revision to pass on.
     for k, v in kwd.items():
         changset_revision_str = 'changeset_revision_'
         if k.startswith( changset_revision_str ):
             repository_id = trans.security.encode_id( int( k.lstrip( changset_revision_str ) ) )
             repository = suc.get_repository_in_tool_shed( trans, repository_id )
             if repository.tip( trans.app ) != v:
                 return trans.response.send_redirect( web.url_for( controller='repository',
                                                                   action='browse_repositories',
                                                                   operation='view_or_manage_repository',
                                                                   id=trans.security.encode_id( repository.id ),
                                                                   changeset_revision=v ) )
     # Render the list view
     return self.repository_grid( trans, **kwd )
Пример #10
0
 def browse_repositories(self, trans, **kwd):
     # We add params to the keyword dict in this method in order to rename the param
     # with an "f-" prefix, simulating filtering by clicking a search link.  We have
     # to take this approach because the "-" character is illegal in HTTP requests.
     if 'operation' in kwd:
         operation = kwd['operation'].lower()
         if operation == "view_or_manage_repository":
             return trans.response.send_redirect(
                 web.url_for(controller='repository',
                             action='browse_repositories',
                             **kwd))
         elif operation == "edit_repository":
             return trans.response.send_redirect(
                 web.url_for(controller='repository',
                             action='edit_repository',
                             **kwd))
         elif operation == "repositories_by_user":
             # Eliminate the current filters if any exist.
             for k, v in kwd.items():
                 if k.startswith('f-'):
                     del kwd[k]
             if 'user_id' in kwd:
                 user = suc.get_user(trans, kwd['user_id'])
                 kwd['f-email'] = user.email
                 del kwd['user_id']
             else:
                 # The received id is the repository id, so we need to get the id of the user
                 # that uploaded the repository.
                 repository_id = kwd.get('id', None)
                 repository = suc.get_repository_in_tool_shed(
                     trans, repository_id)
                 kwd['f-email'] = repository.user.email
         elif operation == "repositories_by_category":
             # Eliminate the current filters if any exist.
             for k, v in kwd.items():
                 if k.startswith('f-'):
                     del kwd[k]
             category_id = kwd.get('id', None)
             category = suc.get_category(trans, category_id)
             kwd['f-Category.name'] = category.name
         elif operation == "receive email alerts":
             if kwd['id']:
                 kwd['caller'] = 'browse_repositories'
                 return trans.response.send_redirect(
                     web.url_for(controller='repository',
                                 action='set_email_alerts',
                                 **kwd))
             else:
                 del kwd['operation']
         elif operation == 'delete':
             return self.delete_repository(trans, **kwd)
         elif operation == "undelete":
             return self.undelete_repository(trans, **kwd)
     # The changeset_revision_select_field in the RepositoryGrid performs a refresh_on_change
     # which sends in request parameters like changeset_revison_1, changeset_revision_2, etc.  One
     # of the many select fields on the grid performed the refresh_on_change, so we loop through
     # all of the received values to see which value is not the repository tip.  If we find it, we
     # know the refresh_on_change occurred, and we have the necessary repository id and change set
     # revision to pass on.
     for k, v in kwd.items():
         changset_revision_str = 'changeset_revision_'
         if k.startswith(changset_revision_str):
             repository_id = trans.security.encode_id(
                 int(k.lstrip(changset_revision_str)))
             repository = suc.get_repository_in_tool_shed(
                 trans, repository_id)
             if repository.tip(trans.app) != v:
                 return trans.response.send_redirect(
                     web.url_for(controller='repository',
                                 action='browse_repositories',
                                 operation='view_or_manage_repository',
                                 id=trans.security.encode_id(repository.id),
                                 changeset_revision=v))
     # Render the list view
     return self.repository_grid(trans, **kwd)