Skip to content

Commit

Permalink
Don't generate sources with no published GIFs
Browse files Browse the repository at this point in the history
  • Loading branch information
norm committed Jun 3, 2021
1 parent 3453a2f commit 56453dd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
9 changes: 6 additions & 3 deletions fragments/sources/all/body_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ <h1>All sources</h1>

<ul>
{% for page in pages %}
<li>
<a href='{{page.path}}'>{{page.title}}{% if page.year %} ({{page.year}}){% endif %}</a>
</li>
{% if page.show_set.count() or page.source_set.count()
or page.artist_set.count() or page.agency_set.count() %}
<li>
<a href='{{page.path}}'>{{page.title}}{% if page.year %} ({{page.year}}){% endif %}</a>
</li>
{% endif %}
{% endfor %}
</ul>
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flourish>=0.9.6
flourish>=0.9.7
Pillow
toml
tweepy
19 changes: 19 additions & 0 deletions source/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ def global_context(self):
class SourcePage(base.SourceGenerator):
template_name = 'base_template.html'

def get_context_data(self):
source = self.source_objects[0]
# don't generate GIF sources (eg tv shows, movies, etc)
# that have no published GIFs attached
if 'type' in source and source.type != 'static':
if not (
source.agency_set.count()
or source.artist_set.count()
or source.episode_set.count()
or source.mission_set.count()
or source.show_set.count()
or source.source_set.count()
):
raise self.DoNotGenerate
return super().get_context_data()


class MostRecentFirstMixin:
order_by = ('-published')
Expand Down Expand Up @@ -126,6 +142,9 @@ def get_objects(self, tokens):
else:
_filtered = source.source_set.order_by('-published')

if _filtered.count() == 0:
raise self.DoNotGenerate

_ordered = _filtered.order_by(self.order_by)

if self.limit is not None:
Expand Down

0 comments on commit 56453dd

Please sign in to comment.