Skip to content

Commit

Permalink
Stop embedding refresh code on pages that don't require it.
Browse files Browse the repository at this point in the history
  • Loading branch information
dodobas committed Sep 12, 2018
1 parent 2c2a350 commit d018be7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
7 changes: 4 additions & 3 deletions smartmin/templates/smartmin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@


</script>

{# embed refresh script if refresh is active #}
{% if refresh %}
<script>
function refresh(onSuccess, forceReload){

Expand All @@ -125,16 +126,16 @@
});
}

{% if refresh %}
function scheduleRefresh() {
window.setTimeout(refresh, {{ refresh }});
}

$(document).ready(function(){
scheduleRefresh();
});
{% endif %}

</script>
{% endif %}

{% endblock %}

Expand Down
18 changes: 18 additions & 0 deletions test_runner/blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ def test_permissions(self):
self.assertHasAccess(self.author, read_url)
self.assertHasAccess(self.superuser, read_url)

def test_refresh_page(self):
self.client.login(username='author', password='author')

refresh_url = reverse('blog.post_refresh', args=[self.post.id])

response = self.client.get(refresh_url)

self.assertContains(response, 'function scheduleRefresh')

def test_norefresh_page(self):
self.client.login(username='author', password='author')

no_refresh_url = reverse('blog.post_no_refresh', args=[self.post.id])

response = self.client.get(no_refresh_url)

self.assertNotContains(response, 'function scheduleRefresh')

def test_create_and_update(self):
self.client.login(username='author', password='author')

Expand Down
18 changes: 16 additions & 2 deletions test_runner/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class Create(SmartCreateView):

class PostCRUDL(SmartCRUDL):
model = Post
actions = ('create', 'read', 'update', 'delete', 'list', 'author',
'exclude', 'exclude2', 'readonly', 'readonly2', 'messages', 'csv_import', 'by_uuid')
actions = (
'create', 'read', 'update', 'delete', 'list', 'author', 'exclude', 'exclude2', 'readonly', 'readonly2',
'messages', 'csv_import', 'by_uuid', 'refresh', 'no_refresh'
)

class Read(SmartReadView):
permission = None
Expand Down Expand Up @@ -95,3 +97,15 @@ def pre_process(self, request, *args, **kwargs):

class ByUuid(SmartReadView):
slug_url_kwarg = 'uuid'

class Refresh(SmartReadView):
permission = None

def derive_refresh(self):
return 123

class NoRefresh(SmartReadView):
permission = None

def derive_refresh(self):
return 0

0 comments on commit d018be7

Please sign in to comment.