Commit 7e778bf4 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Cleanup management commands' common file

parent 2a7b5af5
...@@ -59,48 +59,6 @@ def get_user(email_or_id, **kwargs): ...@@ -59,48 +59,6 @@ def get_user(email_or_id, **kwargs):
return None return None
def format_bool(b):
return 'YES' if b else 'NO'
def format_date(d):
if not d:
return ''
if d < datetime.now():
return timesince(d) + ' ago'
else:
return 'in ' + timeuntil(d)
def format_dict(d, level=1, ident=22):
iteritems = d.iteritems()
if not isinstance(d, OrderedDict):
iteritems = sorted(iteritems)
l = ['%s: %s\n' % (k.rjust(level*ident), format(v, level+1))
for k, v in iteritems]
l.insert(0, '\n')
return ''.join(l)
def format_set(s):
return list(s)
def format(obj, level=1, ident=22):
if isinstance(obj, bool):
return format_bool(obj)
elif isinstance(obj, datetime):
return format_date(obj)
elif isinstance(obj, dict):
return format_dict(obj, level, ident)
elif isinstance(obj, set):
return format_set(obj)
else:
return obj
def get_astakosuser_content_type(): def get_astakosuser_content_type():
try: try:
return ContentType.objects.get(app_label='im', return ContentType.objects.get(app_label='im',
...@@ -159,63 +117,6 @@ def remove_group_permission(group, pname): ...@@ -159,63 +117,6 @@ def remove_group_permission(group, pname):
return -1 return -1
def shortened(s, limit, suffix=True):
length = len(s)
if length <= limit:
return s
else:
display = limit - 2
if suffix:
return '..' + s[-display:]
else:
return s[:display] + '..'
# Copied from snf-cyclades-app/synnefo/management/common.py
# It could be moved to snf-common
def filter_results(objects, filter_by):
filter_list = filter_by.split(",")
filter_dict = {}
exclude_dict = {}
def map_field_type(query):
def fix_bool(val):
if val.lower() in ("yes", "true", "t"):
return True
if val.lower() in ("no", "false", "f"):
return False
return val
if "!=" in query:
key, val = query.split("!=")
exclude_dict[key] = fix_bool(val)
return
OP_MAP = {
">=": "__gte",
"=>": "__gte",
">": "__gt",
"<=": "__lte",
"=<": "__lte",
"<": "__lt",
"=": "",
}
for op, new_op in OP_MAP.items():
if op in query:
key, val = query.split(op)
filter_dict[key + new_op] = fix_bool(val)
return
map(lambda x: map_field_type(x), filter_list)
try:
objects = objects.filter(**filter_dict)
return objects.exclude(**exclude_dict)
except FieldError as e:
raise CommandError(e)
except Exception as e:
raise CommandError("Can not filter results: %s" % e)
def is_uuid(s): def is_uuid(s):
if s is None: if s is None:
return False return False
......
...@@ -41,7 +41,7 @@ from synnefo.lib.ordereddict import OrderedDict ...@@ -41,7 +41,7 @@ from synnefo.lib.ordereddict import OrderedDict
from synnefo.webproject.management.commands import SynnefoCommand from synnefo.webproject.management.commands import SynnefoCommand
from synnefo.webproject.management import utils from synnefo.webproject.management import utils
from ._common import format, show_quotas, style_options, check_style from ._common import show_quotas, style_options, check_style
import uuid import uuid
...@@ -106,7 +106,6 @@ class Command(SynnefoCommand): ...@@ -106,7 +106,6 @@ class Command(SynnefoCommand):
('invitation level', user.level), ('invitation level', user.level),
('providers', user.auth_providers_display), ('providers', user.auth_providers_display),
('verified', user.is_verified), ('verified', user.is_verified),
('has credits', format(user.has_credits)),
('groups', [elem.name for elem in user.groups.all()]), ('groups', [elem.name for elem in user.groups.all()]),
('permissions', [elem.codename ('permissions', [elem.codename
for elem in user.user_permissions.all()]), for elem in user.user_permissions.all()]),
......
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