Esempio n. 1
0
    def GET(self):
        inputs = sh.inputs()
        assert inputs.has_key('model_name'), u'请指定需要裁剪的数据类型'
        assert inputs.has_key('model_id'), u'请指定需要裁剪的数据ID'
        assert inputs.has_key('crop'), u'请设置裁剪配置'
        item = sh.model(inputs.model_name).get(inputs.model_id)
        if not item or not item.has_key('Imageid'): return sh.redirectTo404()

        column_name, settings = sh.unquote(inputs.crop).partition(' ')[::2]
        inputs.crop_width, settings = settings.strip().partition(' ')[::2]

        preview_size, settings = settings.strip().partition(' ')[::2]
        inputs.preview_width, inputs.preview_height = preview_size.split(':')

        inputs.column_name = column_name
        inputs.crop_settings = settings
        inputs.image = item.image

        if item.get(column_name):
            inputs.crop = item.get(column_name)
        else:
            inputs.crop = '0 0 %s %s' % tuple(preview_size.split(':'))

        if len(inputs.crop.split()) == 4:
            x1, y1, x2, y2 = map(int, inputs.crop.split(' '))
            inputs.fx_crop = 'x1=%s;y1=%s;x2=%s;y2=%s;' % (x1, y1, x1 + x2,
                                                           y1 + y2)
        else:
            inputs.fx_crop = ''

        return sh.editor.CropImage(inputs)
Esempio n. 2
0
    def GET(self):
        inputs = sh.inputs()
        assert inputs.has_key('model_name'), u'请指定需要裁剪的数据类型'
        assert inputs.has_key('model_id'), u'请指定需要裁剪的数据ID'
        assert inputs.has_key('crop'), u'请设置裁剪配置'
        item = sh.model(inputs.model_name).get(inputs.model_id)
        if not item or not item.has_key('Imageid'): return sh.redirectTo404()

        column_name, settings = sh.unquote(inputs.crop).partition(' ')[::2]
        inputs.crop_width, settings = settings.strip().partition(' ')[::2]

        preview_size, settings = settings.strip().partition(' ')[::2]
        inputs.preview_width, inputs.preview_height = preview_size.split(':')

        inputs.column_name = column_name
        inputs.crop_settings = settings
        inputs.image = item.image

        if item.get(column_name):
            inputs.crop = item.get(column_name)
        else:
            inputs.crop = '0 0 %s %s' % tuple(preview_size.split(':'))

        if len(inputs.crop.split()) == 4:
            x1, y1, x2, y2 = map(int, inputs.crop.split(' '))
            inputs.fx_crop = 'x1=%s;y1=%s;x2=%s;y2=%s;' % (x1,y1,x1+x2,y1+y2)
        else:
            inputs.fx_crop = ''

        return sh.editor.CropImage(inputs)
Esempio n. 3
0
    def _getEnv(self, model, menu_config):
        inputs = sh.inputs()
        env = sh.storage(dict(paging=True))
        env.orderby = model.replaceAttr(menu_config.orderby  \
                if menu_config.orderby else '{$primary_key} desc')

        if inputs.get('where', ''):
            env.where = [sh.unquote(inputs.where)]

        if inputs.get('action', '') == 'search':
            where = []
            argvs = []
            for query in sh.splitAndStrip(inputs.query):
                where.append('('+ ' or '.join([c+' like %s' for c in menu_config.search]) +')')
                argvs += ['%'+query+'%'] * len(menu_config.search)
            env.where = [' and '.join(where)] + argvs

        return env
Esempio n. 4
0
    def _getEnv(self, model, menu_config):
        inputs = sh.inputs()
        env = sh.storage(dict(paging=True))
        env.orderby = model.replaceAttr(menu_config.orderby  \
                if menu_config.orderby else '{$primary_key} desc')

        if inputs.get('where', ''):
            env.where = [sh.unquote(inputs.where)]

        if inputs.get('action', '') == 'search':
            where = []
            argvs = []
            for query in sh.splitAndStrip(inputs.query):
                where.append(
                    '(' +
                    ' or '.join([c + ' like %s'
                                 for c in menu_config.search]) + ')')
                argvs += ['%' + query + '%'] * len(menu_config.search)
            env.where = [' and '.join(where)] + argvs

        return env