Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 3.138.36.87
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /opt/odoo/addons/website_twitter/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/addons/website_twitter/models/website_twitter_config.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import logging
from urllib2 import URLError, HTTPError
from odoo import api, fields, models, _
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)

TWITTER_EXCEPTION = {
    304: _('There was no new data to return.'),
    400: _('The request was invalid or cannot be otherwise served. Requests without authentication are considered invalid and will yield this response.'),
    401: _('Authentication credentials were missing or incorrect. Maybe screen name tweets are protected.'),
    403: _('The request is understood, but it has been refused or access is not allowed. Please check your Twitter API Key and Secret.'),
    429: _('Request cannot be served due to the applications rate limit having been exhausted for the resource.'),
    500: _('Twitter seems broken. Please retry later. You may consider posting an issue on Twitter forums to get help.'),
    502: _('Twitter is down or being upgraded.'),
    503: _('The Twitter servers are up, but overloaded with requests. Try again later.'),
    504: _('The Twitter servers are up, but the request could not be serviced due to some failure within our stack. Try again later.')
}


class WebsiteTwitterConfig(models.TransientModel):
    _inherit = 'website.config.settings'

    twitter_api_key = fields.Char(
        related='website_id.twitter_api_key',
        string='Twitter API Key',
        help='Twitter API key you can get it from https://apps.twitter.com/app/new')
    twitter_api_secret = fields.Char(
        related='website_id.twitter_api_secret',
        string='Twitter API secret',
        help='Twitter API secret you can get it from https://apps.twitter.com/app/new')
    twitter_tutorial = fields.Boolean(string='Show me how to obtain the Twitter API Key and Secret')
    twitter_screen_name = fields.Char(
        related='website_id.twitter_screen_name',
        string='Get favorites from this screen name',
        help='Screen Name of the Twitter Account from which you want to load favorites.'
             'It does not have to match the API Key/Secret.')

    def _get_twitter_exception_message(self, error_code):
        if error_code in TWITTER_EXCEPTION:
            return TWITTER_EXCEPTION[error_code]
        else:
            return _('HTTP Error: Something is misconfigured')

    def _check_twitter_authorization(self):
        try:
            self.website_id.fetch_favorite_tweets()

        except HTTPError, e:
            _logger.info("%s - %s" % (e.code, e.reason), exc_info=True)
            raise UserError("%s - %s" % (e.code, e.reason) + ':' + self._get_twitter_exception_message(e.code))
        except URLError, e:
            _logger.info(_('We failed to reach a twitter server.'), exc_info=True)
            raise UserError(_('Internet connection refused') + ' ' + _('We failed to reach a twitter server.'))
        except Exception, e:
            _logger.info(_('Please double-check your Twitter API Key and Secret!'), exc_info=True)
            raise UserError(_('Twitter authorization error!') + ' ' + _('Please double-check your Twitter API Key and Secret!'))

    @api.model
    def create(self, vals):
        TwitterConfig = super(WebsiteTwitterConfig, self).create(vals)
        if vals.get('twitter_api_key') or vals.get('twitter_api_secret') or vals.get('twitter_screen_name'):
            TwitterConfig._check_twitter_authorization()
        return TwitterConfig

    @api.multi
    def write(self, vals):
        TwitterConfig = super(WebsiteTwitterConfig, self).write(vals)
        if vals.get('twitter_api_key') or vals.get('twitter_api_secret') or vals.get('twitter_screen_name'):
            self._check_twitter_authorization()
        return TwitterConfig

Anon7 - 2022
AnonSec Team