Skip to content

Commit

Permalink
caching
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-garrido committed Oct 5, 2017
1 parent eff7c64 commit 25c1305
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
13 changes: 8 additions & 5 deletions elections/views.py
Expand Up @@ -66,7 +66,7 @@ def get_context_data(self, **kwargs):
featured_elections = cache.get('featured_elections')
if featured_elections is None:
featured_elections = Election.objects.filter(highlighted=True)
cache.set('featured_elections', featured_elections, 600)
cache.set('featured_elections', featured_elections, 3600)
context['featured_elections'] = featured_elections

context['searchable_elections_enabled'] = True
Expand All @@ -76,15 +76,18 @@ def get_context_data(self, **kwargs):
total_proposals = cache.get('total_proposals')
if total_proposals is None:
total_proposals = PopularProposal.objects.count()
cache.set('total_proposals', total_proposals, 600)
cache.set('total_proposals', total_proposals, 3600)
context['total_proposals'] = total_proposals
proposals_with_likers = cache.get('proposals_with_likers')
if proposals_with_likers is None:
proposals_with_likers = PopularProposal.ordered.by_likers()[:9]
cache.set('proposals_with_likers', proposals_with_likers, 600)
cache.set('proposals_with_likers', proposals_with_likers, 3600)
context['proposals_with_likers'] = proposals_with_likers
featured_proposals = PopularProposal.objects.filter(featured=True)
cache.set('featured_proposals', featured_proposals, 600)

featured_proposals = cache.get('featured_proposals')
if proposals_with_likers is None:
featured_proposals = PopularProposal.objects.filter(featured=True)
cache.set('featured_proposals', featured_proposals, 3600)
context['featured_proposals'] = featured_proposals
return context

Expand Down
8 changes: 6 additions & 2 deletions popular_proposal/models.py
Expand Up @@ -283,9 +283,13 @@ def generate_og_image(self):
propuesta_de = u"Una propuesta de " + proposer_name
propuesta_de = propuesta_de.upper()
d.multiline_text((81,471), propuesta_de, font=montserrat_autor, fill=(255,255,255,255))
out = Image.alpha_composite(base, txt)

return out
image_out = cache.get('image-out')
if image_out is None:
image_out = Image.alpha_composite(base, txt)
cache.set('image-out', image_out, 3600)

return image_out
def get_classification(self):
return self.__class__.get_topic_choices_dict().get(self.clasification, u"")

Expand Down
12 changes: 11 additions & 1 deletion votai_general_theme/templates/index_first_launch.html
@@ -1,4 +1,8 @@
{% load staticfiles %} {% load votainteligente_extras %} {% load i18n %}
{% load staticfiles %}
{% load votainteligente_extras %}
{% load i18n %}
{% load cache %}

<section id="welcome" class="yellow">
<div class="container">
<div class="row">
Expand Down Expand Up @@ -51,7 +55,9 @@ <h3 class="text-center"><a href="{% url 'popular_proposals:home' %}" onclick="ga
{% if featured_proposals.count %}
<section id="highlighted-proposals">
<h3 class="text-center">Conoce algunas de las propuestas ciudadanas</h3>
{% cache 86400 main-proposals_list %}
{% include 'popular_proposal/_lista_propuestas.html' with popular_proposals=featured_proposals form=Nil hide_proposal_list_header=True %}
{% endcache %}
<p class="text-center"><a href="{% url 'popular_proposals:home' %}" class="btn btn-white">Ver todas las propuestas</a></p>
</section>
{% endif %}
Expand All @@ -60,7 +66,9 @@ <h3 class="text-center">Conoce algunas de las propuestas ciudadanas</h3>
<h3 class="text-center">Conoce a las candidaturas</h3>
<div class="row">
<div class="col-md-12">
{% cache 86400 main-know-candidates %}
{% include "_election_search_form.html" %}
{% endcache %}
</div>
</div>
</div>
Expand All @@ -77,7 +85,9 @@ <h3 class="text-center"><a href="{% url 'material_ciudadano' %}" onclick="ga('se
</div>
</div>
</section>
{% cache 86400 main-organizations-list %}
{% organization_logos %}
{% endcache %}
<section id="you-org" class="grey-one">
<div class="container">
<div class="row">
Expand Down
Expand Up @@ -3,6 +3,7 @@
{% load thumbnail %}
{% load bootstrap3 %}
{% load votainteligente_extras %}
{% load cache %}
<!-- Inicio _lista_propuestas -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.1/jquery.form.min.js"></script>
<script>
Expand Down Expand Up @@ -51,6 +52,7 @@ <h3 class="text-center">Hay {{popular_proposals|length}} {% if not tipo_propuest
{% endif %}

<div id="posts">
{% cache 3600 popular-proposal-list %}
{% for proposal in popular_proposals %}
{% display_proposal_card proposal %}
{% empty %}
Expand All @@ -61,6 +63,7 @@ <h3 class="text-center">Hay {{popular_proposals|length}} {% if not tipo_propuest
</p>
{% endblocktrans %}
{% endfor %}
{% endcache %}
</div>
</div>
</div>
Expand Down
Expand Up @@ -2,8 +2,10 @@
{% load votainteligente_extras %}
{% load i18n %}
{% load thumbnail %}
{% load cache %}

{% cache 3600 proposalcard %}
<div class="post propuesta{% if proposal.for_all_areas %} transversal{% endif %}">
<!-- Cata compañera puedes saber si la propuesta es para todas las comunas mediante esto {% comment %}{% if proposal.for_all_areas %}{% else %}{% endif %}{% endcomment %}-->
<div class="propuesta-content">
{% if proposal.is_local_meeting %}
<div class="ribbon-wrapper">
Expand Down Expand Up @@ -66,3 +68,4 @@ <h4><a href="{% url 'popular_proposals:detail' slug=proposal.slug %}">{{proposal
</div>
{% endif %}
</div>
{% endcache %}

0 comments on commit 25c1305

Please sign in to comment.