def set_ip_for_object(self, instance, **kwargs): opts = get_meta(instance) model = (opts.app_label, opts.model_name) if model in SET_IP_MODELS: request = get_current_request() if request: instance.ip_address = get_client_ip(request)
def replace_file_urls(val, moves): host = '' req = get_current_request() if req is not None: host = req.scheme + '://' + req.get_host() for src, dst in moves: src_dir = '/'.join(src.split('/')[:-1]) dst_dir = '/'.join(dst.split('/')[:-1]) val = re.sub('(' + re.escape(host) + ')?' + re.escape(settings.MEDIA_URL + src_dir), settings.MEDIA_URL + dst_dir, val) return val
def replace_file_urls(val, moves): host = "" req = get_current_request() if req is not None: host = req.scheme + "://" + req.get_host() for src, dst in moves: src_dir = "/".join(src.split("/")[:-1]) dst_dir = "/".join(dst.split("/")[:-1]) val = re.sub( "(" + re.escape(host) + ")?" + re.escape(settings.MEDIA_URL + src_dir), settings.MEDIA_URL + dst_dir, val ) return val
def replace_file_urls(val, moves): host = '' req = get_current_request() if req is not None: host = req.scheme + '://' + req.get_host() for src, dst in moves: src_dir = '/'.join(src.split('/')[:-1]) dst_dir = '/'.join(dst.split('/')[:-1]) val = re.sub( '(' + re.escape(host) + ')?' + re.escape(settings.MEDIA_URL + src_dir), settings.MEDIA_URL + dst_dir, val) return val