File tree Expand file tree Collapse file tree 4 files changed +44
-7
lines changed Expand file tree Collapse file tree 4 files changed +44
-7
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,7 @@ def is_open(self):
192
192
day = current_day ,
193
193
opening_time__lte = current_time ,
194
194
closing_time__gte = current_time ,
195
+ closed = False ,
195
196
)
196
197
return True
197
198
except LocationOperatingHours .DoesNotExist :
Original file line number Diff line number Diff line change
1
+ class LocationStatus extends HTMLElement {
2
+ connectedCallback ( ) {
3
+ this . url = this . getAttribute ( 'url' ) ;
4
+ this . updateStatus ( ) ;
5
+ }
6
+
7
+ async updateStatus ( ) {
8
+ const data = await this . fetchPage ( ) ;
9
+ if ( ! data || typeof data . is_open !== 'boolean' ) {
10
+ this . textContent =
11
+ "Sorry, we couldn't retrieve the status of this location." ;
12
+ } else if ( data . is_open ) {
13
+ this . textContent = 'This location is currently open.' ;
14
+ } else {
15
+ this . textContent = 'Sorry, this location is currently closed.' ;
16
+ }
17
+ }
18
+
19
+ fetchPage ( ) {
20
+ return fetch ( this . url )
21
+ . then ( ( response ) => response . json ( ) )
22
+ . catch ( ( ) => null ) ;
23
+ }
24
+ }
25
+
26
+ window . customElements . define ( 'location-status' , LocationStatus ) ;
Original file line number Diff line number Diff line change 54
54
55
55
{% include "includes/footer.html" %}
56
56
57
- < script type ="module " src ="{% static 'js/main.js' %} "> </ script >
57
+ {% block js %}
58
+ < script type ="module " src ="{% static 'js/main.js' %} "> </ script >
59
+ {% endblock %}
58
60
</ body >
59
61
</ html >
Original file line number Diff line number Diff line change 1
1
{% extends "base.html" %}
2
- {% load wagtailimages_tags navigation_tags %}
2
+ {% load wagtailimages_tags navigation_tags static %}
3
3
4
4
{% block content %}
5
5
{% include "base/include/header-hero.html" %}
25
25
< div class ="row ">
26
26
< div class ="bread-detail__meta ">
27
27
< h2 class ="location__meta-title "> Operating Status</ h2 >
28
- {% if page.is_open %}
29
- This location is currently open.
30
- {% else %}
31
- Sorry, this location is currently closed.
32
- {% endif %}
28
+ {% comment %}
29
+ Fetch the status of the location on the client side
30
+ as a Wagtail API usage example and to allow for
31
+ caching of the whole page without the status.
32
+ {% endcomment %}
33
+ < location-status url ="{% url 'wagtailapi:pages:detail' page.pk %} ">
34
+ Please wait...
35
+ </ location-status >
33
36
34
37
< h2 class ="location__meta-title "> Address</ h2 >
35
38
< address > {{ page.address|linebreaks }}</ address >
@@ -67,3 +70,8 @@ <h2 class="location__meta-title">Opening hours</h2>
67
70
</ div >
68
71
69
72
{% endblock content %}
73
+
74
+ {% block js %}
75
+ {{ block.super }}
76
+ < script type ="module " src ="{% static 'js/location-status.js' %} "> </ script >
77
+ {% endblock js %}
You can’t perform that action at this time.
0 commit comments