예제 #1
0
 def website_logo(self, dbname=None, **kw):
     imgname = 'website_nologo.png'
     placeholder = functools.partial(get_module_resource, 'website_logo',
                                     'static', 'src', 'img')
     uid = None
     if request.session.db:
         dbname = request.session.db
         uid = request.session.uid
     elif dbname is None:
         dbname = db_monodb()
     if not uid:
         uid = SUPERUSER_ID
     if uid and dbname:
         try:
             # create an empty registry
             reg = registry.Registry(dbname)
             env = request.httprequest.environ
             domain = env.get('HTTP_HOST', '').split(':')[0]
             with reg.cursor() as cr:
                 image, mtime = self._image_logo_get(cr, domain)
                 if not image:
                     image, mtime = self._image_logo_get(cr, 'localhost')
                 if image:
                     response = http.send_file(image,
                                               filename=imgname,
                                               mtime=mtime)
                     return response
         except Exception:  # pragma: no cover
             _logger.exception(
                 _('Could not get website logo, falling back to default', ))
     return http.send_file(placeholder(imgname))
예제 #2
0
 def _get_company_image_data(self, dbname, uid, field, company=None):
     try:
         dbreg = registry.Registry(dbname)
         with dbreg.cursor() as cr:
             if company:
                 cr.execute("""
                     SELECT {0}, write_date
                     FROM res_company
                     WHERE id = %s        
                 """.format(field), (company,))
             else:
                 cr.execute("""
                     SELECT c.{0}, c.write_date
                     FROM res_users u
                     LEFT JOIN res_company c
                     ON c.id = u.company_id
                     WHERE u.id = %s
                 """.format(field), (uid,))
             return cr.fetchone()
     except Exception:
         return None