예제 #1
0
파일: main.py 프로젝트: Tecnativa/website
 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 = openerp.SUPERUSER_ID
     if uid and dbname:
         try:
             # create an empty registry
             registry = openerp.modules.registry.Registry(dbname)
             env = request.httprequest.environ
             domain = env.get('HTTP_HOST', '').split(':')[0]
             with registry.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(
                 openerp._(
                     'Could not get website logo, falling back to default',
                 ))
     return http.send_file(placeholder(imgname))
예제 #2
0
 def website_logo(self, dbname=None, **kw):
     imgname = 'logo.png'
     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 = openerp.SUPERUSER_ID
     if uid and dbname:
         placeholder = functools.partial(get_module_resource, 'web',
                                         'static', 'src', 'img')
         try:
             # create an empty registry
             registry = openerp.modules.registry.Registry(dbname)
             with registry.cursor() as cr:
                 cr.execute(
                     """SELECT c.website_logo, c.write_date
                                 FROM res_users u
                            LEFT JOIN res_company c
                                   ON c.id = u.company_id
                                WHERE u.id = %s
                            """, (uid, ))
                 row = cr.fetchone()
                 if row and row[0]:
                     image_data = StringIO(str(row[0]).decode('base64'))
                     response = http.send_file(image_data,
                                               filename=imgname,
                                               mtime=row[1])
                     return response
         except Exception:
             return http.send_file(placeholder(imgname))
     return super(website_logo, self).company_logo(dbname=dbname, **kw)
예제 #3
0
파일: main.py 프로젝트: Benniphx/website
 def website_logo(self, dbname=None, **kw):
     imgname = 'logo.png'
     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 = openerp.SUPERUSER_ID
     if uid and dbname:
         placeholder = functools.partial(
             get_module_resource, 'web', 'static', 'src', 'img')
         try:
             # create an empty registry
             registry = openerp.modules.registry.Registry(dbname)
             with registry.cursor() as cr:
                 cr.execute("""SELECT c.website_logo, c.write_date
                                 FROM res_users u
                            LEFT JOIN res_company c
                                   ON c.id = u.company_id
                                WHERE u.id = %s
                            """, (uid,))
                 row = cr.fetchone()
                 if row and row[0]:
                     image_data = StringIO(str(row[0]).decode('base64'))
                     response = http.send_file(
                         image_data, filename=imgname, mtime=row[1])
                     return response
         except Exception:
             return http.send_file(placeholder(imgname))
     return super(website_logo, self).company_logo(dbname=dbname, **kw)
예제 #4
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 = openerp.SUPERUSER_ID
     if uid and dbname:
         try:
             # create an empty registry
             registry = openerp.modules.registry.Registry(dbname)
             env = request.httprequest.environ
             domain = env.get('HTTP_HOST', '').split(':')[0]
             with registry.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:
             return http.send_file(placeholder(imgname))
     return http.send_file(placeholder(imgname))
예제 #5
0
파일: main.py 프로젝트: wwwsec/odoo
    def download_attachment(self, attachment_id):
        # Check if this is a valid attachment id
        attachment = request.env['ir.attachment'].sudo().search_read([
            ('id', '=', int(attachment_id))
        ], [
            "name", "datas", "file_type", "res_model", "res_id", "type", "url"
        ])

        if attachment:
            attachment = attachment[0]
        else:
            return redirect(self.orders_page)

        # Check if the user has bought the associated product
        res_model = attachment['res_model']
        res_id = attachment['res_id']
        purchased_products = request.env[
            'account.invoice.line'].get_digital_purchases(request.uid)

        if res_model == 'product.product':
            if res_id not in purchased_products:
                return redirect(self.orders_page)

        # Also check for attachments in the product templates
        elif res_model == 'product.template':
            P = request.env['product.product']
            template_ids = map(lambda x: P.browse(x).product_tmpl_id.id,
                               purchased_products)
            if res_id not in template_ids:
                return redirect(self.orders_page)

        else:
            return redirect(self.orders_page)

        # The client has bought the product, otherwise it would have been blocked by now
        if attachment["type"] == "url":
            if attachment["url"]:
                return redirect(attachment["url"])
            else:
                return request.not_found()
        elif attachment["datas"]:
            data = StringIO(base64.standard_b64decode(attachment["datas"]))
            return http.send_file(data,
                                  filename=attachment['name'],
                                  as_attachment=True)
        else:
            return request.not_found()
예제 #6
0
파일: main.py 프로젝트: hoanhdung/odoo
    def download_attachment(self, attachment_id):
        # Check if this is a valid attachment id
        attachment = request.env['ir.attachment'].sudo().search_read(
            [('id', '=', int(attachment_id))],
            ["name", "datas", "file_type", "res_model", "res_id", "type", "url"]
        )

        if attachment:
            attachment = attachment[0]
        else:
            return redirect(self.orders_page)


        # Check if the user has bought the associated product
        res_model = attachment['res_model']
        res_id = attachment['res_id']
        purchased_products = request.env['account.invoice.line'].get_digital_purchases(request.uid)

        if res_model == 'product.product':
            if res_id not in purchased_products:
                return redirect(self.orders_page)

        # Also check for attachments in the product templates
        elif res_model == 'product.template':
            P = request.env['product.product']
            template_ids = map(lambda x: P.browse(x).product_tmpl_id.id, purchased_products)
            if res_id not in template_ids:
                return redirect(self.orders_page)

        else:
            return redirect(self.orders_page)

        # The client has bought the product, otherwise it would have been blocked by now
        if attachment["type"] == "url":
            if attachment["url"]:
                return redirect(attachment["url"])
            else:
                return request.not_found()
        elif attachment["datas"]:
            data = StringIO(base64.standard_b64decode(attachment["datas"]))
            return http.send_file(data, filename=attachment['name'], as_attachment=True)
        else:
            return request.not_found()