Simplify overlay api methods.
This commit is contained in:
parent
1583907571
commit
f8cdad711c
@ -104,29 +104,22 @@ def default_slide():
|
||||
return render_to_string('projector/default_slide.html')
|
||||
|
||||
|
||||
def get_overlays():
|
||||
def get_overlays(only_active=False):
|
||||
"""
|
||||
Returns all overlay objects.
|
||||
|
||||
If only_active is True, returns only active overlays.
|
||||
|
||||
The returned value is a dictonary with the name of the overlay as key, and
|
||||
the overlay object as value.
|
||||
"""
|
||||
overlays = {}
|
||||
for receiver, overlay in projector_overlays.send(sender='get_overlays'):
|
||||
overlays[overlay.name] = overlay
|
||||
if not only_active or overlay.is_active():
|
||||
overlays[overlay.name] = overlay
|
||||
return overlays
|
||||
|
||||
|
||||
def get_projector_overlays():
|
||||
"""
|
||||
Returns the HTML code for all active overlays.
|
||||
"""
|
||||
overlays = [{'name': key, 'html': overlay.get_projector_html()}
|
||||
for key, overlay in get_overlays().items()
|
||||
if overlay.is_active()]
|
||||
return render_to_string('projector/all_overlays.html', {'overlays': overlays})
|
||||
|
||||
|
||||
def get_projector_overlays_js(as_json=False):
|
||||
"""
|
||||
Returns JS-Code for the active overlays.
|
||||
|
@ -59,7 +59,9 @@
|
||||
</div>
|
||||
|
||||
<div id="overlays">
|
||||
{{ overlays }}
|
||||
{% for overlay in overlays.values %}
|
||||
{{ overlay.get_projector_html|safe }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div id="content" {% if reload %}class="reload"{% endif %}>
|
||||
|
@ -1,3 +0,0 @@
|
||||
{% for overlay in overlays %}
|
||||
{{ overlay.html|safe }}
|
||||
{% endfor %}
|
@ -6,7 +6,7 @@ from openslides.utils.tornado_webserver import ProjectorSocketHandler
|
||||
from openslides.utils.views import RedirectView, TemplateView
|
||||
|
||||
from .api import (call_on_projector, get_active_slide,
|
||||
get_overlays, get_projector_content, get_projector_overlays,
|
||||
get_overlays, get_projector_content,
|
||||
get_projector_overlays_js, reset_countdown, set_active_slide,
|
||||
start_countdown, stop_countdown, update_projector_overlay)
|
||||
|
||||
@ -24,7 +24,7 @@ class ProjectorView(TemplateView):
|
||||
if callback is None:
|
||||
kwargs.update({
|
||||
'content': get_projector_content(),
|
||||
'overlays': get_projector_overlays(),
|
||||
'overlays': get_overlays(only_active=True),
|
||||
'overlay_js': get_projector_overlays_js(as_json=True),
|
||||
'reload': True,
|
||||
'calls': config['projector_js_cache']})
|
||||
|
@ -91,30 +91,17 @@ class ApiFunctions(TestCase):
|
||||
mock_overlay = MagicMock()
|
||||
mock_overlay.name = 'mock_overlay'
|
||||
mock_projector_overlays.send.return_value = ((None, mock_overlay), )
|
||||
|
||||
value = projector_api.get_overlays()
|
||||
self.assertEqual(value, {'mock_overlay': mock_overlay})
|
||||
|
||||
@patch('openslides.projector.api.render_to_string')
|
||||
@patch('openslides.projector.api.get_overlays')
|
||||
def test_get_projector_overlays(self, mock_get_overlays, mock_render_to_string):
|
||||
@patch('openslides.projector.api.projector_overlays')
|
||||
def test_get_overlays_inactive(self, mock_projector_overlays):
|
||||
mock_overlay = MagicMock()
|
||||
mock_overlay.get_projector_html.return_value = 'some html'
|
||||
mock_get_overlays.return_value = {'overlay_name': mock_overlay}
|
||||
|
||||
# Test with inactive overlay
|
||||
mock_overlay.name = 'mock_overlay_2'
|
||||
mock_overlay.is_active.return_value = False
|
||||
projector_api.get_projector_overlays()
|
||||
mock_render_to_string.assert_called_with(
|
||||
'projector/all_overlays.html',
|
||||
{'overlays': []})
|
||||
|
||||
# Test with active overlay
|
||||
mock_overlay.is_active.return_value = True
|
||||
projector_api.get_projector_overlays()
|
||||
mock_render_to_string.assert_Called_with(
|
||||
'projector/all_overlays.html',
|
||||
{'overlays': [{'name': 'overlay_name', 'html': 'some html'}]})
|
||||
mock_projector_overlays.send.return_value = ((None, mock_overlay), )
|
||||
value = projector_api.get_overlays(only_active=True)
|
||||
self.assertNotEqual(value, {'mock_overlay_2': mock_overlay})
|
||||
|
||||
@patch('openslides.projector.api.get_overlays')
|
||||
def test_get_projector_overlays_js(self, mock_get_overlays):
|
||||
|
@ -13,9 +13,9 @@ class ProjectorViewTest(TestCase):
|
||||
rf = RequestFactory()
|
||||
|
||||
@patch('openslides.projector.views.get_projector_overlays_js')
|
||||
@patch('openslides.projector.views.get_projector_overlays')
|
||||
@patch('openslides.projector.views.get_overlays')
|
||||
@patch('openslides.projector.views.get_projector_content')
|
||||
def test_get(self, mock_get_projector_content, mock_get_projector_overlays,
|
||||
def test_get(self, mock_get_projector_content, mock_get_overlays,
|
||||
mock_get_projector_overlays_js):
|
||||
view = views.ProjectorView()
|
||||
view.request = self.rf.get('/')
|
||||
@ -34,7 +34,7 @@ class ProjectorViewTest(TestCase):
|
||||
with patch('openslides.projector.views.config', mock_config):
|
||||
context = view.get_context_data()
|
||||
mock_get_projector_content.assert_called_with()
|
||||
mock_get_projector_overlays.assert_called_with()
|
||||
mock_get_overlays.assert_called_with(only_active=True)
|
||||
mock_get_projector_overlays_js.assert_called_with(as_json=True)
|
||||
self.assertTrue(context['reload'])
|
||||
self.assertEqual(context['calls'], 'js_cache')
|
||||
|
Loading…
Reference in New Issue
Block a user