示例#1
0
def generate_url_for_picture(model, name, id, value):
    url = ''

    if isinstance(value, (tuple, list)) and len(value)==2:
        type, data = value
    else:
        type, data = None, value
        
    if data:
        if type == 'stock':
            stock, size = data
            url =  icons.get_icon(stock)
        else:
            key = "%s,%s:%s@%s" % (model, id or 0, name, time.time())
            hashkey = str(hash(key))
            fname = get_temp_file(hash=hashkey)
            tmp = open(fname, "w")
            try:
                tmp.write(base64.decodestring(data))
            finally:
                tmp.close()
             
            url = tools.url("/image/get_picture", hash=hashkey)
    else:
        url = tools.url("/static/images/blank.gif")

    return url
示例#2
0
def generate_url_for_picture(model, name, id, value):
    url = ''

    if isinstance(value, (tuple, list)) and len(value) == 2:
        type, data = value
    else:
        type, data = None, value

    if data:
        if type == 'stock':
            stock, size = data
            url = icons.get_icon(stock)
        else:
            key = "%s,%s:%s@%s" % (model, id or 0, name, time.time())
            hashkey = str(hash(key))
            fname = get_temp_file(hash=hashkey)
            tmp = open(fname, "w")
            try:
                tmp.write(base64.decodestring(data))
            finally:
                tmp.close()

            url = tools.url("/image/get_picture", hash=hashkey)
    else:
        url = tools.url("/static/images/blank.gif")

    return url
示例#3
0
 def get_link(self):
     m2o_link = int(self.attrs.get('link', 1))
     
     c_context = self.attrs.get('context',{})
     
     if m2o_link == 1:
         if c_context:
             return tools.url('/form/view', model=self.attrs['relation'], id=(self.value or False) and self.value[0],context=c_context)
         else:
             return tools.url('/form/view', model=self.attrs['relation'], id=(self.value or False) and self.value[0])
     else:
         return None
示例#4
0
 def update_params(self, d):
     super(DTLink, self).update_params(d)
     
     lang = get_locale()
     link = "calendar/lang/calendar-%s.js" % lang
     
     if os.path.exists(tools.find_resource("openerp", "static", link)):
         d.link = tools.url(["/cp_widgets/openerp", link])
     else:
         lang = lang.split('_')[0]
         link = "calendar/lang/calendar-%s.js" % lang
         if os.path.exists(tools.find_resource("openerp", "static", link)):
             d.link = tools.url(["/cp_widgets/openerp", link])
示例#5
0
 def update_params(self, d):
     super(DTLink, self).update_params(d)
     
     lang = get_locale()
     link = "calendar/lang/calendar-%s.js" % lang
     
     if os.path.exists(tools.find_resource("openerp", "static", link)):
         d.link = tools.url(["/cp_widgets/openerp", link])
     else:
         lang = lang.split('_')[0]
         link = "calendar/lang/calendar-%s.js" % lang
         if os.path.exists(tools.find_resource("openerp", "static", link)):
             d.link = tools.url(["/cp_widgets/openerp", link])
示例#6
0
    def __init__(self, **attrs):
        icon = attrs.get('name')
        attrs['name'] = attrs.get('name', 'Image').replace("-","_")

        super(Image, self).__init__(**attrs)

        self.filename = attrs.get('filename', '')
        if getattr(self,'size', ''):
            self.img_size = True
        else:
            self.img_size = False
        if 'widget' in attrs:
            self.stock = False
            self.field = self.name.split('/')[-1]
            if self.id:
                self.src = tools.url('/image/get_image', model=self.model, id=self.id, field=self.field)
            else:
                self.src = attrs.get('value')
            self.height = attrs.get('img_height', attrs.get('height', 160))
            self.width = attrs.get('img_width', attrs.get('width', 200))
            self.validator = validators.Binary()
        else:
            self.src =  icons.get_icon(icon)
        
        if self.readonly:
            self.editable = False
