Add a default card image when no custom one exists (#23)

* Add a default card image when no custom one exists
* Add coming_soon.png source
* Use directly the svg source instead of the png raster
This commit is contained in:
2023-10-01 16:36:30 +02:00
committed by GitHub
parent a189646aa5
commit f4023f105f
6 changed files with 76 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ from solo.admin import SingletonModelAdmin
from portal.models import SiteConfiguration, Flatpage from portal.models import SiteConfiguration, Flatpage
@admin.register(SiteConfiguration) @admin.register(SiteConfiguration)
class SiteConfigurationAdmin(SingletonModelAdmin): class SiteConfigurationAdmin(SingletonModelAdmin):
fieldsets = ( fieldsets = (

View File

@@ -0,0 +1,5 @@
from django.conf import settings
def default_card_image(request):
return {"DEFAULT_CARD_IMAGE": settings.DEFAULT_CARD_IMAGE}

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="420"
height="226"
viewBox="0 0 5.8333333 3.1388889"
version="1.1"
id="svg1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1">
<linearGradient
id="linearGradient1">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0.59606808"
id="stop2" />
<stop
style="stop-color:#f5f5f5;stop-opacity:1;"
offset="1"
id="stop1" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient1"
id="linearGradient2"
x1="0"
y1="1.5694444"
x2="5.8333335"
y2="1.5694444"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.53809522,0,0,1.8584071,-3.1388889,0)"
spreadMethod="pad" />
</defs>
<g
id="layer1">
<rect
style="mix-blend-mode:normal;fill:url(#linearGradient2);stroke:none;stroke-width:0.801535"
id="rect1"
width="3.1388888"
height="5.8333335"
x="-3.1388888"
y="-2.220446e-16"
transform="rotate(-90)" />
<text
xml:space="preserve"
style="font-weight:bold;font-size:0.444444px;line-height:1.25;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans Bold';letter-spacing:0px;word-spacing:0px;stroke-width:0.0138889"
x="1.5366687"
y="1.6798887"
id="text1"><tspan
id="tspan1"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:0.444444px;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans';fill:#dee2e6;fill-opacity:1;stroke-width:0.0138889"
x="1.5366687"
y="1.6798887">Coming soon</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -1,4 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load static %}
{% block header %} {% block header %}
<p class="lead text-muted">Results found: {{ matches }}</p> <p class="lead text-muted">Results found: {{ matches }}</p>
@@ -9,9 +10,11 @@
{% for d in data %} {% for d in data %}
<div class="col"> <div class="col">
<div class="card shadow-sm"> <div class="card shadow-sm">
{% for i in d.image.all %} {% if d.image.count > 0 %}
{% if forloop.first %}<a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{{ i.image.url }}" alt="Card image cap"></a>{% endif %} <a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{{ d.image.first.image.url }}" alt="{{ d }}"></a>
{% endfor %} {% else %}
<a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{% static DEFAULT_CARD_IMAGE %}" alt="{{ d }}"></a>
{% endif %}
<div class="card-body"> <div class="card-body">
<p class="card-text" style="position: relative;"> <p class="card-text" style="position: relative;">
<strong>{{ d }}</strong> <strong>{{ d }}</strong>

View File

@@ -1,4 +1,4 @@
from ram.utils import git_suffix from ram.utils import git_suffix
__version__ = "0.4.2" __version__ = "0.4.3"
__version__ += git_suffix(__file__) __version__ += git_suffix(__file__)

View File

@@ -80,6 +80,7 @@ TEMPLATES = [
"django.template.context_processors.request", "django.template.context_processors.request",
"django.contrib.auth.context_processors.auth", "django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages", "django.contrib.messages.context_processors.messages",
"portal.context_processors.default_card_image",
], ],
}, },
}, },
@@ -148,6 +149,10 @@ COUNTRIES_OVERRIDE = {
"ZZ": "Freelance", "ZZ": "Freelance",
} }
# Image used on cards without a custom image uploaded.
# The file must be placed in the root of the 'static' folder
DEFAULT_CARD_IMAGE = "coming_soon.svg"
DECODER_INTERFACES = [ DECODER_INTERFACES = [
(1, "NEM651"), (1, "NEM651"),
(2, "NEM652"), (2, "NEM652"),