Ejemplo n.º 1
0
class SocialMediaMixin(JSONColumnMixin('social_media', c.SOCIAL_MEDIA)):
    _social_media_urls = config.get('social_media_urls', {})
    _social_media_placeholders = config.get('social_media_placeholders', {})

    @classmethod
    def get_placeholder(cls, name):
        name = cls.unqualify(name)
        return cls._social_media_placeholders.get(name, '')

    @property
    def has_social_media(self):
        return any(getattr(self, f) for f in self._social_media_fields.keys())

    def __getattr__(self, name):
        if name.endswith('_url'):
            field_name = self.unqualify(name[:-4])
            if field_name in self._social_media_fields:
                attr = super(SocialMediaMixin, self).__getattr__(field_name)
                attr = attr.strip('@#?=. ') if attr else ''
                if attr:
                    if attr.startswith('http:') or attr.startswith('https:'):
                        return attr
                    else:
                        url = self._social_media_urls.get(field_name, '{}')
                        if url_domain(url.format('')) in url_domain(attr):
                            return attr
                        return url.format(attr)
                return ''
            else:
                return super(SocialMediaMixin, self).__getattr__(name)
        elif name.endswith('_placeholder'):
            return self.get_placeholder(name[:-12])
        else:
            return super(SocialMediaMixin, self).__getattr__(name)
Ejemplo n.º 2
0
def _format_import_params(target_server, api_token):
    target_url = _server_to_url(target_server)
    target_host = _server_to_host(target_server)
    remote_api_token = api_token.strip()
    if not remote_api_token:
        remote_api_tokens = _config.get('secret', {}).get('remote_api_tokens', {})
        remote_api_token = remote_api_tokens.get(target_host, remote_api_tokens.get('default', ''))
    return target_url, target_host, remote_api_token.strip()
Ejemplo n.º 3
0
def _format_import_params(target_server, api_token):
    target_url = _server_to_url(target_server)
    target_host = _server_to_host(target_server)
    remote_api_token = api_token.strip()
    if not remote_api_token:
        remote_api_tokens = _config.get('secret', {}).get('remote_api_tokens', {})
        remote_api_token = remote_api_tokens.get(target_host, remote_api_tokens.get('default', ''))
    return (target_url, target_host, remote_api_token.strip())