"""
Created on Jun 17, 2016

@author: noob
"""
# -*- coding: utf-8 -*-
from django import template

register = template.Library()


@register.filter(name='sexy_bytes')
def sexy_bytes(number):
    prefix = ''

    if number < 1024:
        pass
    elif number > 1024 ** 5:
        prefix = 'P'
        number /= 1024 ** 5
    elif number > 1024 ** 4:
        prefix = 'T'
        number /= 1024 ** 4.
    elif number > 1024 ** 3:
        prefix = 'G'
        number /= 1024 ** 3
    elif number > 1024 ** 2:
        prefix = 'M'
        number /= 1024 ** 2
    elif number > 1024 ** 1:
        prefix = 'K'
        number /= 1024 ** 1

    return '{} {}b'.format(number, prefix)
