def ready(self): # Load main menu entry, personal info and widgets. # Do this by just importing all from these files. from . import main_menu, personal_info, widgets # noqa # Import all required stuff. from django.db.models.signals import pre_delete from openslides.config.signals import config_signal from openslides.projector.api import register_slide from openslides.projector.signals import projector_overlays from openslides.utils.rest_api import router from .signals import agenda_list_of_speakers, setup_agenda_config, listen_to_related_object_delete_signal from .slides import agenda_slide from .views import ItemViewSet # Connect signals. config_signal.connect(setup_agenda_config, dispatch_uid='setup_agenda_config') projector_overlays.connect(agenda_list_of_speakers, dispatch_uid='agenda_list_of_speakers') pre_delete.connect( listen_to_related_object_delete_signal, dispatch_uid='agenda_listen_to_related_object_delete_signal') # Register slides. Item = self.get_model('Item') register_slide('agenda', agenda_slide, Item) # Register viewsets. router.register('agenda/item', ItemViewSet)
def test_register_slide(self): mock_slide_callback = {} mock_slide_model = {} with patch('openslides.projector.api.slide_model', mock_slide_model): with patch('openslides.projector.api.slide_callback', mock_slide_callback): projector_api.register_slide('some name', 'some callback') projector_api.register_slide('other name', 'other callback', 'Model') self.assertEqual(mock_slide_callback, {'some name': 'some callback', 'other name': 'other callback'}) self.assertEqual(mock_slide_model, {'other name': 'Model'})
def ready(self): # Load main menu entry and widgets. # Do this by just importing all from these files. from . import main_menu, widgets # noqa # Import all required stuff. from openslides.projector.api import register_slide from openslides.utils.rest_api import router from openslides.utils.signals import template_manipulation from .slides import mediafile_presentation_as_slide from .template import add_mediafile_stylesheets from .views import MediafileViewSet # Connect template signal. template_manipulation.connect(add_mediafile_stylesheets, dispatch_uid='add_mediafile_stylesheets') # Register slides. Mediafile = self.get_model('Mediafile') register_slide('mediafile', mediafile_presentation_as_slide, Mediafile) # Register viewsets. router.register('mediafile/mediafile', MediafileViewSet)
context = {} if item is None: items = Item.objects.filter(parent=None, type__exact=Item.AGENDA_ITEM) else: items = item.get_children().filter(type__exact=Item.AGENDA_ITEM) context['title'] = item.get_title() context['items'] = items slide = render_to_string('agenda/item_slide_summary.html', context) elif slide_type == 'list_of_speakers': list_of_speakers = item.get_list_of_speakers( old_speakers_count=config['agenda_show_last_speakers']) context = {'title': item.get_title(), 'item': item, 'list_of_speakers': list_of_speakers} slide = render_to_string('agenda/item_slide_list_of_speaker.html', context) elif item.content_object: slide_dict = { 'callback': item.content_object.slide_callback_name, 'pk': item.content_object.pk} slide = get_projector_content(slide_dict) else: context = {'item': item} slide = render_to_string('agenda/item_slide.html', context) return slide register_slide('agenda', agenda_slide)
context = {} if item is None: items = Item.objects.filter(parent=None, type__exact=Item.AGENDA_ITEM) else: items = item.get_children().filter(type__exact=Item.AGENDA_ITEM) context['title'] = item.get_title() context['items'] = items slide = render_to_string('agenda/item_slide_summary.html', context) elif slide_type == 'list_of_speakers': list_of_speakers = item.get_list_of_speakers( old_speakers_count=config['agenda_show_last_speakers']) context = {'title': item.get_title(), 'item': item, 'list_of_speakers': list_of_speakers} slide = render_to_string('agenda/item_slide_list_of_speaker.html', context) elif item.content_object: slide_dict = { 'callback': item.content_object.slide_callback_name, 'pk': item.content_object.pk} slide = get_projector_content(slide_dict) else: context = {'item': item} slide = render_to_string('agenda/item_slide.html', context) return slide register_slide('agenda', agenda_slide, Item)
from openslides.projector.api import register_slide, SlideError from .models import Mediafile def mediafile_presentation_as_slide(**kwargs): """ Return the html code for a presentation of a Mediafile. At the moment, only the presentation of pdfs is supported. """ file_pk = kwargs.get('pk', None) page_num = kwargs.get('page_num', 1) try: pdf = Mediafile.objects.get( pk=file_pk, filetype__in=Mediafile.PRESENTABLE_FILE_TYPES, is_presentable=True) except Mediafile.DoesNotExist: raise SlideError context = { 'pdf': pdf, 'page_num': page_num, 'fullscreen': config['pdf_fullscreen'] } return render_to_string('mediafile/presentation_slide.html', context) register_slide('mediafile', mediafile_presentation_as_slide, Mediafile)
def test_register_slide(self): mock_slide_callback = {} with patch('openslides.projector.api.slide_callback', mock_slide_callback): projector_api.register_slide('some name', 'some callback') self.assertEqual(mock_slide_callback, {'some name': 'some callback'})
from .models import Category from .voting_system import Hoechstzahl, feed_hoechstzahls def category_slide_list(**kwargs): """ Slide to show an overview of all categories. """ context = {'category_list': Category.objects.all()} return render_to_string('openslides_topicvoting/category_slide_list.html', context) def result_slide(**kwargs): """ Slide to show a table with all voting results. The winning topics are given too. """ feed_hoechstzahls() result_table_and_info = Hoechstzahl.get_result_table_and_info() context = {'result_table': result_table_and_info['result_table'], 'winning_topics': result_table_and_info['winning_topics'], 'runoff_poll_warning': result_table_and_info['runoff_poll_warning'], 'topic_post_warning': result_table_and_info['topic_post_warning'], 'divisors': map(lambda rank: rank * 2 + 1, range(max(config['openslides_topicvoting_posts'], 3)))} return render_to_string('openslides_topicvoting/result_slide.html', context) register_slide_model(Category, 'openslides_topicvoting/category_slide.html') register_slide('topicvoting_category_list', category_slide_list) register_slide('topicvoting_result', result_slide)
from django.template.loader import render_to_string from openslides.config.api import config from openslides.projector.api import register_slide, SlideError from openslides.mediafile.models import Mediafile from .models import Video def openslides_video_presentation_as_slide(**kwargs): """ Return the html code for a presentation of a Mediafile. At the moment, only the presentation of pdfs is supported. """ file_pk = kwargs.get('pk', None) page_num = kwargs.get('page_num', 1) try: video = Mediafile.objects.get( pk=file_pk, filetype__in=Video.PRESENTABLE_VIDEO_TYPES, is_presentable=True) except Mediafile.DoesNotExist: raise SlideError context = {'video': video} return render_to_string('openslides_video/video_slide.html', context) register_slide('openslides_video', openslides_video_presentation_as_slide, Mediafile)
from django.template.loader import render_to_string from openslides.config.api import config from openslides.projector.api import register_slide, SlideError from .models import Mediafile def mediafile_presentation_as_slide(**kwargs): """ Return the html code for a presentation of a Mediafile. At the moment, only the presentation of pdfs is supported. """ file_pk = kwargs.get('pk', None) page_num = kwargs.get('page_num', 1) try: pdf = Mediafile.objects.get( pk=file_pk, filetype__in=Mediafile.PRESENTABLE_FILE_TYPES, is_presentable=True) except Mediafile.DoesNotExist: raise SlideError context = {'pdf': pdf, 'page_num': page_num, 'fullscreen': config['pdf_fullscreen']} return render_to_string('mediafile/presentation_slide.html', context) register_slide('mediafile', mediafile_presentation_as_slide, Mediafile)
def change_motionpoll_slide_template(): """ Overrides motion poll slide entry in the slide_callback dictionary. Raises OpenSlidesError if the former entry can not be found. """ if 'motionpoll' not in slide_callback: raise OpenSlidesError( 'Motion app was not properly loaded before loading ' 'openslides-votecollector. Please check you settings, particularly ' 'the INSTALLED_APPS.') def motionpoll_slide(**kwargs): """ Returns the html code for the motion poll slide """ # Get motion poll from url pattern argument slide_pk = kwargs.get('pk', None) try: slide = MotionPoll.objects.get(pk=slide_pk) except MotionPoll.DoesNotExist: raise SlideError else: # Get context of the slide context = slide.get_slide_context() # Generate seating plan with empty seats seating_plan = {} seats = Seat.objects.all() max_x_axis = seats.aggregate(Max('seating_plan_x_axis'))['seating_plan_x_axis__max'] max_y_axis = seats.aggregate(Max('seating_plan_y_axis'))['seating_plan_y_axis__max'] seating_plan['columns_number'] = max_x_axis seating_plan['width'] = '%dem' % (max_x_axis * 4) seating_plan['rows'] = [[None for j in range(max_x_axis)] for i in range(max_y_axis)] for seat in seats: seating_plan['rows'][seat.seating_plan_y_axis-1][seat.seating_plan_x_axis-1] = {'css': 'seat', 'number': seat.number} # Add votes to the seating plan and cummarize vote result all_keypad_votes = {'Y': 0, 'N': 0, 'A': 0} votes_with_seat = 0 votes_without_seat = 0 for keypad_data in context['poll'].keypad_data_list.select_related('keypad__seat'): all_keypad_votes[keypad_data.value] += 1 if keypad_data.keypad is not None and keypad_data.keypad.seat: x = keypad_data.keypad.seat.seating_plan_x_axis y = keypad_data.keypad.seat.seating_plan_y_axis seating_plan['rows'][y-1][x-1]['css'] += ' seat-%s' % keypad_data.get_css_value() votes_with_seat += 1 else: votes_without_seat += 1 votes_cast = all_keypad_votes['votes_cast'] = all_keypad_votes['Y'] + all_keypad_votes['N'] + all_keypad_votes['A'] # Add percent values if useful or set all_keypad_votes to None # which means that nobody has use a keypad to vote. if votes_cast: if config['motion_poll_100_percent_base'] == 'WITHOUT_INVALID': all_keypad_votes_percentage = {'Y': 0, 'N': 0, 'A': 0, 'votes_cast': 100} locale.setlocale(locale.LC_ALL, '') for item, votes in all_keypad_votes.items(): all_keypad_votes_percentage[item] = '%s' % locale.format('%.1f', votes * 100 / float(votes_cast)) all_keypad_votes_percentage[item+"_progress"] = '%.1f' % (votes * 100 / float(votes_cast)) else: if config['votecollector_in_vote']: all_keypad_votes = "{'Y': 0, 'N': 0, 'A': 0}" else: all_keypad_votes = None all_keypad_votes_percentage = None # Add all context data context['seating_plan'] = seating_plan context['all_keypad_votes'] = all_keypad_votes context['all_keypad_votes_percentage'] = all_keypad_votes_percentage context['votes_with_seat'] = votes_with_seat context['votes_without_seat'] = votes_without_seat return render_to_string('openslides_votecollector/motionpoll_slide.html', context) register_slide(MotionPoll.slide_callback_name, motionpoll_slide, MotionPoll)