Revision 44f510e1 snf-astakos-app/astakos/im/management/commands/_common.py

b/snf-astakos-app/astakos/im/management/commands/_common.py
41 41
from django.core.exceptions import FieldError
42 42
from django.core.management import CommandError
43 43

  
44
from synnefo.util import units
44 45
from synnefo.lib.ordereddict import OrderedDict
45 46
from astakos.im.models import AstakosUser
47
from astakos.im.resources import get_resources
46 48

  
47 49
DEFAULT_CONTENT_TYPE = None
48 50

  
......
236 238
        return True
237 239

  
238 240

  
239
def show_quotas(qh_quotas, astakos_initial, info=None):
241
style_options = ', '.join(units.STYLES)
242

  
243

  
244
def check_style(style):
245
    if style not in units.STYLES:
246
        m = "Invalid unit style. Valid ones are %s." % style_options
247
        raise CommandError(m)
248

  
249

  
250
class ResourceDict(object):
251
    _object = None
252

  
253
    @classmethod
254
    def get(cls):
255
        if cls._object is None:
256
            cls._object = get_resources()
257
        return cls._object
258

  
259

  
260
def show_resource_value(number, resource, style):
261
    resource_dict = ResourceDict.get()
262
    unit = resource_dict[resource]['unit']
263
    return units.show(number, unit, style)
264

  
265

  
266
def show_quotas(qh_quotas, astakos_initial, info=None, style=None):
240 267
    labels = ('source', 'resource', 'base quota', 'total quota', 'usage')
241 268
    if info is not None:
242 269
        labels = ('uuid', 'email') + labels
......
251 278
            s_initial = h_initial.get(source) if h_initial else None
252 279
            for resource, values in source_quotas.iteritems():
253 280
                initial = s_initial.get(resource) if s_initial else None
254
                fields = (source, resource, initial,
255
                          values['limit'], values['usage'])
281
                initial = show_resource_value(initial, resource, style)
282
                limit = show_resource_value(values['limit'], resource, style)
283
                usage = show_resource_value(values['usage'], resource, style)
284
                fields = (source, resource, initial, limit, usage)
256 285
                if info is not None:
257 286
                    fields = (holder, email) + fields
258 287

  

Also available in: Unified diff