Пример #1
0
    def synchronize_events_cron(self):
        """ Call by the cron. """
        users = self.env['res.users'].search([
            ('google_calendar_last_sync_date', '!=', False)
        ])
        _logger.info("Calendar Synchro - Started by cron")

        for user_to_sync in users.ids:
            _logger.info(
                "Calendar Synchro - Starting synchronization for a new user [%s]",
                user_to_sync)
            try:
                resp = self.sudo(user_to_sync).synchronize_events(
                    lastSync=True)
                if resp.get("status") == "need_reset":
                    _logger.info(
                        "[%s] Calendar Synchro - Failed - NEED RESET  !",
                        user_to_sync)
                else:
                    _logger.info(
                        "[%s] Calendar Synchro - Done with status : %s  !",
                        user_to_sync, resp.get("status"))
            except Exception as e:
                _logger.info("[%s] Calendar Synchro - Exception : %s !",
                             user_to_sync, exception_to_unicode(e))
        _logger.info("Calendar Synchro - Ended by cron")
Пример #2
0
    def _warn_template_error(self, scheduler, exception):
        # We warn ~ once by hour ~ instead of every 10 min if the interval unit is more than 'hours'.
        if random.random() < 0.1666 or scheduler.interval_unit in ('now', 'hours'):
            ex_s = exception_to_unicode(exception)
            try:
                event, template = scheduler.event_id, scheduler.template_id
                emails = list(set([event.organizer_id.email, event.user_id.email, template.write_uid.email]))
                subject = _("WARNING: Event Scheduler Error for event: %s" % event.name)
                body = _("""Event Scheduler for:
                              - Event: %s (%s)
                              - Scheduled: %s
                              - Template: %s (%s)

                            Failed with error:
                              - %s

                            You receive this email because you are:
                              - the organizer of the event,
                              - or the responsible of the event,
                              - or the last writer of the template."""
                         % (event.name, event.id, scheduler.scheduled_date, template.name, template.id, ex_s))
                email = self.env['ir.mail_server'].build_email(
                    email_from=self.env.user.email,
                    email_to=emails,
                    subject=subject, body=body,
                )
                self.env['ir.mail_server'].send_email(email)
            except Exception as e:
                _logger.error("Exception while sending traceback by email: %s.\n Original Traceback:\n%s", e, exception)
                pass
Пример #3
0
    def import_zipfile(self, module_file, force=False):
        if not module_file:
            raise Exception(_("No file sent."))
        if not zipfile.is_zipfile(module_file):
            raise UserError(_('Only zip files are supported.'))

        success = []
        errors = dict()
        module_names = []
        with zipfile.ZipFile(module_file, "r") as z:
            for zf in z.filelist:
                if zf.file_size > MAX_FILE_SIZE:
                    raise UserError(
                        _("File '%s' exceed maximum allowed file size",
                          zf.filename))

            with tempfile.TemporaryDirectory() as module_dir:
                import flectra.modules.module as module
                try:
                    flectra.addons.__path__.append(module_dir)
                    z.extractall(module_dir)
                    dirs = [
                        d for d in os.listdir(module_dir)
                        if os.path.isdir(opj(module_dir, d))
                    ]
                    for mod_name in dirs:
                        module_names.append(mod_name)
                        try:
                            # assert mod_name.startswith('theme_')
                            path = opj(module_dir, mod_name)
                            if self._import_module(mod_name, path,
                                                   force=force):
                                success.append(mod_name)
                        except Exception as e:
                            _logger.exception('Error while importing module')
                            errors[mod_name] = exception_to_unicode(e)
                finally:
                    flectra.addons.__path__.remove(module_dir)
        r = ["Successfully imported module '%s'" % mod for mod in success]
        for mod, error in errors.items():
            r.append(
                "Error while importing module '%s'.\n\n %s \n Make sure those modules are installed and try again."
                % (mod, error))
        return '\n'.join(r), module_names
Пример #4
0
    def get_one_event_synchro(self, google_id):
        token = self.get_token()

        params = {
            'access_token': token,
            'maxResults': 1000,
            'showDeleted': True,
        }

        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}

        url = "/calendar/v3/calendars/%s/events/%s" % ('primary', google_id)
        try:
            status, content, ask_time = self.env['google.service']._do_request(url, params, headers, type='GET')
        except Exception as e:
            _logger.info("Calendar Synchro - In except of get_one_event_synchro")
            _logger.info(exception_to_unicode(e))
            return False

        return status_response(status) and content or False
Пример #5
0
    def import_zipfile(self, module_file, force=False):
        if not module_file:
            raise Exception(_("No file sent."))
        if not zipfile.is_zipfile(module_file):
            raise UserError(_('File is not a zip file!'))

        success = []
        errors = dict()
        module_names = []
        with zipfile.ZipFile(module_file, "r") as z:
            for zf in z.filelist:
                if zf.file_size > MAX_FILE_SIZE:
                    raise UserError(
                        _("File '%s' exceed maximum allowed file size") %
                        zf.filename)

            with tempdir() as module_dir:
                import flectra.modules.module as module
                try:
                    module.ad_paths.append(module_dir)
                    z.extractall(module_dir)
                    dirs = [
                        d for d in os.listdir(module_dir)
                        if os.path.isdir(opj(module_dir, d))
                    ]
                    for mod_name in dirs:
                        module_names.append(mod_name)
                        try:
                            # assert mod_name.startswith('theme_')
                            path = opj(module_dir, mod_name)
                            self._import_module(mod_name, path, force=force)
                            success.append(mod_name)
                        except Exception as e:
                            _logger.exception('Error while importing module')
                            errors[mod_name] = exception_to_unicode(e)
                finally:
                    module.ad_paths.remove(module_dir)
        r = ["Successfully imported module '%s'" % mod for mod in success]
        for mod, error in errors.items():
            r.append("Error while importing module '%s': %r" % (mod, error))
        return '\n'.join(r), module_names