def get_attachments(self, obj): include_attachments = getattr(obj, "include_attachments", False) if include_attachments: assert hasattr(obj, "attachments_attr" ), "instance must have a attachments_attr attribute" if not include_attachments or obj.attachments_attr is None: return [] for at in obj.attachments_attr: at["thumbnail_card_url"] = get_thumbnail_url( at["attached_file"], settings.THN_ATTACHMENT_CARD) return obj.attachments_attr
def parse_url(self, item): if 'attached_file' in item: attached_file = item['attached_file'] else: # This is the case for old timeline entries file_path = urlparse(item['url']).path index = file_path.find('/attachments') attached_file = file_path[index+1:] item['url'] = default_storage.url(attached_file) if 'thumbnail_file' in item: thumb_file = item['thumbnail_file'] thumb_url = default_storage.url(thumb_file) if thumb_file else None else: thumb_url = get_thumbnail_url(attached_file, settings.THN_ATTACHMENT_TIMELINE) item['thumb_url'] = thumb_url
def test_get_watched_list_valid_info_for_project(): fav_user = f.UserFactory() viewer_user = f.UserFactory() project = f.ProjectFactory(is_private=False, name="Testing project") role = f.RoleFactory(project=project, permissions=[ "view_project", "view_epic", "view_us", "view_tasks", "view_issues" ]) project.add_watcher(fav_user) raw_project_watch_info = get_watched_list(fav_user, viewer_user)[0] project_watch_info = LikedObjectSerializer( into_namedtuple(raw_project_watch_info)).data assert project_watch_info["type"] == "project" assert project_watch_info["id"] == project.id assert project_watch_info["ref"] == None assert project_watch_info["slug"] == project.slug assert project_watch_info["name"] == project.name assert project_watch_info["subject"] == None assert project_watch_info["description"] == project.description assert project_watch_info["assigned_to"] == None assert project_watch_info["status"] == None assert project_watch_info["status_color"] == None assert project_watch_info["is_private"] == project.is_private assert project_watch_info["logo_small_url"] == get_thumbnail_url( project.logo, settings.THN_LOGO_SMALL) assert project_watch_info["is_fan"] == False assert project_watch_info["is_watcher"] == False assert project_watch_info["total_watchers"] == 1 assert project_watch_info["total_fans"] == 0 assert project_watch_info["project"] == None assert project_watch_info["project_name"] == None assert project_watch_info["project_slug"] == None assert project_watch_info["project_is_private"] == None assert project_watch_info["project_blocked_code"] == None assert project_watch_info["assigned_to"] == None assert project_watch_info["assigned_to_extra_info"] == None
def test_get_liked_list_valid_info(): fan_user = f.UserFactory() viewer_user = f.UserFactory() project = f.ProjectFactory(is_private=False, name="Testing project") content_type = ContentType.objects.get_for_model(project) like = f.LikeFactory(content_type=content_type, object_id=project.id, user=fan_user) project.refresh_totals() raw_project_like_info = get_liked_list(fan_user, viewer_user)[0] project_like_info = LikedObjectSerializer( into_namedtuple(raw_project_like_info)).data assert project_like_info["type"] == "project" assert project_like_info["id"] == project.id assert project_like_info["ref"] == None assert project_like_info["slug"] == project.slug assert project_like_info["name"] == project.name assert project_like_info["subject"] == None assert project_like_info["description"] == project.description assert project_like_info["assigned_to"] == None assert project_like_info["status"] == None assert project_like_info["status_color"] == None assert project_like_info["is_private"] == project.is_private assert project_like_info["logo_small_url"] == get_thumbnail_url( project.logo, settings.THN_LOGO_SMALL) assert project_like_info["is_fan"] == False assert project_like_info["is_watcher"] == False assert project_like_info["total_watchers"] == 0 assert project_like_info["total_fans"] == 1 assert project_like_info["project"] == None assert project_like_info["project_name"] == None assert project_like_info["project_slug"] == None assert project_like_info["project_is_private"] == None assert project_like_info["project_blocked_code"] == None assert project_like_info["assigned_to"] == None assert project_like_info["assigned_to_extra_info"] == None
def get_logo_small_url(self, obj): logo = self._none_if_not_project(obj, "logo") if logo: return get_thumbnail_url(logo, settings.THN_LOGO_SMALL) return None
def get_logo_big_thumbnail_url(project): if project.logo: return get_thumbnail_url(project.logo, settings.THN_LOGO_BIG) return None
def get_logo_small_thumbnail_url(project): if project.logo: return get_thumbnail_url(project.logo, settings.THN_LOGO_SMALL) return None
def get_attachment_image_preview_url(attachment): if attachment.attached_file: return get_thumbnail_url(attachment.attached_file, settings.THN_ATTACHMENT_PREVIEW) return None
def get_card_image_thumbnail_url(attachment): if attachment.attached_file: return get_thumbnail_url(attachment.attached_file, settings.THN_ATTACHMENT_CARD) return None