def get_big_photo_url(photo): """Get a big photo absolute url and the photo automatically cropped.""" try: url = get_thumbnailer(photo)[settings.THN_AVATAR_BIG].url return get_absolute_url(url) except InvalidImageFormatError as e: return None
def get_photo_url(photo): """Get a photo absolute url and the photo automatically cropped.""" try: url = get_thumbnailer(photo)['avatar'].url return get_absolute_url(url) except InvalidImageFormatError as e: return None
def _get_attachment_thumbnailer_url(attachment, thumbnailer_size): try: thumb_url = get_thumbnailer(attachment.attached_file)[thumbnailer_size].url thumb_url = get_absolute_url(thumb_url) except InvalidImageFormatError: thumb_url = None return thumb_url
def get_thumbnail_url(file_obj, thumbnailer_size): try: path_url = get_thumbnailer(file_obj)[thumbnailer_size].url thumb_url = get_absolute_url(path_url) except InvalidImageFormatError: thumb_url = None return thumb_url
def get_thumbnail_url(file_obj, thumbnailer_size): thumbnail = get_thumbnail(file_obj, thumbnailer_size) if not thumbnail: return None path_url = thumbnail.url thumb_url = get_absolute_url(path_url) return thumb_url
def get_or_generate_config(project): config = project.modules_config.config if config and "github" in config: g_config = project.modules_config.config["github"] else: g_config = {"secret": uuid.uuid4().hex} url = reverse("github-hook-list") url = get_absolute_url(url) url = "%s?project=%s" % (url, project.id) g_config["webhooks_url"] = url return g_config
def get_or_generate_config(project): config = project.modules_config.config if config and "bitbucket" in config: g_config = project.modules_config.config["bitbucket"] else: g_config = {"secret": uuid.uuid4().hex, "valid_origin_ips": settings.BITBUCKET_VALID_ORIGIN_IPS} url = reverse("bitbucket-hook-list") url = get_absolute_url(url) url = "%s?project=%s&key=%s" % (url, project.id, g_config["secret"]) g_config["webhooks_url"] = url return g_config
def get_or_generate_config(project): config = project.modules_config.config if config and "gitlab" in config: g_config = project.modules_config.config["gitlab"] else: g_config = { "secret": uuid.uuid4().hex, "valid_origin_ips": settings.GITLAB_VALID_ORIGIN_IPS, } url = reverse("gitlab-hook-list") url = get_absolute_url(url) url = "{}?project={}&key={}".format(url, project.id, g_config["secret"]) g_config["webhooks_url"] = url return g_config
def extract_attachments(obj) -> list: for attach in obj.attachments.all(): try: thumb_url = get_thumbnailer(attach.attached_file)['timeline-image'].url thumb_url = get_absolute_url(thumb_url) except InvalidImageFormatError as e: thumb_url = None yield {"id": attach.id, "filename": os.path.basename(attach.attached_file.name), "url": attach.attached_file.url, "thumb_url": thumb_url, "is_deprecated": attach.is_deprecated, "description": attach.description, "order": attach.order}
def get_thumbnail_url(file_obj, thumbnailer_size): # Ugly hack to temporary ignore tiff files relative_name = file_obj if isinstance(file_obj, FieldFile): relative_name = file_obj.name source_extension = os.path.splitext(relative_name)[1][1:] if source_extension == "tiff": return None try: path_url = get_thumbnailer(file_obj)[thumbnailer_size].url thumb_url = get_absolute_url(path_url) except InvalidImageFormatError: thumb_url = None return thumb_url
def get_gravatar_url(email: str, **options) -> str: """Get the gravatar url associated to an email. :param options: Additional options to gravatar. - `default` defines what image url to show if no gravatar exists - `size` defines the size of the avatar. By default the `settings.GRAVATAR_DEFAULT_OPTIONS` are used. :return: Gravatar url. """ defaults = settings.GRAVATAR_DEFAULT_OPTIONS.copy() default = defaults.get("default", None) if default: defaults["default"] = get_absolute_url(default) defaults.update(options) email_hash = hashlib.md5(email.lower().encode()).hexdigest() url = GRAVATAR_BASE_URL.format(email_hash, urlencode(defaults)) return url
def test_get_absolute_url(): site = sites.get_current() assert get_absolute_url("http://domain/path") == "http://domain/path" assert get_absolute_url("/path") == build_url("/path", domain=site.domain, scheme=site.scheme)
def get_photo_url(photo): """Get a photo absolute url and the photo automatically cropped.""" url = get_thumbnailer(photo)['avatar'].url return get_absolute_url(url)