Beispiel #1
0
 def _response_by_status(self, status, headers, content):
     if status == 304:
         return werkzeug.wrappers.Response(status=status, headers=headers)
     elif status == 301:
         return werkzeug.utils.redirect(content, code=301)
     elif status != 200:
         return request.not_found()
Beispiel #2
0
 def submit_rating(self, token, rate, **kwargs):
     rating = request.env['rating.rating'].sudo().search([('access_token',
                                                           '=', token)])
     if not rating:
         return request.not_found()
     record_sudo = request.env[rating.res_model].sudo().browse(
         rating.res_id)
     record_sudo.rating_apply(rate,
                              token=token,
                              feedback=kwargs.get('feedback'))
     lang = rating.partner_id.lang or get_lang(request.env).code
     return request.env['ir.ui.view'].with_context(
         lang=lang).render_template(
             'rating.rating_external_page_view', {
                 'web_base_url':
                 request.env['ir.config_parameter'].sudo().get_param(
                     'web.base.url'),
                 'rating':
                 rating,
             })
Beispiel #3
0
 def open_rating(self, token, rate, **kwargs):
     assert rate in (1, 5, 10), "Incorrect rating"
     rating = request.env['rating.rating'].sudo().search([('access_token',
                                                           '=', token)])
     if not rating:
         return request.not_found()
     rate_names = {
         5: _("not satisfied"),
         1: _("highly dissatisfied"),
         10: _("satisfied")
     }
     rating.write({'rating': rate, 'consumed': True})
     lang = rating.partner_id.lang or get_lang(request.env).code
     return request.env['ir.ui.view'].with_context(
         lang=lang).render_template(
             'rating.rating_external_page_submit', {
                 'rating': rating,
                 'token': token,
                 'rate_name': rate_names[rate],
                 'rate': rate
             })
Beispiel #4
0
    def view(self, db, token, action, id, view='calendar'):
        registry = registry_get(db)
        with registry.cursor() as cr:
            # Since we are in auth=none, create an env with SUPERUSER_ID
            env = Environment(cr, SUPERUSER_ID, {})
            attendee = env['calendar.attendee'].search([
                ('access_token', '=', token), ('event_id', '=', int(id))
            ])
            if not attendee:
                return request.not_found()
            timezone = attendee.partner_id.tz
            lang = attendee.partner_id.lang or get_lang(request.env).code
            event = env['calendar.event'].with_context(tz=timezone,
                                                       lang=lang).browse(
                                                           int(id))

            # If user is internal and logged, redirect to form view of event
            # otherwise, display the simplifyed web page with event informations
            if request.session.uid and request.env['res.users'].browse(
                    request.session.uid).user_has_groups('base.group_user'):
                return werkzeug.utils.redirect(
                    '/web?db=%s#id=%s&view_type=form&model=calendar.event' %
                    (db, id))

            # NOTE : we don't use request.render() since:
            # - we need a template rendering which is not lazy, to render before cursor closing
            # - we need to display the template in the language of the user (not possible with
            #   request.render())
            response_content = env['ir.ui.view'].with_context(
                lang=lang).render_template(
                    'calendar.invitation_page_anonymous', {
                        'event': event,
                        'attendee': attendee,
                    })
            return request.make_response(response_content,
                                         headers=[('Content-Type', 'text/html')
                                                  ])
Beispiel #5
0
    def get_claim_report_user(self, employee_id, **post):
        if not request.env.user.has_group('fleet.fleet_group_manager'):
            return request.not_found()

        employee = request.env['hr.employee'].search(
            [('id', '=', employee_id)], limit=1)
        partner_ids = (employee.user_id.partner_id
                       | employee.sudo().address_home_id).ids
        if not employee or not partner_ids:
            return request.not_found()

        car_assignation_logs = request.env[
            'fleet.vehicle.assignation.log'].search([('driver_id', 'in',
                                                      partner_ids)])
        doc_list = request.env['ir.attachment'].search(
            [('res_model', '=', 'fleet.vehicle.assignation.log'),
             ('res_id', 'in', car_assignation_logs.ids)],
            order='create_date')

        writer = PdfFileWriter()

        font = "Helvetica"
        normal_font_size = 14

        for document in doc_list:
            car_line_doc = request.env['fleet.vehicle.assignation.log'].browse(
                document.res_id)
            try:
                reader = PdfFileReader(io.BytesIO(
                    base64.b64decode(document.datas)),
                                       strict=False,
                                       overwriteWarnings=False)
            except Exception:
                continue

            width = float(reader.getPage(0).mediaBox.getUpperRight_x())
            height = float(reader.getPage(0).mediaBox.getUpperRight_y())

            header = io.BytesIO()
            can = canvas.Canvas(header)
            can.setFont(font, normal_font_size)
            can.setFillColorRGB(1, 0, 0)

            car_name = car_line_doc.vehicle_id.display_name
            date_start = car_line_doc.date_start
            date_end = car_line_doc.date_end or '...'

            text_to_print = _("%s (driven from: %s to %s)") % (
                car_name, date_start, date_end)
            can.drawCentredString(width / 2, height - normal_font_size,
                                  text_to_print)
            can.save()
            header_pdf = PdfFileReader(header, overwriteWarnings=False)

            for page_number in range(0, reader.getNumPages()):
                page = reader.getPage(page_number)
                page.mergePage(header_pdf.getPage(0))
                writer.addPage(page)

        _buffer = io.BytesIO()
        writer.write(_buffer)
        merged_pdf = _buffer.getvalue()
        _buffer.close()

        pdfhttpheaders = [('Content-Type', 'application/pdf'),
                          ('Content-Length', len(merged_pdf))]

        return request.make_response(merged_pdf, headers=pdfhttpheaders)