From 2392c1ab3642bd4008bb2823ba48924a3ae96779 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Tue, 28 Jan 2014 08:32:26 +0100 Subject: [PATCH] Move projector.models.ProjectorSlide to core.models.CustomSlide --- fabfile.py | 3 +- .../agenda/templates/agenda/item_row.html | 4 +- .../agenda/templates/agenda/overview.html | 6 +-- openslides/agenda/templates/agenda/view.html | 4 +- openslides/agenda/widgets.py | 2 +- .../assignment/assignment_detail.html | 2 +- .../templates/assignment/assignment_list.html | 2 +- .../templates/assignment/poll_view.html | 2 +- openslides/assignment/widgets.py | 2 +- openslides/core/__init__.py | 2 +- openslides/core/main_menu.py | 2 +- openslides/core/models.py | 39 +++++++++++++++ openslides/core/slides.py | 7 +++ .../templates/core/customslide_slide.html} | 0 .../templates/core/customslide_update.html} | 0 .../templates/core/widget_customslide.html} | 2 +- openslides/core/urls.py | 16 +++++- openslides/core/views.py | 47 +++++++++++++++--- openslides/core/widgets.py | 28 ++++++++++- openslides/mediafile/widgets.py | 2 +- .../templates/motion/motion_detail.html | 2 +- .../motion/templates/motion/motion_list.html | 2 +- .../motion/templates/motion/poll_form.html | 2 +- openslides/motion/widgets.py | 2 +- openslides/participant/signals.py | 8 +-- .../templates/participant/group_detail.html | 2 +- .../templates/participant/group_overview.html | 2 +- .../templates/participant/overview.html | 2 +- .../templates/participant/user_detail.html | 2 +- openslides/participant/widgets.py | 4 +- openslides/projector/__init__.py | 2 +- openslides/projector/models.py | 35 ------------- openslides/projector/slides.py | 7 --- .../templates/projector/widget_live_view.html | 2 +- openslides/projector/urls.py | 12 ----- openslides/projector/views.py | 49 +++---------------- openslides/projector/widgets.py | 25 +--------- tests/core/test_views.py | 46 ++++++++++++++++- tests/participant/test_models.py | 4 +- tests/projector/test_views.py | 38 -------------- 40 files changed, 216 insertions(+), 204 deletions(-) create mode 100644 openslides/core/slides.py rename openslides/{projector/templates/projector/projectorslide_slide.html => core/templates/core/customslide_slide.html} (100%) rename openslides/{projector/templates/projector/new.html => core/templates/core/customslide_update.html} (100%) rename openslides/{projector/templates/projector/widget_custom_slide.html => core/templates/core/widget_customslide.html} (95%) delete mode 100644 openslides/projector/slides.py diff --git a/fabfile.py b/fabfile.py index ea4300a0a..41371c549 100644 --- a/fabfile.py +++ b/fabfile.py @@ -43,8 +43,7 @@ def check(): """ Checks for PEP 8 errors in openslides and in tests. """ - local('flake8 --max-line-length=150 --statistics openslides') - local('flake8 --max-line-length=150 --statistics tests') + local('flake8 --max-line-length=150 --statistics openslides tests') def prepare_commit(): diff --git a/openslides/agenda/templates/agenda/item_row.html b/openslides/agenda/templates/agenda/item_row.html index 0491e082d..8c850fa88 100644 --- a/openslides/agenda/templates/agenda/item_row.html +++ b/openslides/agenda/templates/agenda/item_row.html @@ -2,10 +2,10 @@ {% load tags %}
- {% if perms.agenda.can_manage_agenda or perms.projector.can_manage_projector %} + {% if perms.agenda.can_manage_agenda or perms.core.can_manage_projector %}
- {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/agenda/templates/agenda/overview.html b/openslides/agenda/templates/agenda/overview.html index f50b92c50..1002bedbe 100644 --- a/openslides/agenda/templates/agenda/overview.html +++ b/openslides/agenda/templates/agenda/overview.html @@ -79,7 +79,7 @@ {% if perms.agenda.can_see_orga_items %} {% trans "Duration" %} {% endif %} - {% if perms.agenda.can_manage_agenda or perms.projector.can_manage_projector %} + {% if perms.agenda.can_manage_agenda or perms.core.can_manage_projector %} {% trans "Actions" %} {% endif %} @@ -93,9 +93,9 @@ {% if perms.agenda.can_see_orga_items %} {{ duration }} h {% endif %} - {% if perms.agenda.can_manage_agenda or perms.projector.can_manage_projector %} + {% if perms.agenda.can_manage_agenda or perms.core.can_manage_projector %} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} {% trans "Back to overview" %} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} @@ -67,7 +67,7 @@ {% trans 'Close list' %} {% endif %} {% endif %} -{% if perms.projector.can_manage_projector %} +{% if perms.core.can_manage_projector %} diff --git a/openslides/agenda/widgets.py b/openslides/agenda/widgets.py index 666267863..06f5ff185 100644 --- a/openslides/agenda/widgets.py +++ b/openslides/agenda/widgets.py @@ -14,7 +14,7 @@ class AgendaWidget(Widget): """ name = 'agenda' verbose_name = ugettext_lazy('Agenda') - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' default_column = 1 default_weight = 20 template_name = 'agenda/widget_item.html' diff --git a/openslides/assignment/templates/assignment/assignment_detail.html b/openslides/assignment/templates/assignment/assignment_detail.html index a649663c9..2407e2e0d 100644 --- a/openslides/assignment/templates/assignment/assignment_detail.html +++ b/openslides/assignment/templates/assignment/assignment_detail.html @@ -22,7 +22,7 @@ {% trans "Back to overview" %} PDF - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/assignment/templates/assignment/assignment_list.html b/openslides/assignment/templates/assignment/assignment_list.html index 1ea6fb7d2..5466e5358 100644 --- a/openslides/assignment/templates/assignment/assignment_list.html +++ b/openslides/assignment/templates/assignment/assignment_list.html @@ -53,7 +53,7 @@ {{ object.get_status_display }} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/assignment/templates/assignment/poll_view.html b/openslides/assignment/templates/assignment/poll_view.html index 5de2d10cf..40e440c31 100644 --- a/openslides/assignment/templates/assignment/poll_view.html +++ b/openslides/assignment/templates/assignment/poll_view.html @@ -15,7 +15,7 @@ {% trans "Back to election" %} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/assignment/widgets.py b/openslides/assignment/widgets.py index 2f61d5c22..accbe9733 100644 --- a/openslides/assignment/widgets.py +++ b/openslides/assignment/widgets.py @@ -13,7 +13,7 @@ class AssignmentWidget(Widget): """ name = 'assignment' verbose_name = ugettext_lazy('Elections') - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' default_column = 1 default_weight = 50 template_name = 'assignment/widget_assignment.html' diff --git a/openslides/core/__init__.py b/openslides/core/__init__.py index 0c6390484..c57e8c26e 100644 --- a/openslides/core/__init__.py +++ b/openslides/core/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from . import main_menu, signals, widgets # noqa +from . import main_menu, signals, slides, widgets # noqa diff --git a/openslides/core/main_menu.py b/openslides/core/main_menu.py index e44425e51..e040ab165 100644 --- a/openslides/core/main_menu.py +++ b/openslides/core/main_menu.py @@ -10,7 +10,7 @@ class DashboardMainMenuEntry(MainMenuEntry): Main menu entry to the dashboard. """ verbose_name = ugettext_lazy('Dashboard') - permission_required = 'projector.can_see_dashboard' + permission_required = 'core.can_see_dashboard' default_weight = 10 icon_css_class = 'icon-home' pattern_name = 'core_dashboard' diff --git a/openslides/core/models.py b/openslides/core/models.py index e69de29bb..59ea883fa 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -0,0 +1,39 @@ +from django.core.urlresolvers import reverse +from django.db import models +from django.utils.translation import ugettext_lazy, ugettext_noop + +from openslides.utils.models import AbsoluteUrlMixin +from openslides.projector.models import SlideMixin + + +class CustomSlide(SlideMixin, AbsoluteUrlMixin, models.Model): + """ + Model for Slides, only for the projector. + """ + slide_callback_name = 'customslide' + + title = models.CharField(max_length=256, verbose_name=ugettext_lazy('Title')) + text = models.TextField(null=True, blank=True, verbose_name=ugettext_lazy('Text')) + weight = models.IntegerField(default=0, verbose_name=ugettext_lazy('Weight')) + + class Meta: + """ + General permissions that can not be placed at a specific app. + """ + permissions = ( + ('can_manage_projector', ugettext_noop('Can manage the projector')), + ('can_see_projector', ugettext_noop('Can see the projector')), + ('can_see_dashboard', ugettext_noop('Can see the dashboard')), + ) + + def __unicode__(self): + return self.title + + def get_absolute_url(self, link='update'): + if link == 'update': + url = reverse('customslide_update', args=[str(self.pk)]) + elif link == 'delete': + url = reverse('customslide_delete', args=[str(self.pk)]) + else: + url = super(CustomSlide, self).get_absolute_url(link) + return url diff --git a/openslides/core/slides.py b/openslides/core/slides.py new file mode 100644 index 000000000..c1d515116 --- /dev/null +++ b/openslides/core/slides.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +from openslides.projector.api import register_slide_model + +from .models import CustomSlide + +register_slide_model(CustomSlide, 'core/customslide_slide.html') diff --git a/openslides/projector/templates/projector/projectorslide_slide.html b/openslides/core/templates/core/customslide_slide.html similarity index 100% rename from openslides/projector/templates/projector/projectorslide_slide.html rename to openslides/core/templates/core/customslide_slide.html diff --git a/openslides/projector/templates/projector/new.html b/openslides/core/templates/core/customslide_update.html similarity index 100% rename from openslides/projector/templates/projector/new.html rename to openslides/core/templates/core/customslide_update.html diff --git a/openslides/projector/templates/projector/widget_custom_slide.html b/openslides/core/templates/core/widget_customslide.html similarity index 95% rename from openslides/projector/templates/projector/widget_custom_slide.html rename to openslides/core/templates/core/widget_customslide.html index 109ab0dfa..e74678a78 100644 --- a/openslides/projector/templates/projector/widget_custom_slide.html +++ b/openslides/core/templates/core/widget_customslide.html @@ -43,7 +43,7 @@
  • {% trans 'No items available.' %}
  • {% endfor %} -
    + {% trans 'New' %} {% endblock %} diff --git a/openslides/core/urls.py b/openslides/core/urls.py index b859ddeba..0fcde33b1 100644 --- a/openslides/core/urls.py +++ b/openslides/core/urls.py @@ -27,4 +27,18 @@ urlpatterns = patterns( url(r'^search/$', views.SearchView(), - name='core_search',)) + name='core_search',), + + # CustomSlide urls + url(r'^customslide/new/$', + views.CustomSlideCreateView.as_view(), + name='customslide_create'), + + url(r'^customslide/(?P\d+)/edit/$', + views.CustomSlideUpdateView.as_view(), + name='customslide_update'), + + url(r'^customslide/(?P\d+)/del/$', + views.CustomSlideDeleteView.as_view(), + name='customslide_delete'), +) diff --git a/openslides/core/views.py b/openslides/core/views.py index 219d6c85a..aa29fb08f 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -15,19 +15,20 @@ from openslides import get_git_commit_id, RELEASE from openslides.config.api import config from openslides.utils.plugins import get_plugin_description, get_plugin_verbose_name, get_plugin_version from openslides.utils.signals import template_manipulation -from openslides.utils.views import AjaxMixin, TemplateView, View +from openslides.utils import views as utils_views from openslides.utils.widgets import Widget from .forms import SelectWidgetsForm +from .models import CustomSlide -class DashboardView(AjaxMixin, TemplateView): +class DashboardView(utils_views.AjaxMixin, utils_views.TemplateView): """ Overview over all possible slides, the overlays and a live view: the Dashboard of OpenSlides. This main view uses the widget api to collect all widgets from all apps. See openslides.utils.widgets.Widget for more details. """ - permission_required = 'projector.can_see_dashboard' # TODO: Rename this to core.can_see_dashboard + permission_required = 'core.can_see_dashboard' template_name = 'core/dashboard.html' def get_context_data(self, **kwargs): @@ -42,13 +43,13 @@ class DashboardView(AjaxMixin, TemplateView): return context -class SelectWidgetsView(TemplateView): +class SelectWidgetsView(utils_views.TemplateView): """ Shows a form to select which widgets should be displayed on the own dashboard. The setting is saved in the session. """ # TODO: Use another base view class here, e. g. a FormView - permission_required = 'projector.can_see_dashboard' # TODO: Rename this to core.can_see_dashboard + permission_required = 'core.can_see_dashboard' template_name = 'core/select_widgets.html' def get_context_data(self, **kwargs): @@ -84,7 +85,7 @@ class SelectWidgetsView(TemplateView): return redirect(reverse('core_dashboard')) -class VersionView(TemplateView): +class VersionView(utils_views.TemplateView): """ Shows version infos. """ @@ -155,7 +156,7 @@ class SearchView(_SearchView): return models -class ErrorView(View): +class ErrorView(utils_views.View): """ View for Http 403, 404 and 500 error pages. """ @@ -180,3 +181,35 @@ class ErrorView(View): context_instance=RequestContext(request, context)) response.status_code = self.status_code return response + + +class CustomSlideViewMixin(object): + """ + Mixin for for CustomSlide Views. + """ + permission_required = 'core.can_manage_projector' + template_name = 'core/customslide_update.html' + model = CustomSlide + success_url_name = 'core_dashboard' + url_name_args = [] + + +class CustomSlideCreateView(CustomSlideViewMixin, utils_views.CreateView): + """ + Create a custom slide. + """ + pass + + +class CustomSlideUpdateView(CustomSlideViewMixin, utils_views.UpdateView): + """ + Update a custom slide. + """ + pass + + +class CustomSlideDeleteView(CustomSlideViewMixin, utils_views.DeleteView): + """ + Delete a custom slide. + """ + pass diff --git a/openslides/core/widgets.py b/openslides/core/widgets.py index acd0b2ff4..4f6571db1 100644 --- a/openslides/core/widgets.py +++ b/openslides/core/widgets.py @@ -1,16 +1,20 @@ # -*- coding: utf-8 -*- -from openslides.config.api import config +from django.utils.translation import ugettext_lazy +from openslides.config.api import config +from openslides.projector.api import get_active_slide from openslides.utils.widgets import Widget +from .models import CustomSlide + class WelcomeWidget(Widget): """ Welcome widget with static info for all users. """ name = 'welcome' - permission_required = 'projector.can_see_dashboard' + permission_required = 'core.can_see_dashboard' default_column = 1 default_weight = 10 template_name = 'core/widget_welcome.html' @@ -18,3 +22,23 @@ class WelcomeWidget(Widget): def get_verbose_name(self): return config['welcome_title'] + + +class CustonSlideWidget(Widget): + """ + Widget to control custom slides. + """ + name = 'custom_slide' + verbose_name = ugettext_lazy('Custom Slides') + permission_required = 'core.can_manage_projector' + default_column = 2 + default_weight = 30 + template_name = 'core/widget_customslide.html' + context = None + + def get_context_data(self, **context): + return super(CustonSlideWidget, self).get_context_data( + slides=CustomSlide.objects.all().order_by('weight'), + welcomepage_is_active=( + get_active_slide().get('callback', 'default') == 'default'), + **context) diff --git a/openslides/mediafile/widgets.py b/openslides/mediafile/widgets.py index 533a88a8b..b0e23b02e 100644 --- a/openslides/mediafile/widgets.py +++ b/openslides/mediafile/widgets.py @@ -14,7 +14,7 @@ class PDFPresentationWidget(Widget): """ name = 'presentations' verbose_name = ugettext_lazy('Presentations') - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' default_column = 1 default_weight = 75 template_name = 'mediafile/widget_pdfpresentation.html' diff --git a/openslides/motion/templates/motion/motion_detail.html b/openslides/motion/templates/motion/motion_detail.html index 626466244..3682b5df2 100644 --- a/openslides/motion/templates/motion/motion_detail.html +++ b/openslides/motion/templates/motion/motion_detail.html @@ -37,7 +37,7 @@ rel="tooltip" data-original-title="{% trans 'Print motion as PDF' %}" target="_blank"> PDF - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/motion/templates/motion/motion_list.html b/openslides/motion/templates/motion/motion_list.html index b30346051..768c18b37 100644 --- a/openslides/motion/templates/motion/motion_list.html +++ b/openslides/motion/templates/motion/motion_list.html @@ -78,7 +78,7 @@ {% endif %} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/motion/templates/motion/poll_form.html b/openslides/motion/templates/motion/poll_form.html index f72f9c97e..9e7fb5930 100644 --- a/openslides/motion/templates/motion/poll_form.html +++ b/openslides/motion/templates/motion/poll_form.html @@ -18,7 +18,7 @@
    {% trans "Back to motion" %} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/motion/widgets.py b/openslides/motion/widgets.py index 5e016fd68..73eb42c93 100644 --- a/openslides/motion/widgets.py +++ b/openslides/motion/widgets.py @@ -13,7 +13,7 @@ class MotionWidget(Widget): """ name = 'motion' verbose_name = ugettext_lazy('Motions') - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' default_column = 1 default_weight = 40 icon_css_class = 'icon-file' diff --git a/openslides/participant/signals.py b/openslides/participant/signals.py index c76387680..7664595b4 100644 --- a/openslides/participant/signals.py +++ b/openslides/participant/signals.py @@ -68,9 +68,9 @@ def create_builtin_groups_and_admin(sender, **kwargs): return # Anonymous and Registered - ct_projector = ContentType.objects.get(app_label='projector', model='projectorslide') - perm_1 = Permission.objects.get(content_type=ct_projector, codename='can_see_projector') - perm_2 = Permission.objects.get(content_type=ct_projector, codename='can_see_dashboard') + ct_core = ContentType.objects.get(app_label='core', model='customslide') + perm_1 = Permission.objects.get(content_type=ct_core, codename='can_see_projector') + perm_2 = Permission.objects.get(content_type=ct_core, codename='can_see_dashboard') ct_agenda = ContentType.objects.get(app_label='agenda', model='item') ct_speaker = ContentType.objects.get(app_label='agenda', model='speaker') @@ -110,7 +110,7 @@ def create_builtin_groups_and_admin(sender, **kwargs): perm_12 = Permission.objects.get(content_type=ct_motion, codename='can_manage_motion') perm_13 = Permission.objects.get(content_type=ct_assignment, codename='can_manage_assignment') perm_14 = Permission.objects.get(content_type=ct_participant, codename='can_manage_participant') - perm_15 = Permission.objects.get(content_type=ct_projector, codename='can_manage_projector') + perm_15 = Permission.objects.get(content_type=ct_core, codename='can_manage_projector') perm_15a = Permission.objects.get(content_type=ct_mediafile, codename='can_manage') ct_config = ContentType.objects.get(app_label='config', model='configstore') diff --git a/openslides/participant/templates/participant/group_detail.html b/openslides/participant/templates/participant/group_detail.html index 5b6fc9230..c62c5189e 100644 --- a/openslides/participant/templates/participant/group_detail.html +++ b/openslides/participant/templates/participant/group_detail.html @@ -11,7 +11,7 @@ {% trans "Back to overview" %} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/participant/templates/participant/group_overview.html b/openslides/participant/templates/participant/group_overview.html index 10c133214..67599f641 100644 --- a/openslides/participant/templates/participant/group_overview.html +++ b/openslides/participant/templates/participant/group_overview.html @@ -48,7 +48,7 @@ - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/participant/templates/participant/overview.html b/openslides/participant/templates/participant/overview.html index add2cd197..bd73e1e4d 100644 --- a/openslides/participant/templates/participant/overview.html +++ b/openslides/participant/templates/participant/overview.html @@ -108,7 +108,7 @@ - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/participant/templates/participant/user_detail.html b/openslides/participant/templates/participant/user_detail.html index 40f0925a0..6c37099cd 100644 --- a/openslides/participant/templates/participant/user_detail.html +++ b/openslides/participant/templates/participant/user_detail.html @@ -11,7 +11,7 @@ {% trans "Back to overview" %} - {% if perms.projector.can_manage_projector %} + {% if perms.core.can_manage_projector %} diff --git a/openslides/participant/widgets.py b/openslides/participant/widgets.py index c5bbefc63..d5f8f2fa4 100644 --- a/openslides/participant/widgets.py +++ b/openslides/participant/widgets.py @@ -14,7 +14,7 @@ class UserWidget(Widget): """ name = 'user' verbose_name = ugettext_lazy('Participants') - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' default_column = 1 default_weight = 60 default_active = False @@ -34,7 +34,7 @@ class GroupWidget(Widget): """ name = 'group' verbose_name = ugettext_lazy('Groups') - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' default_column = 1 default_weight = 70 default_active = False diff --git a/openslides/projector/__init__.py b/openslides/projector/__init__.py index 635921a8c..a5101f887 100644 --- a/openslides/projector/__init__.py +++ b/openslides/projector/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from . import signals, slides, widgets # noqa +from . import signals, widgets # noqa diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 35d5ecd4c..a9de923c8 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -2,10 +2,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse -from django.db import models -from django.utils.translation import ugettext_lazy, ugettext_noop -from openslides.utils.models import AbsoluteUrlMixin from openslides.utils.utils import int_or_none @@ -105,35 +102,3 @@ class SlideMixin(object): context.update({'slide': self, slide_name: self}) return context - - -class ProjectorSlide(SlideMixin, AbsoluteUrlMixin, models.Model): - """ - Model for Slides, only for the projector. Also called custom slides. - """ - # TODO: Rename it to CustomSlide and move it to core app. - # Check and rename permissions. - slide_callback_name = 'projector_slide' - - title = models.CharField(max_length=256, verbose_name=ugettext_lazy("Title")) - text = models.TextField(null=True, blank=True, verbose_name=ugettext_lazy("Text")) - weight = models.IntegerField(default=0, verbose_name=ugettext_lazy("Weight")) - - class Meta: - permissions = ( - ('can_manage_projector', ugettext_noop("Can manage the projector")), - ('can_see_projector', ugettext_noop("Can see the projector")), - ('can_see_dashboard', ugettext_noop("Can see the dashboard")), - ) - - def __unicode__(self): - return self.title - - def get_absolute_url(self, link='update'): - if link == 'update': - url = reverse('customslide_edit', args=[str(self.pk)]) - elif link == 'delete': - url = reverse('customslide_delete', args=[str(self.pk)]) - else: - url = super(ProjectorSlide, self).get_absolute_url(link) - return url diff --git a/openslides/projector/slides.py b/openslides/projector/slides.py deleted file mode 100644 index 54c0e8775..000000000 --- a/openslides/projector/slides.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- - -from openslides.projector.api import register_slide_model - -from .models import ProjectorSlide - -register_slide_model(ProjectorSlide, 'projector/projectorslide_slide.html') diff --git a/openslides/projector/templates/projector/widget_live_view.html b/openslides/projector/templates/projector/widget_live_view.html index fd94f219a..85af3a983 100644 --- a/openslides/projector/templates/projector/widget_live_view.html +++ b/openslides/projector/templates/projector/widget_live_view.html @@ -14,7 +14,7 @@ -{% if perms.projector.can_manage_projector %} +{% if perms.core.can_manage_projector %}

    diff --git a/openslides/projector/urls.py b/openslides/projector/urls.py index d9bc69d85..5689fbfc9 100644 --- a/openslides/projector/urls.py +++ b/openslides/projector/urls.py @@ -27,18 +27,6 @@ urlpatterns = patterns( views.OverlayMessageView.as_view(), name='projector_overlay_message'), - url(r'^new/$', - views.CustomSlideCreateView.as_view(), - name='customslide_new'), - - url(r'^(?P\d+)/edit/$', - views.CustomSlideUpdateView.as_view(), - name='customslide_edit'), - - url(r'^(?P\d+)/del/$', - views.CustomSlideDeleteView.as_view(), - name='customslide_delete'), - url(r'^bigger/$', views.ProjectorControllView.as_view(), {'direction': 'bigger'}, diff --git a/openslides/projector/views.py b/openslides/projector/views.py index fa84d2522..913165c0f 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -3,21 +3,19 @@ from openslides.config.api import config from openslides.mediafile.models import Mediafile from openslides.utils.tornado_webserver import ProjectorSocketHandler -from openslides.utils.views import (CreateView, DeleteView, - RedirectView, TemplateView, UpdateView) +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_projector_overlays_js, reset_countdown, set_active_slide, start_countdown, stop_countdown, update_projector_overlay) -from .models import ProjectorSlide class ProjectorView(TemplateView): """ The Projector-Page. """ - permission_required = 'projector.can_see_projector' + permission_required = 'core.can_see_projector' template_name = 'projector.html' def get_context_data(self, **kwargs): @@ -45,7 +43,7 @@ class ActivateView(RedirectView): """ Activate a Slide. """ - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' url_name = 'core_dashboard' allow_ajax = True @@ -72,7 +70,7 @@ class ProjectorControllView(RedirectView): """ Scale or scroll the projector. """ - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' url_name = 'core_dashboard' allow_ajax = True @@ -106,7 +104,7 @@ class CountdownControllView(RedirectView): """ Start, stop or reset the countdown. """ - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' url_name = 'core_dashboard' allow_ajax = True @@ -141,7 +139,7 @@ class OverlayMessageView(RedirectView): """ url_name = 'core_dashboard' allow_ajax = True - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' def pre_post_redirect(self, request, *args, **kwargs): if 'message' in request.POST: @@ -162,7 +160,7 @@ class ActivateOverlay(RedirectView): """ url_name = 'core_dashboard' allow_ajax = True - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' def pre_redirect(self, request, *args, **kwargs): overlay = get_overlays()[kwargs['name']] @@ -180,36 +178,3 @@ class ActivateOverlay(RedirectView): def get_ajax_context(self, **kwargs): return {'active': self.active, 'name': self.name} - - -class CustomSlideCreateView(CreateView): - """ - Create a custom slide. - """ - permission_required = 'agenda.can_manage_agenda' - template_name = 'projector/new.html' - model = ProjectorSlide - context_object_name = 'customslide' - success_url_name = 'core_dashboard' - url_name_args = [] - - -class CustomSlideUpdateView(UpdateView): - """ - Update a custom slide. - """ - permission_required = 'projector.can_manage_projector' - template_name = 'projector/new.html' - model = ProjectorSlide - context_object_name = 'customslide' - success_url_name = 'core_dashboard' - url_name_args = [] - - -class CustomSlideDeleteView(DeleteView): - """ - Delete a custom slide. - """ - permission_required = 'projector.can_manage_projector' - model = ProjectorSlide - success_url_name = 'core_dashboard' diff --git a/openslides/projector/widgets.py b/openslides/projector/widgets.py index 9d089d8a2..a4fc76e6f 100644 --- a/openslides/projector/widgets.py +++ b/openslides/projector/widgets.py @@ -3,10 +3,8 @@ from django.core.context_processors import csrf from django.utils.translation import ugettext_lazy -from openslides.projector.api import get_active_slide from openslides.utils.widgets import Widget -from .models import ProjectorSlide from .signals import projector_overlays @@ -16,7 +14,7 @@ class ProjectorLiveWidget(Widget): """ name = 'live_view' verbose_name = ugettext_lazy('Projector live view') - permission_required = 'projector.can_see_projector' + permission_required = 'core.can_see_projector' default_column = 2 default_weight = 10 template_name = 'projector/widget_live_view.html' @@ -28,7 +26,7 @@ class OverlayWidget(Widget): """ name = 'overlays' # TODO: Use singular here verbose_name = ugettext_lazy('Overlays') - permission_required = 'projector.can_manage_projector' + permission_required = 'core.can_manage_projector' default_column = 2 default_weight = 20 template_name = 'projector/widget_overlay.html' @@ -44,22 +42,3 @@ class OverlayWidget(Widget): return super(OverlayWidget, self).get_context_data( overlays=overlays, **context) - - -class CustonSlideWidget(Widget): - """ - Widget to control custom slides. - """ - name = 'custom_slide' - verbose_name = ugettext_lazy('Custom Slides') - permission_required = 'projector.can_manage_projector' - default_column = 2 - default_weight = 30 - template_name = 'projector/widget_custom_slide.html' - context = None - - def get_context_data(self, **context): - return super(CustonSlideWidget, self).get_context_data( - slides=ProjectorSlide.objects.all().order_by('weight'), - welcomepage_is_active=get_active_slide().get('callback', 'default') == 'default', - **context) diff --git a/tests/core/test_views.py b/tests/core/test_views.py index 6042730a1..eb7a1daf2 100644 --- a/tests/core/test_views.py +++ b/tests/core/test_views.py @@ -7,6 +7,7 @@ from openslides import get_version from openslides.agenda.models import Item from openslides.config.api import config from openslides.core import views +from openslides.core.models import CustomSlide from openslides.participant.models import User from openslides.utils.test import TestCase @@ -15,7 +16,7 @@ class SelectWidgetsViewTest(TestCase): rf = RequestFactory() @patch('openslides.core.views.SelectWidgetsForm') - @patch('openslides.core.views.TemplateView.get_context_data') + @patch('openslides.core.views.utils_views.TemplateView.get_context_data') @patch('openslides.core.views.Widget') def test_get_context_data(self, mock_Widget, mock_get_context_data, mock_SelectWidgetsForm): @@ -99,3 +100,46 @@ class SearchViewTest(TestCase): self.assertEqual(Client().get('/search/').status_code, 403) config['system_enable_anonymous'] = True self.assertEqual(Client().get('/search/').status_code, 200) + + +class CustomSlidesTest(TestCase): + def setUp(self): + self.admin_client = Client() + self.admin_client.login(username='admin', password='admin') + + def test_create(self): + url = '/customslide/new/' + response = self.admin_client.get(url) + self.assertTemplateUsed(response, 'core/customslide_update.html') + response = self.admin_client.post( + url, + {'title': 'test_title_roo2xi2EibooHie1kohd', 'weight': '0'}) + self.assertRedirects(response, '/dashboard/') + self.assertTrue(CustomSlide.objects.filter( + title='test_title_roo2xi2EibooHie1kohd').exists()) + + def test_update(self): + # Setup + url = '/customslide/1/edit/' + CustomSlide.objects.create(title='test_title_jeeDeB3aedei8ahceeso') + # Test + response = self.admin_client.get(url) + self.assertTemplateUsed(response, 'core/customslide_update.html') + self.assertContains(response, 'test_title_jeeDeB3aedei8ahceeso') + response = self.admin_client.post( + url, + {'title': 'test_title_ai8Ooboh5bahr6Ee7goo', 'weight': '0'}) + self.assertRedirects(response, '/dashboard/') + self.assertEqual(CustomSlide.objects.get(pk=1).title, + 'test_title_ai8Ooboh5bahr6Ee7goo') + + def test_delete(self): + # Setup + url = '/customslide/1/del/' + CustomSlide.objects.create(title='test_title_oyie0em1chieM7YohX4H') + # Test + response = self.admin_client.get(url) + self.assertRedirects(response, '/customslide/1/edit/') + response = self.admin_client.post(url, {'yes': 'true'}) + self.assertRedirects(response, '/dashboard/') + self.assertFalse(CustomSlide.objects.exists()) diff --git a/tests/participant/test_models.py b/tests/participant/test_models.py index 15671b236..9b2a0ae0d 100644 --- a/tests/participant/test_models.py +++ b/tests/participant/test_models.py @@ -82,8 +82,8 @@ class DefaultGroups(TestCase): def test_default_perms_anonymous(self): anonymous = Group.objects.get(pk=1) - default_perms = ('projector.can_see_projector', - 'projector.can_see_dashboard', + default_perms = ('core.can_see_projector', + 'core.can_see_dashboard', 'agenda.can_see_agenda', 'agenda.can_see_orga_items', 'motion.can_see_motion', diff --git a/tests/projector/test_views.py b/tests/projector/test_views.py index 6403814bb..e64261236 100644 --- a/tests/projector/test_views.py +++ b/tests/projector/test_views.py @@ -5,7 +5,6 @@ from django.test.client import Client, RequestFactory from mock import call, MagicMock, patch from openslides.config.api import config -from openslides.projector.models import ProjectorSlide from openslides.projector import views from openslides.utils.test import TestCase @@ -114,43 +113,6 @@ class ProjectorControllViewTest(TestCase): self.assertEqual(context, {'scale_level': 1, 'scroll_level': 2}) -class CustomSlidesTest(TestCase): - def setUp(self): - self.admin_client = Client() - self.admin_client.login(username='admin', password='admin') - - def test_create(self): - url = '/projector/new/' - response = self.admin_client.get(url) - self.assertTemplateUsed(response, 'projector/new.html') - response = self.admin_client.post(url, {'title': 'test_title_roo2xi2EibooHie1kohd', 'weight': '0'}) - self.assertRedirects(response, '/dashboard/') - self.assertTrue(ProjectorSlide.objects.filter(title='test_title_roo2xi2EibooHie1kohd').exists()) - - def test_update(self): - # Setup - url = '/projector/1/edit/' - ProjectorSlide.objects.create(title='test_title_jeeDeB3aedei8ahceeso') - # Test - response = self.admin_client.get(url) - self.assertTemplateUsed(response, 'projector/new.html') - self.assertContains(response, 'test_title_jeeDeB3aedei8ahceeso') - response = self.admin_client.post(url, {'title': 'test_title_ai8Ooboh5bahr6Ee7goo', 'weight': '0'}) - self.assertRedirects(response, '/dashboard/') - self.assertEqual(ProjectorSlide.objects.get(pk=1).title, 'test_title_ai8Ooboh5bahr6Ee7goo') - - def test_delete(self): - # Setup - url = '/projector/1/del/' - ProjectorSlide.objects.create(title='test_title_oyie0em1chieM7YohX4H') - # Test - response = self.admin_client.get(url) - self.assertRedirects(response, '/projector/1/edit/') - response = self.admin_client.post(url, {'yes': 'true'}) - self.assertRedirects(response, '/dashboard/') - self.assertFalse(ProjectorSlide.objects.exists()) - - class CountdownControllView(TestCase): def setUp(self): self.admin_client = Client()