示例#7
0
    def __init__(self, **attrs):
        icon = attrs.get('name')
        attrs['name'] = attrs.get('name', 'Image').replace("-", "_")

        super(Image, self).__init__(**attrs)

        self.filename = attrs.get('filename', '')
        if getattr(self, 'size', ''):
            self.img_size = True
        else:
            self.img_size = False
        if 'widget' in attrs:
            self.stock = False
            self.field = self.name.split('/')[-1]
            if self.id:
                self.src = tools.url('/image/get_image',
                                     model=self.model,
                                     id=self.id,
                                     field=self.field)
            else:
                self.src = attrs.get('value')
            self.height = attrs.get('img_height', attrs.get('height', 160))
            self.width = attrs.get('img_width', attrs.get('width', 200))
            self.validator = validators.Binary()
        else:
            self.src = icons.get_icon(icon)

        if self.readonly:
            self.editable = False
示例#8
0
    def get_link(self):
        m2o_link = int(self.attrs.get('link', 1))

        if m2o_link == 1:
            return tools.url('/form/view',
                             model=self.attrs['relation'],
                             id=(self.value or False) and self.value[0])
        else:
            return None
示例#9
0
    def login(self, db=None, user=None, password=None, style=None, location=None, **kw):

        location = url(location or '/', kw or {})

        if db and user and user.startswith("anonymous"):
            if rpc.session.login(db, user, password):
                raise redirect(location)

        if cherrypy.request.params.get('tg_format') == 'json':
            if rpc.session.login(db, user, password) > 0:
                return dict(result=1)
            return dict(result=0)

        if style in ('ajax', 'ajax_small'):
            return dict(db=db, user=user, password=password, location=location, 
                    style=style, cp_template="templates/login_ajax.mako")

        return tiny_login(target=location, db=db, user=user, password=password, action="login")
示例#10
0
    def data(self, ids, model, fields, field_parent=None, icon_name=None, domain=[], context={}, sort_by=None, sort_order="asc"):

        ids = ids or []

        if isinstance(ids, basestring):
            ids = [int(id) for id in ids.split(',')]

        if isinstance(fields, basestring):
            fields = eval(fields)

        if isinstance(domain, basestring):
            domain = eval(domain)

        if isinstance(context, basestring):
            context = eval(context)

        if field_parent and field_parent not in fields:
            fields.append(field_parent)

        proxy = rpc.RPCProxy(model)

        ctx = context or {}
        ctx.update(rpc.session.context.copy())

        if icon_name:
            fields.append(icon_name)

        fields_info = cache.fields_get(model, fields, ctx)
        result = proxy.read(ids, fields, ctx)
        
        if sort_by:
            result.sort(lambda a,b: self.sort_callback(a, b, sort_by, sort_order, type=fields_info[sort_by]['type']))

        # formate the data
        for field in fields:

            if fields_info[field]['type'] in ('integer'):
                for x in result:
                    if x[field]:
                        x[field] = '%s'%(x[field])
            
            if fields_info[field]['type'] in ('float'):
                for x in result:
                    if x[field]:
                        x[field] = '%.02f'%(round(x[field], 2))

            if fields_info[field]['type'] in ('date',):
                for x in result:
                    if x[field]:
                        date = time.strptime(x[field], DT_FORMAT)
                        x[field] = time.strftime('%x', date)

            if fields_info[field]['type'] in ('datetime',):
                for x in result:
                    if x[field]:
                        date = time.strptime(x[field], DHM_FORMAT)
                        x[field] = time.strftime('%x %H:%M:%S', date)

            if fields_info[field]['type'] in ('one2one', 'many2one'):
                for x in result:
                    if x[field]:
                        x[field] = x[field][1]

            if fields_info[field]['type'] in ('selection'):
                for x in result:
                    if x[field]:
                        x[field] = dict(fields_info[field]['selection']).get(x[field], '')

        records = []
        for item in result:

            # empty string instead of bool and None
            for k, v in item.items():
                if v==None or (v==False and type(v)==bool):
                    item[k] = ''

            record = {}

            record['id'] = item.pop('id')
            record['action'] = url('/tree/open', model=model, id=record['id'])
            record['target'] = None

            record['icon'] = None

            if icon_name and item.get(icon_name):
                icon = item.pop(icon_name)
                record['icon'] = icons.get_icon(icon)

                if icon == 'STOCK_OPEN':
                    record['action'] = None
                    record['target'] = None

            record['children'] = []

            if field_parent and field_parent in item:
                record['children'] = item.pop(field_parent) or None

            record['items'] = item

            records += [record]

        return dict(records=records)
