Commit c0aad919 authored by Flavio TARSETTI's avatar Flavio TARSETTI

Merge branch 'command_to_print_db_object_information' into 'master'

Implement database access information print command

See merge request !298
parents f7ed9c32 c1c4b01d
Pipeline #32481 passed with stages
in 21 minutes and 52 seconds
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import logging
from django.core.management.base import BaseCommand
from ...models import Database
logger = logging.getLogger("beat.web")
class Command(BaseCommand):
help = "Prints the list of databases with access level and user information"
def handle(self, *ignored, **options):
# Setup this command's logging level
global logger
verbosity = int(options["verbosity"])
if verbosity >= 1:
if verbosity == 1:
logger.setLevel(logging.INFO)
elif verbosity >= 2:
logger.setLevel(logging.DEBUG)
self.stdout.write("name, access, user")
for database in Database.objects.all():
db_info = "{}, {}".format(
database.fullname(), database.get_sharing_display()
)
for user in [
"{}: {} {}".format(user.username, user.first_name, user.last_name)
for user in database.all_shared_with_users()
]:
self.stdout.write("{}, {}".format(db_info, user))
else:
self.stdout.write(db_info)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment