2015-02-18 01:45:39 +01:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from openslides.core.exceptions import ProjectorException
|
2015-06-12 21:08:57 +02:00
|
|
|
from openslides.utils.projector import ProjectorElement, ProjectorRequirement
|
2015-02-18 01:45:39 +01:00
|
|
|
|
|
|
|
from .models import User
|
2015-06-12 21:08:57 +02:00
|
|
|
from .views import GroupViewSet, UserViewSet
|
2015-02-18 01:45:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
class UserSlide(ProjectorElement):
|
|
|
|
"""
|
|
|
|
Slide definitions for user model.
|
|
|
|
"""
|
|
|
|
name = 'users/user'
|
|
|
|
scripts = 'users/user_slide.js'
|
|
|
|
|
|
|
|
def get_context(self):
|
|
|
|
pk = self.config_entry.get('id')
|
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=pk)
|
|
|
|
except User.DoesNotExist:
|
|
|
|
raise ProjectorException(_('User does not exist.'))
|
|
|
|
result = [{
|
|
|
|
'collection': 'users/user',
|
|
|
|
'id': pk}]
|
|
|
|
for group in user.groups.all():
|
|
|
|
result.append({
|
|
|
|
'collection': 'users/group',
|
|
|
|
'id': group.pk})
|
|
|
|
return result
|
2015-06-12 21:08:57 +02:00
|
|
|
|
|
|
|
def get_requirements(self, config_entry):
|
|
|
|
self.config_entry = config_entry
|
|
|
|
try:
|
|
|
|
context = self.get_context()
|
|
|
|
except ProjectorException:
|
|
|
|
# User does not exist so just do nothing.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for item in context:
|
|
|
|
yield ProjectorRequirement(
|
|
|
|
view_class=UserViewSet if item['collection'] == 'users/user' else GroupViewSet,
|
|
|
|
view_action='retrieve',
|
|
|
|
pk=str(item['id']))
|