Commit 03e5ef16 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Change astakos show commands

* rename `invitation-details` command to 
`invitation-show` to conform with the rest 
synnefo show commands
* Enable the --output-format option (by changing 
them to inherit by `synnefo.webproject.management.commands.SynnefoCommand`
instead
* print the output using
`synnefo.webproject.management.utils.pprint_table` 
parent fe7e2b18
......@@ -31,15 +31,16 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.models import Invitation
from synnefo.webproject.management.commands import SynnefoCommand
from ._common import format
from synnefo.webproject.management import utils
class Command(BaseCommand):
args = "<invitation ID>"
class Command(SynnefoCommand):
args = "<invitation ID or code>"
help = "Show invitation info"
def handle(self, *args, **options):
......@@ -49,7 +50,10 @@ class Command(BaseCommand):
try:
invitation = Invitation.objects.get(id=int(args[0]))
except Invitation.DoesNotExist:
raise CommandError("Unknown invitation id '%s'" % (args[0],))
try:
invitation = Invitation.objects.get(code=args[0])
except Invitation.DoesNotExist:
raise CommandError("Unknown invitation id '%s'" % (args[0],))
kv = {
'id': invitation.id,
......@@ -63,6 +67,5 @@ class Command(BaseCommand):
'invitater email': invitation.inviter.email,
}
for key, val in sorted(kv.items()):
line = '%s: %s\n' % (key.rjust(18), format(val))
self.stdout.write(line)
utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
options["output_format"], vertical=True)
......@@ -32,15 +32,15 @@
# or implied, of GRNET S.A.
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from synnefo.lib.ordereddict import OrderedDict
from synnefo.webproject.management.commands import SynnefoCommand
from synnefo.webproject.management import utils
from astakos.im.models import Chain, ProjectApplication
from ._common import format
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<id or name>"
help = """
Show project details.
......@@ -52,7 +52,7 @@ class Command(BaseCommand):
contains the given string
"""
option_list = BaseCommand.option_list + (
option_list = SynnefoCommand.option_list + (
make_option('--app',
action='store_true',
dest='app',
......@@ -63,17 +63,17 @@ class Command(BaseCommand):
action='store_true',
dest='pending',
default=False,
help=("For a given project, show also pending modifications "
help=("For a given project, show also pending modifications"
"(applications), if any")
),
)
)
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("Please provide project ID or name")
show_pending = bool(options['pending'])
search_apps = options['app']
search_apps = options['app']
name_or_id = args[0]
is_id = name_or_id.isdigit()
......@@ -93,13 +93,8 @@ class Command(BaseCommand):
raise CommandError(msg)
for info in infolist:
self.show_info(info)
def show_info(self, info):
for key, val in info.items():
line = '%s: %s\n' % (key.rjust(22), format(val))
self.stdout.write(line)
self.stdout.write('\n')
utils.pprint_table(self.stdout, [info.values()], info.keys(),
options["output_format"], vertical=True)
def app_info(name_or_id, is_id):
......@@ -111,6 +106,7 @@ def app_info(name_or_id, is_id):
except ProjectApplication.DoesNotExist:
return []
def get_chains(name_or_id, is_id):
if is_id:
try:
......@@ -120,6 +116,7 @@ def get_chains(name_or_id, is_id):
else:
return Chain.objects.search_by_name(name_or_id)
def collect_info(chains, pending):
states = [chain.full_state() for chain in chains]
......@@ -128,6 +125,7 @@ def collect_info(chains, pending):
infolist += (chain_fields(state, pending))
return infolist
def chain_fields((s, project, app), request=False):
l = []
if project:
......@@ -138,28 +136,29 @@ def chain_fields((s, project, app), request=False):
l = [app_fields(app)]
return l
def app_fields(app):
mem_limit = app.limit_on_members_number
mem_limit_show = mem_limit if mem_limit is not None else "unlimited"
d = OrderedDict([
('project id', app.chain),
('application id', app.id),
('name', app.name),
('status', app.state_display()),
('owner', app.owner),
('applicant', app.applicant),
('homepage', app.homepage),
('description', app.description),
('comments for review', app.comments),
('request issue date', app.issue_date),
('request start date', app.start_date),
('request end date', app.end_date),
('resources', app.resource_policies),
('join policy', app.member_join_policy_display),
('leave policy', app.member_leave_policy_display),
('max members', mem_limit_show),
])
('project id', app.chain),
('application id', app.id),
('name', app.name),
('status', app.state_display()),
('owner', app.owner),
('applicant', app.applicant),
('homepage', app.homepage),
('description', app.description),
('comments for review', app.comments),
('request issue date', app.issue_date),
('request start date', app.start_date),
('request end date', app.end_date),
('resources', app.resource_policies),
('join policy', app.member_join_policy_display),
('leave policy', app.member_leave_policy_display),
('max members', mem_limit_show),
])
return d
......@@ -168,11 +167,11 @@ def project_fields(s, project, last_app):
app = project.application
d = OrderedDict([
('project id', project.id),
('application id', app.id),
('name', app.name),
('status', Chain.state_display(s)),
])
('project id', project.id),
('application id', app.id),
('name', app.name),
('status', Chain.state_display(s)),
])
if s in Chain.PENDING_STATES:
d.update([('pending application', last_app.id)])
......@@ -200,10 +199,10 @@ def project_fields(s, project, last_app):
('leave policy', app.member_leave_policy_display),
('max members', mem_limit_show),
('total members', project.members_count()),
])
])
memberships = project.projectmembership_set
accepted = [str(m.person) for m in memberships.any_accepted()]
accepted = [str(m.person) for m in memberships.any_accepted()]
requested = [str(m.person) for m in memberships.requested()]
suspended = [str(m.person) for m in memberships.suspended()]
......
......@@ -31,17 +31,15 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.models import AuthProviderPolicyProfile as Profile
from synnefo.lib.ordereddict import OrderedDict
from synnefo.webproject.management.commands import SynnefoCommand
from synnefo.webproject.management import utils
from ._common import format
import uuid
class Command(BaseCommand):
class Command(SynnefoCommand):
args = "<profile_name>"
help = "Show authentication provider profile details"
......@@ -65,5 +63,5 @@ class Command(BaseCommand):
('users', profile.users.all())
])
self.stdout.write(format(kv))
self.stdout.write('\n')
utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
options["output_format"], vertical=True)
......@@ -31,19 +31,20 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import CommandError
from astakos.im.models import AstakosUser, get_latest_terms
from astakos.im.util import model_to_dict
from synnefo.lib.ordereddict import OrderedDict
from synnefo.webproject.management.commands import SynnefoCommand
from synnefo.webproject.management import utils
from ._common import format
import uuid
class Command(BaseCommand):
args = "<user ID or email>"
class Command(SynnefoCommand):
args = "<user ID or email or uuid>"
help = "Show user info"
def handle(self, *args, **options):
......@@ -115,5 +116,5 @@ class Command(BaseCommand):
if has_signed_terms:
kv['date_signed_terms'] = user.date_signed_terms
self.stdout.write(format(kv))
self.stdout.write('\n')
utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
options["output_format"], vertical=True)
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