2013-03-01 17:13:12 +01:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""
|
|
|
|
|
openslides.core.views
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Views for the core app.
|
|
|
|
|
|
|
|
|
|
:copyright: 2011–2013 by OpenSlides team, see AUTHORS.
|
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from django.conf import settings
|
2013-09-08 14:44:41 +02:00
|
|
|
|
from django.core.exceptions import PermissionDenied
|
2013-03-01 17:13:12 +01:00
|
|
|
|
from django.utils.importlib import import_module
|
2013-09-08 14:44:41 +02:00
|
|
|
|
from haystack.views import SearchView as _SearchView
|
2013-03-01 17:13:12 +01:00
|
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
|
from openslides import get_git_commit_id, get_version, RELEASE
|
2013-09-08 14:44:41 +02:00
|
|
|
|
from openslides.utils.signals import template_manipulation
|
2013-03-01 17:13:12 +01:00
|
|
|
|
from openslides.utils.views import TemplateView
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VersionView(TemplateView):
|
|
|
|
|
"""
|
2013-05-11 14:27:46 +02:00
|
|
|
|
Shows version infos.
|
2013-03-01 17:13:12 +01:00
|
|
|
|
"""
|
|
|
|
|
template_name = 'core/version.html'
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Adds version strings to the context.
|
|
|
|
|
"""
|
|
|
|
|
context = super(VersionView, self).get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
|
# OpenSlides version. During development the git commit id is added.
|
|
|
|
|
openslides_version_string = get_version()
|
|
|
|
|
if not RELEASE:
|
2013-05-11 14:27:46 +02:00
|
|
|
|
openslides_version_string += ' – Commit %s' % get_git_commit_id()
|
2013-03-01 17:13:12 +01:00
|
|
|
|
context['versions'] = [('OpenSlides', openslides_version_string)]
|
|
|
|
|
|
|
|
|
|
# Versions of plugins.
|
|
|
|
|
for plugin in settings.INSTALLED_PLUGINS:
|
2013-05-11 14:27:46 +02:00
|
|
|
|
# Get plugin
|
2013-03-01 17:13:12 +01:00
|
|
|
|
try:
|
|
|
|
|
mod = import_module(plugin)
|
2013-05-11 14:27:46 +02:00
|
|
|
|
except ImportError:
|
2013-03-01 17:13:12 +01:00
|
|
|
|
continue
|
2013-05-11 14:27:46 +02:00
|
|
|
|
|
|
|
|
|
# Get version.
|
2013-03-01 17:13:12 +01:00
|
|
|
|
try:
|
2013-05-11 14:27:46 +02:00
|
|
|
|
plugin_version = mod.get_version()
|
2013-03-01 17:13:12 +01:00
|
|
|
|
except AttributeError:
|
2013-05-11 14:27:46 +02:00
|
|
|
|
try:
|
|
|
|
|
plugin_version = mod.VERSION
|
|
|
|
|
except AttributeError:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Get name.
|
|
|
|
|
try:
|
|
|
|
|
plugin_name = mod.get_name()
|
|
|
|
|
except AttributeError:
|
|
|
|
|
try:
|
|
|
|
|
plugin_name = mod.NAME
|
|
|
|
|
except AttributeError:
|
|
|
|
|
plugin_name = mod.__name__.split('.')[0]
|
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
|
context['versions'].append((plugin_name, plugin_version))
|
|
|
|
|
|
|
|
|
|
return context
|
2013-09-08 14:44:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchView(_SearchView):
|
|
|
|
|
"""
|
|
|
|
|
Shows search result page.
|
|
|
|
|
"""
|
|
|
|
|
template = 'core/search.html'
|
|
|
|
|
|
|
|
|
|
def __call__(self, request):
|
|
|
|
|
if not request.user.is_authenticated():
|
|
|
|
|
raise PermissionDenied
|
|
|
|
|
return super(SearchView, self).__call__(request)
|
|
|
|
|
|
|
|
|
|
def extra_context(self):
|
|
|
|
|
"""
|
|
|
|
|
Adds extra context variables to set navigation and search filter.
|
|
|
|
|
|
|
|
|
|
Returns a context dictionary.
|
|
|
|
|
"""
|
|
|
|
|
context = {}
|
|
|
|
|
template_manipulation.send(
|
|
|
|
|
sender=self.__class__, request=self.request, context=context)
|
|
|
|
|
context['models'] = self.get_indexed_searchmodels()
|
|
|
|
|
context['get_values'] = self.request.GET.getlist('models')
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
def get_indexed_searchmodels(self):
|
|
|
|
|
"""
|
|
|
|
|
Iterate over all INSTALLED_APPS and return a list of models which are
|
|
|
|
|
indexed by haystack/whoosh for using in customized model search filter
|
|
|
|
|
in search template search.html. Each list entry contains a verbose name
|
|
|
|
|
of the model and a special form field value for haystack (app_name.model_name),
|
|
|
|
|
e.g. ['Agenda', 'agenda.item'].
|
|
|
|
|
"""
|
|
|
|
|
models = []
|
|
|
|
|
# TODO: cache this query!
|
|
|
|
|
for app in settings.INSTALLED_APPS:
|
|
|
|
|
try:
|
|
|
|
|
module = import_module(app + '.search_indexes')
|
|
|
|
|
except ImportError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
models.append([module.Index.modelfilter_name, module.Index.modelfilter_value])
|
|
|
|
|
return models
|