コード例 #1
0
ファイル: views.py プロジェクト: woerwin/LuoYunCloud
    def chart_data(self, what=None):
        if not what: return

        ud = self._get_data()
        if not ud: return

        profile = self.current_user.profile

        d = { 'subcaption': self.trans(_("TOTAL: ")),
              'name1': self.trans(_("Used")),
              'name2': self.trans(_("Unused")) }
        number_suffix = ''

        if what == 'cpu':
            caption = self.trans(_("CPU USED INFO"))
            total = '%s CPU' % profile.cpus
            value1 = ud['USED_CPU']
            value2 = profile.cpus - ud['USED_CPU']
            number_suffix = self.trans(_("core"))
        elif what == 'memory':
            caption = self.trans(_("MOMORY USED INFO"))
            total = human_size(profile.memory*1024*1024)
            value1 = ud['USED_MEMORY']
            value2 = profile.memory - ud['USED_MEMORY']
            number_suffix = "M"
        elif what == 'instance':
            caption = self.trans(_("INSTANCE USED INFO"))
            total = profile.instances
            value1 = ud['USED_INSTANCE']
            value2 = profile.instances - ud['USED_INSTANCE']
        elif what == 'storage':
            caption = self.trans(_("STORAGE USED INFO"))
            total = '%s G' % profile.storage
            value1 = ud['USED_STORAGE']
            value2 = profile.storage - ud['USED_STORAGE']
            number_suffix = "G"
        else:
            return

        d.update({ 'caption': caption, 'total': total,
                   'value1': value1, 'value2': value2,
                   'number_suffix': number_suffix })

        T = '<graph caption="%(caption)s" \
subCaption="%(subcaption)s %(total)s" \
showNames="1" bgColor="F4F8FC" decimalPrecision="0" \
formatNumberScale="0" baseFontSize="16" \
numberSuffix="%(number_suffix)s">\
<set name="%(name1)s" value="%(value1)s" color="FC0101" />\
<set name="%(name2)s" value="%(value2)s" color="AFD8F8" /></graph>'

        return T % d
コード例 #2
0
ファイル: views.py プロジェクト: woerwin/LuoYunCloud
    def chart_data(self, what=None):
        if not what: return

        ud = self._get_data()
        if not ud: return

        profile = self.current_user.profile

        d = { 'subcaption': self.trans(_("TOTAL: ")),
              'name1': self.trans(_("Used")),
              'name2': self.trans(_("Unused")) }
        number_suffix = ''

        if what == 'cpu':
            caption = self.trans(_("CPU USED INFO"))
            total = '%s CPU' % ud['TOTAL_CPU']
            value1 = ud['USED_CPU']
            value2 = ud['TOTAL_CPU'] - ud['USED_CPU']
            number_suffix = self.trans(_("core"))
        elif what == 'memory':
            caption = self.trans(_("MOMORY USED INFO"))
            total = human_size(ud['TOTAL_MEMORY']*1024)
            value1 = ud['USED_MEMORY']
            value2 = ud['TOTAL_MEMORY'] - ud['USED_MEMORY']
            number_suffix = "M"
        else:
            return

        d.update({ 'caption': caption, 'total': total,
                   'value1': value1, 'value2': value2,
                   'number_suffix': number_suffix })

        T = '<graph caption="%(caption)s" \
subCaption="%(subcaption)s %(total)s" \
showNames="1" bgColor="F4F8FC" decimalPrecision="0" \
formatNumberScale="0" baseFontSize="16" \
numberSuffix="%(number_suffix)s">\
<set name="%(name1)s" value="%(value1)s" color="FC0101" />\
<set name="%(name2)s" value="%(value2)s" color="AFD8F8" /></graph>'

        return T % d