示例#11
0
 def update_params(self, d):
     super(JSCatelog, self).update_params(d)
     lang = _get_locale()
     if i18n.is_locale_supported(lang):
         d["link"] = tools.url("/static/javascript/i18n/%s.js" % (lang))
示例#12
0
    def data(self, ids, model, fields, field_parent=None, icon_name=None, domain=[], context={}, sort_by=None, sort_order="asc"):

        ids = ids or []

        if isinstance(ids, basestring):
            ids = [int(id) for id in ids.split(',')]

        if isinstance(fields, basestring):
            fields = eval(fields)

        if isinstance(domain, basestring):
            domain = eval(domain)

        if isinstance(context, basestring):
            context = eval(context)

        if field_parent and field_parent not in fields:
            fields.append(field_parent)

        proxy = rpc.RPCProxy(model)

        ctx = context or {}
        ctx.update(rpc.session.context.copy())

        if icon_name:
            fields.append(icon_name)

        fields_info = cache.fields_get(model, fields, ctx)
        result = proxy.read(ids, fields, ctx)
        
        if sort_by:
            result.sort(lambda a,b: self.sort_callback(a, b, sort_by, sort_order, type=fields_info[sort_by]['type']))

        # formate the data
        for field in fields:

            if fields_info[field]['type'] in ('integer'):
                for x in result:
                    if x[field]:
                        x[field] = '%s'%(x[field])
            
            if fields_info[field]['type'] in ('float'):
                for x in result:
                    if x[field]:
                        x[field] = '%.02f'%(round(x[field], 2))

            if fields_info[field]['type'] in ('date',):
                for x in result:
                    if x[field]:
                        date = time.strptime(x[field], DT_FORMAT)
                        x[field] = time.strftime('%x', date)

            if fields_info[field]['type'] in ('datetime',):
                for x in result:
                    if x[field]:
                        date = time.strptime(x[field], DHM_FORMAT)
                        x[field] = time.strftime('%x %H:%M:%S', date)

            if fields_info[field]['type'] in ('one2one', 'many2one'):
                for x in result:
                    if x[field]:
                        x[field] = x[field][1]

            if fields_info[field]['type'] in ('selection'):
                for x in result:
                    if x[field]:
                        x[field] = dict(fields_info[field]['selection']).get(x[field], '')

        records = []
        for item in result:

            # empty string instead of bool and None
            for k, v in item.items():
                if v==None or (v==False and type(v)==bool):
                    item[k] = ''

            record = {}

            record['id'] = item.pop('id')
            record['action'] = url('/tree/open', model=model, id=record['id'], context=ctx)
            record['target'] = None

            record['icon'] = None

            if icon_name and item.get(icon_name):
                icon = item.pop(icon_name)
                record['icon'] = icons.get_icon(icon)

                if icon == 'STOCK_OPEN':
                    record['action'] = None
                    record['target'] = None

            record['children'] = []

            if field_parent and field_parent in item:
                record['children'] = item.pop(field_parent) or None

            record['items'] = item

            records += [record]

        return dict(records=records)
示例#13
0
 def update_params(self, d):
     super(JSCatelog, self).update_params(d)
     lang = _get_locale()
     if i18n.is_locale_supported(lang):
         d["link"] = tools.url("/static/javascript/i18n/%s.js" % (lang))