Exemple #1
0
def photo_card(photo):
    class_name = "photo-card"
    anchor_attrs = f'data-rotation="{photo.rotation}" ' f'data-fancybox="gallery"'

    if photo.album.shareable:
        anchor_attrs += " data-download={}".format(
            reverse(
                "photos:shared-download",
                args=[photo.album.slug, photo.album.access_token, photo],
            ))
    else:
        anchor_attrs += " data-download={}".format(
            reverse("photos:download", args=[photo.album.slug, photo]))

    image_url = get_thumbnail_url(photo.file,
                                  settings.THUMBNAIL_SIZES["medium"])

    if photo.rotation > 0:
        class_name += " rotate{}".format(photo.rotation)
        anchor_attrs += (f" data-options="
                         f'\'{{"slideClass": "rotate{photo.rotation}"}}\'')

    return grid_item(
        title="",
        url=get_thumbnail_url(photo.file,
                              settings.THUMBNAIL_SIZES["large"],
                              fit=False),
        image_url=image_url,
        class_name=class_name,
        anchor_attrs=anchor_attrs,
    )
Exemple #2
0
def create_image_thumbnail_dict(
    request,
    file,
    placeholder="",
    size_small=settings.THUMBNAIL_SIZES["small"],
    size_medium=settings.THUMBNAIL_SIZES["medium"],
    size_large=settings.THUMBNAIL_SIZES["large"],
    fit_small=True,
    fit_medium=True,
    fit_large=True,
):
    if file:
        return {
            "full": request.build_absolute_uri(get_media_url(file)),
            "small": request.build_absolute_uri(
                get_thumbnail_url(file, size_small, fit=fit_small)
            ),
            "medium": request.build_absolute_uri(
                get_thumbnail_url(file, size_medium, fit=fit_medium)
            ),
            "large": request.build_absolute_uri(
                get_thumbnail_url(file, size_large, fit=fit_large)
            ),
        }
    return {
        "full": placeholder,
        "small": placeholder,
        "medium": placeholder,
        "large": placeholder,
    }
Exemple #3
0
def partner_image_card(image):
    """Return grid item showing partner image."""
    class_name = "partner-image-card"
    image_url = get_thumbnail_url(image, settings.THUMBNAIL_SIZES["medium"])

    return grid_item(
        title="",
        url=get_thumbnail_url(image,
                              settings.THUMBNAIL_SIZES["large"],
                              fit=False),
        image_url=image_url,
        class_name=class_name,
        anchor_attrs='data-fancybox="gallery"',
    )
Exemple #4
0
def thumbnail(path, size, fit=True):
    """
    This templatetag provides us with a way of getting a thumbnail
    directly inside templates. See the documentation
    of :func:`get_thumbnail_url` for a more information.
    :param path: the path or ImageField we want an thumbnail from,
    this field MUST NEVER be a user input
    :param size: the size formatted like `widthxheight`
    :param fit: True if we want the image to fit
    :return: the thumbnail url
    """
    return get_thumbnail_url(path, size, fit)
def membergroup_card(group, language):
    image_url = static(f"activemembers/images/{language}/" f"placeholder_overview.png")
    if group.photo:
        image_url = get_thumbnail_url(group.photo, settings.THUMBNAIL_SIZES["medium"])

    return grid_item(
        title=group.name,
        meta_text="",
        url=group.get_absolute_url,
        image_url=image_url,
        class_name="membergroup-card",
    )
Exemple #6
0
def partner_card(partner):
    """Return grid item showing partner."""
    image_url = ""
    if partner.logo:
        image_url = get_thumbnail_url(partner.logo,
                                      settings.THUMBNAIL_SIZES["medium"],
                                      fit=False)

    meta_text = truncatechars(bleach(striptags(partner.company_profile)), 80)

    return grid_item(
        title=partner.name,
        meta_text='<p class="px-2 d-none d-md-block">{}</p>'.format(meta_text),
        url=partner.get_absolute_url,
        image_url=image_url,
        class_name="partner-card",
    )
Exemple #7
0
def member_card(member, meta_text=None, ribbon=None):
    if meta_text is None and member.profile.starting_year:
        meta_text = '<p class="px-1">{}: {}</p>'.format(
            _("Cohort"), member.profile.starting_year
        )

    image_url = static("members/images/default-avatar.jpg")
    if member.profile.photo:
        image_url = get_thumbnail_url(
            member.profile.photo, settings.THUMBNAIL_SIZES["medium"]
        )

    return grid_item(
        title=member.profile.display_name(),
        meta_text=meta_text,
        url=reverse("members:profile", kwargs={"pk": member.pk}),
        image_url=image_url,
        ribbon=ribbon,
        class_name="member-card",
    )
Exemple #8
0
def thabloid_card(year, thabloid):
    view_url = reverse("thabloid:pages", args=[thabloid.year, thabloid.issue])
    buttons = (
        '<div class="text-center mt-2">'
        '<a href="{}" class="btn btn-secondary d-inline-flex open mr-1">'
        '<i class="fas fa-book-open"></i>'
        "</a>"
        '<a href="{}" download '
        'class="btn btn-secondary d-inline-flex download ml-1">'
        '<i class="fas fa-download"></i>'
        "</a>"
        "</div>").format(view_url, thabloid.file.url)

    return grid_item(
        title="{}-{}, #{}".format(thabloid.year, thabloid.year + 1,
                                  thabloid.issue),
        meta_text=buttons,
        url=None,
        image_url=get_thumbnail_url(thabloid.cover, "255x360"),
        class_name=f"thabloid-card",
    )
Exemple #9
0
def album_card(album):
    class_name = "album-card"
    image_url = ""

    if album.cover:
        image_url = get_thumbnail_url(album.cover.file,
                                      settings.THUMBNAIL_SIZES["medium"])
        if album.cover.rotation > 0:
            class_name += " rotate{}".format(album.cover.rotation)

    url = album.get_absolute_url
    if not album.accessible:
        class_name += " grayscale"
        url = None

    return grid_item(
        title=album.title,
        meta_text="<p>{}</p>".format(date(album.date, "Y-m-d")),
        url=url,
        image_url=image_url,
        class_name=class_name,
    )
Exemple #10
0
def vacancy_card(vacancy):
    """Return grid item showing vacancy."""
    image_url = None
    if vacancy.get_company_logo():
        image_url = get_thumbnail_url(vacancy.get_company_logo(),
                                      settings.THUMBNAIL_SIZES["medium"],
                                      fit=False)

    description = truncatechars(bleach(striptags(vacancy.description)), 150)
    extra_class = "external-vacancy"
    url = "#vacancy-{}".format(vacancy.id)
    if vacancy.partner:
        url = "{}#vacancy-{}".format(vacancy.partner.get_absolute_url(),
                                     vacancy.id)
        extra_class = ""

    return {
        "title": vacancy.title,
        "company_name": vacancy.get_company_name(),
        "image_url": image_url,
        "description": description,
        "url": url,
        "extra_class": extra_class,
    }
 def _file(self, obj):
     return self.context["request"].build_absolute_uri(
         get_thumbnail_url(obj.content, settings.THUMBNAIL_SIZES["slide"]))