handle empty results correctly in CampViewMixin, also add a text to the speaker list page when no speakers are found
This commit is contained in:
parent
025692d017
commit
d46ccc530b
|
@ -16,7 +16,12 @@ class CampViewMixin(object):
|
|||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
if queryset:
|
||||
|
||||
# if this queryset is empty return it right away, because nothing for us to do
|
||||
if not queryset:
|
||||
return queryset
|
||||
|
||||
# get the camp_filter from the model
|
||||
camp_filter = self.model.get_camp_filter()
|
||||
|
||||
# Let us deal with eveything as a list
|
||||
|
@ -42,10 +47,12 @@ class CampViewMixin(object):
|
|||
filter_dict[self.get_slug_field()] = slug
|
||||
|
||||
# do the filtering and return the result
|
||||
print("filter_dict is %s" % filter_dict)
|
||||
result = queryset.filter(**filter_dict)
|
||||
if result.exists():
|
||||
# we got some results with this camp_filter, return now
|
||||
return result
|
||||
|
||||
# Camp relation not found, or queryset is empty, return it unaltered
|
||||
return queryset
|
||||
# no camp_filter returned any results, return an empty queryset
|
||||
return result
|
||||
|
||||
|
|
|
@ -17,5 +17,7 @@
|
|||
{{ speaker.name }} {% for event in speaker.events.all %}<i class="fas fa-{{ event.event_type.icon }} fa-lg" style="color: {{ event.event_type.color }};" data-toggle="tooltip" title="{{ event.title }}"></i> {% endfor %}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="lead">No speakers found for {{ camp.title }}</p>
|
||||
{% endif %}
|
||||
{% endblock program_content %}
|
||||
|
|
Loading…
Reference in a new issue