File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import RandomQuote from './random-quotes'
2+
3+
4+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
5+
6+ RandomQuote . init ( )
7+ } )
Original file line number Diff line number Diff line change 1+ function init ( ) {
2+ getRandomQuote ( ) ;
3+
4+ // Change quote every RANDOM_QUOTE_INTERVAL
5+ setInterval ( function ( ) { getRandomQuote ( ) ; } , random_quote_interval ) ;
6+
7+ function getRandomQuote ( ) {
8+ // Get the text and author span id
9+ let text = document . getElementById ( "quote-text" ) ;
10+ let author = document . getElementById ( "quote-author" ) ;
11+ // Load random quote and convert to JSON
12+ fetch ( quotes_api_url )
13+ . then ( response => response . json ( ) )
14+ . then ( data => {
15+ text . textContent = data . result . text
16+ author . textContent = data . result . author
17+ } )
18+ // Animate display
19+ let quote_block = document . getElementById ( "quote-block" ) ;
20+ fadeInQuote ( quote_block )
21+ }
22+ }
23+
24+ function fadeInQuote ( quote , duration = 2000 ) {
25+ quote . animate ( [
26+ { // from
27+ opacity : 0 ,
28+ } ,
29+ { // to
30+ opacity : 1 ,
31+ }
32+ ] , duration ) ;
33+ }
34+
35+ export default {
36+ init
37+ }
Original file line number Diff line number Diff line change 3737
3838 < img class ="logo " src ="{{ assets|get_asset_key:'commons/img/logo_text.png' }} " alt ="Python Canarias " />
3939
40- {% if quote %}
41- < div class ="quote is-centered ">
42- < p > < i class ="fas fa-quote-left "> </ i > {{ quote.text }} < i class ="fas fa-quote-right "> </ i > </ p >
43- < p > — {{ quote.author }}</ p >
40+ < div id ="quote-block " class ="quote is-centered ">
41+ < p >
42+ < i class ="fas fa-quote-left "> </ i >
43+ < span id ="quote-text ">
44+ </ span >
45+ < i class ="fas fa-quote-right "> </ i >
46+ </ p >
47+ < p > —
48+ < span id ="quote-author ">
49+ </ span >
50+ </ p >
4451 </ div >
45- {% endif %}
4652
4753 < div class ="links buttons is-centered ">
4854 < a href ="{% url 'about:index' %} " class ="link button is-primary is-medium is-outlined "> Entrar</ a >
@@ -93,5 +99,13 @@ <h4 class="blog-message">Para más noticias, pásate por nuestro
9399 </ div >
94100 </ div >
95101 </ div >
102+
103+ <!-- Live random quotes managed through JS -->
104+ < script >
105+ const random_quote_interval = "{{ random_quote_interval }}" ;
106+ const quotes_api_url = "{% url 'api:random_quote' %}" ;
107+ </ script >
108+ < script src ="{{ assets|get_asset_key:'homepage/custom.min.js' }} "> </ script >
109+
96110</ body >
97111</ html >
Original file line number Diff line number Diff line change 22
33from django .shortcuts import render
44
5+ from django .conf import settings
6+
57from apps .events .models import Event
68from apps .quotes .models import Quote
79from apps .jobs .models import JobOffer
@@ -12,4 +14,5 @@ def homepage(request):
1214 'active_events' : Event .objects .all ().filter (active = True ).count (),
1315 'quote' : Quote .get_random_quote (),
1416 'jobs_count' : JobOffer .actives .count (),
17+ 'random_quote_interval' : settings .RANDOM_QUOTE_INTERVAL ,
1518 })
Original file line number Diff line number Diff line change 331331TWITTER_ACCESS_TOKEN = config ('TWITTER_ACCESS_TOKEN' )
332332TWITTER_ACCESS_TOKEN_SECRET = config ('TWITTER_ACCESS_TOKEN_SECRET' )
333333
334+ # Random quote interval (seconds)
335+ RANDOM_QUOTE_INTERVAL = config (
336+ 'RANDOM_QUOTE_INTERVAL' , default = 10 , cast = lambda i : 1000 * int (i )
337+ )
338+
334339if DEBUG :
335340 MESSAGE_LEVEL = message_constants .DEBUG
336341
You can’t perform that action at this time.
0 commit comments