コード例 #3
0
class AvatarEdit(LyRequestHandler):

    @authenticated
    def get(self):
        form = AvatarEditForm(self)
        d = { 'title': self.trans(_('Change my avatar')),
              'form': form }

        self.render( 'account/avatar_edit.html', **d )


    @authenticated
    def post(self):
        # Save logo file
        form = AvatarEditForm(self)

        if self.request.files:
            r = self.save_avatar()
            if r:
                form.avatar.errors = [ r ] # TODO: a tuple
            else:
                url = self.reverse_url('account:index')
                return self.redirect( url )

        d = { 'title': self.trans(_('Change my avatar')),
              'form': form }

        self.render( 'account/avatar_edit.html', **d )


    def save_avatar(self):

        homedir = self.current_user.homedir
        if not os.path.exists(homedir):
            try:
                os.makedirs(homedir)
            except Exception, e:
                return self.trans(_('Create user home dir "%(dir)s" failed: %(emsg)s')) % {
                    'dir': homedir, 'emsg': e }

        max_size = settings.USER_AVATAR_MAXSIZE
        avatar_name = settings.USER_AVATAR_NAME

        for f in self.request.files['avatar']:

            if len(f['body']) > max_size:
                return self.trans(_('Avatar file must smaller than %s !')) % human_size(max_size)

            tf = tempfile.NamedTemporaryFile()
            tf.write(f['body'])
            tf.seek(0)

            try:
                img = Image.open( tf.name )

            except Exception, e:
                return self.trans(_('Open %(filename)s failed: %(emsg)s , is it a picture ?')) % {
                    'filename': f.get('filename'), 'emsg': e }

            try:
                img.save(self.current_user.avatar_orig_path)
                img.thumbnail(settings.USER_AVATAR_THUM_SIZE, resample=1)
                img.save(self.current_user.avatar_path)
                img.thumbnail(settings.USER_AVATAR_MINI_THUM_SIZE, resample=1)
                img.save(self.current_user.avatar_mini_path)
                tf.close()

            except Exception, e:
                return self.trans(_('Save %(filename)s failed: %(emsg)s')) % {
                    'filename': f.get('filename'), 'emsg': e }
コード例 #4
0
ファイル: models.py プロジェクト: cloudcache/LuoYunCloud
 def vmemory_human(self):
     try:
         return human_size(self.vmemory*1024)
     except:
         return ''
コード例 #5
0
ファイル: views.py プロジェクト: woerwin/LuoYunCloud
    def save_logo(self, appliance):

        if not os.path.exists(appliance.logodir):
            try:
                os.makedirs(appliance.logodir)
            except Exception, e:
                return self.trans(_('create appliance logo dir "%(dir)s" failed: %(emsg)s')) % {
                    'dir': appliance.logodir, 'emsg': e }

        max_size = settings.APPLIANCE_LOGO_MAXSIZE
        logoname = settings.APPLIANCE_LOGO_NAME

        for f in self.request.files['logo']:

            if len(f['body']) > max_size:
                return self.trans(_('Picture must smaller than %s !')) % human_size(max_size)

            tf = tempfile.NamedTemporaryFile()
            tf.write(f['body'])
            tf.seek(0)

            try:
                img = Image.open(tf.name)
            except Exception, emsg:
                return self.trans(_('Open %(filename)s failed: %(emsg)s , is it a picture ?')) % {
                    'filename': f.get('filename'), 'emsg': emsg }

            try:
                # can convert image type
                img.save(appliance.logopath)
 
コード例 #6
0
ファイル: views.py プロジェクト: woerwin/LuoYunCloud
            except Exception, e:
                return self.trans(
                    _('create appliance logo dir "%(dir)s" failed: %(emsg)s')
                ) % {
                    'dir': appliance.logodir,
                    'emsg': e
                }

        max_size = settings.APPLIANCE_LOGO_MAXSIZE
        logoname = settings.APPLIANCE_LOGO_NAME

        for f in self.request.files['logo']:

            if len(f['body']) > max_size:
                return self.trans(
                    _('Picture must smaller than %s !')) % human_size(max_size)

            tf = tempfile.NamedTemporaryFile()
            tf.write(f['body'])
            tf.seek(0)

            try:
                img = Image.open(tf.name)
            except Exception, emsg:
                return self.trans(
                    _('Open %(filename)s failed: %(emsg)s , is it a picture ?')
                ) % {
                    'filename': f.get('filename'),
                    'emsg': emsg
                }
コード例 #7
0
ファイル: models.py プロジェクト: woerwin/LuoYunCloud
 def vmemory_human(self):
     try:
         return human_size(self.vmemory * 1024)
     except:
         return ''