Skip to content

Commit

Permalink
Add a default card image when no custom one exists
Browse files Browse the repository at this point in the history
  • Loading branch information
daniviga committed Oct 1, 2023
1 parent a189646 commit 2c2f3f8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions ram/portal/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from portal.models import SiteConfiguration, Flatpage


@admin.register(SiteConfiguration)
class SiteConfigurationAdmin(SingletonModelAdmin):
fieldsets = (
Expand Down
5 changes: 5 additions & 0 deletions ram/portal/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.conf import settings


def default_card_image(request):
return {"DEFAULT_CARD_IMAGE": settings.DEFAULT_CARD_IMAGE}
Binary file added ram/portal/static/coming_soon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions ram/portal/templates/cards.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "base.html" %}
{% load static %}

{% block header %}
<p class="lead text-muted">Results found: {{ matches }}</p>
Expand All @@ -9,9 +10,11 @@
{% for d in data %}
<div class="col">
<div class="card shadow-sm">
{% for i in d.image.all %}
{% if forloop.first %}<a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{{ i.image.url }}" alt="Card image cap"></a>{% endif %}
{% endfor %}
{% if d.image.count > 0 %}
<a href="{{d.get_absolute_url}}"><img class="card-img-top" src="{{ d.image.first.image.url }}" alt="{{ d }}"></a>
{% 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">
<p class="card-text" style="position: relative;">
<strong>{{ d }}</strong>
Expand Down
2 changes: 1 addition & 1 deletion ram/ram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ram.utils import git_suffix

__version__ = "0.4.2"
__version__ = "0.4.3"
__version__ += git_suffix(__file__)
5 changes: 5 additions & 0 deletions ram/ram/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"portal.context_processors.default_card_image",
],
},
},
Expand Down Expand Up @@ -148,6 +149,10 @@
"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.png"

DECODER_INTERFACES = [
(1, "NEM651"),
(2, "NEM652"),
Expand Down

0 comments on commit 2c2f3f8

Please sign in to comment.