From 5b544ceed20de0e1d3d40deafe7caa24d5d5f584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Sch=C3=BCtze?= Date: Fri, 4 Nov 2016 13:26:44 +0100 Subject: [PATCH] Improve importing and sorting of users * Add is_present field for csv import of users. * Refactor JS functions get_full_name and get_short_name (Fixes #2136). - Show participant number in get_full_name() output. - Sort users by first or last name. - Extend config option to sort users. - Mark unused Python methods get_short_name and get_full_name. --- openslides/agenda/static/js/agenda/site.js | 5 +- openslides/users/config_variables.py | 14 +- openslides/users/models.py | 36 +--- openslides/users/pdf.py | 10 +- openslides/users/static/js/users/base.js | 58 +++--- openslides/users/static/js/users/site.js | 32 ++-- .../static/templates/users/user-import.html | 6 +- openslides/utils/search.py | 5 +- tests/unit/users/test_models.py | 170 +----------------- 9 files changed, 89 insertions(+), 247 deletions(-) diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index 49efc3f78..fa6b7d85f 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -442,7 +442,10 @@ angular.module('OpenSlidesApp.agenda.site', [ !item.speaker_list_closed && $.inArray(operator.user.id, nextUsers) == -1); case 'remove': - return ($.inArray(operator.user.id, nextUsers) != -1); + if (operator.user) { + return ($.inArray(operator.user.id, nextUsers) != -1); + } + return false; case 'removeAll': return (operator.hasPerms('agenda.can_manage') && $scope.speakers.length > 0); diff --git a/openslides/users/config_variables.py b/openslides/users/config_variables.py index 3d00f7895..72ea77f78 100644 --- a/openslides/users/config_variables.py +++ b/openslides/users/config_variables.py @@ -10,14 +10,16 @@ def get_config_variables(): """ # Sorting yield ConfigVariable( - name='users_sort_users_by_first_name', - default_value=False, - input_type='boolean', - label='Sort users by first name', - help_text='Disable for sorting by last name', + name='users_sort_by', + default_value='firstName', + input_type='choice', + label='Sort name of participants by', + choices=( + {'value': 'firstName', 'display_name': 'First name'}, + {'value': 'lastName', 'display_name': 'Last name'}), weight=510, group='Participants', - subgroup='Sorting') + subgroup='General') # PDF diff --git a/openslides/users/models.py b/openslides/users/models.py index e7a8fcf03..8273b98d4 100644 --- a/openslides/users/models.py +++ b/openslides/users/models.py @@ -13,7 +13,6 @@ from django.db.models import Q from openslides.utils.search import user_name_helper -from ..core.config import config from ..utils.models import RESTModelMixin from .access_permissions import UserAccessPermissions @@ -175,38 +174,13 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser): ordering = ('last_name', 'first_name', 'username', ) def __str__(self): - return self.get_full_name() - - def get_full_name(self): - """ - Returns a long form of the name. - - E. g.: * Dr. Max Mustermann (Villingen) - * Professor Dr. Enders, Christoph (Leipzig) - """ - structure = '(%s)' % self.structure_level if self.structure_level else '' - return ' '.join((self.title, self.get_short_name(), structure)).strip() - - def get_short_name(self, sort_by_first_name=None): - """ - Returns only the name of the user. - - E. g.: * Max Mustermann - * Enders, Christoph - """ # Strip white spaces from the name parts first_name = self.first_name.strip() last_name = self.last_name.strip() # The user has a last_name and a first_name if first_name and last_name: - if sort_by_first_name is None: - sort_by_first_name = config['users_sort_users_by_first_name'] - if sort_by_first_name: - name = ' '.join((first_name, last_name)) - else: - name = ', '.join((last_name, first_name)) - + name = ' '.join((self.first_name, self.last_name)) # The user has only a first_name or a last_name or no name else: name = first_name or last_name or self.username @@ -214,6 +188,14 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser): # Return result return name + # TODO: remove this function after PR#2476 is merged. (see Issue#2594) + def get_full_name(self): + return '' + + # TODO: remove this function after PR#2476 is merged. (see Issue#2594) + def get_short_name(self): + return '' + def get_search_index_string(self): """ Returns a string that can be indexed for the search. diff --git a/openslides/users/pdf.py b/openslides/users/pdf.py index d3a7555d7..8bdf84042 100644 --- a/openslides/users/pdf.py +++ b/openslides/users/pdf.py @@ -24,10 +24,7 @@ def users_to_pdf(pdf): Create a list of all users as PDF. """ data = [['#', _('Name'), _('Structure level'), _('Group')]] - if config['users_sort_users_by_first_name']: - sort = 'first_name' - else: - sort = 'last_name' + sort = 'first_name' counter = 0 for user in User.objects.all().order_by(sort): counter += 1 @@ -73,10 +70,7 @@ def users_passwords_to_pdf(pdf): users_pdf_welcometitle = config["users_pdf_welcometitle"] users_pdf_welcometext = config["users_pdf_welcometext"] - if config['users_sort_users_by_first_name']: - sort = 'first_name' - else: - sort = 'last_name' + sort = 'first_name' qrcode_size = 2 * cm # qrcode for system url qrcode_url = QrCodeWidget(users_pdf_url) diff --git a/openslides/users/static/js/users/base.js b/openslides/users/static/js/users/base.js index d4aa56b50..6eaaba27b 100644 --- a/openslides/users/static/js/users/base.js +++ b/openslides/users/static/js/users/base.js @@ -69,7 +69,8 @@ angular.module('OpenSlidesApp.users', []) 'Group', 'jsDataModel', 'gettext', - function(DS, Group, jsDataModel, gettext) { + 'Config', + function(DS, Group, jsDataModel, gettext, Config) { var name = 'users/user'; return DS.defineResource({ name: name, @@ -88,41 +89,54 @@ angular.module('OpenSlidesApp.users', []) getResourceName: function () { return name; }, + /* + * Returns a short form of the name. + * + * Example: + * - Dr. Max Mustermann + * - Professor Dr. Enders, Christoph + */ get_short_name: function() { - // should be the same as in the python user model. var title = _.trim(this.title), firstName = _.trim(this.first_name), lastName = _.trim(this.last_name), name = ''; - - if (title) { - name = title + ' '; - } - if (firstName && lastName) { - name += [firstName, lastName].join(' '); + if (Config.get('users_sort_by').value == 'lastName') { + if (lastName && firstName) { + name += [lastName, firstName].join(', '); + } else { + name += lastName || firstName; + } } else { - name += firstName || lastName || this.username; + name += [firstName, lastName].join(' '); + } + if (title !== '') { + name = title + ' ' + name; } return name; }, + /* + * Returns a long form of the name. + * + * Example: + * - Dr. Max Mustermann (Villingen) + * - Professor Dr. Enders, Christoph (Leipzig) + */ get_full_name: function() { - // should be the same as in the python user model. - var title = _.trim(this.title), - firstName = _.trim(this.first_name), - lastName = _.trim(this.last_name), + var name = this.get_short_name(), structure_level = _.trim(this.structure_level), - name = ''; + number = _.trim(this.number), + addition = []; - if (title) { - name = title + ' '; - } - if (firstName && lastName) { - name += [firstName, lastName].join(' '); - } else { - name += firstName || lastName || this.username; + // addition: add number and structure level + if (number) { + addition.push(number); } if (structure_level) { - name += " (" + structure_level + ")"; + addition.push(structure_level); + } + if (addition.length > 0) { + name += ' (' + addition.join(', ') + ')'; } return name; }, diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js index 525d356c1..22fdd0571 100644 --- a/openslides/users/static/js/users/site.js +++ b/openslides/users/static/js/users/site.js @@ -897,6 +897,17 @@ angular.module('OpenSlidesApp.users.site', [ } else { user.is_active = false; } + // is present + if (user.is_present) { + user.is_present = user.is_present.replace(quotionRe, '$1'); + if (user.is_present == '1') { + user.is_present = true; + } else { + user.is_present = false; + } + } else { + user.is_present = false; + } // is committee if (user.is_committee) { user.is_committee = user.is_committee.replace(quotionRe, '$1'); @@ -1016,12 +1027,12 @@ angular.module('OpenSlidesApp.users.site', [ var element = document.getElementById('downloadLink'); var csvRows = [ // column header line - ['title', 'first_name', 'last_name', 'structure_level', 'number', 'groups', 'comment', 'is_active', 'is_committee'], + ['title', 'first_name', 'last_name', 'structure_level', 'number', 'groups', 'comment', 'is_active', 'is_present', 'is_committee'], // example entries - ['Dr.', 'Max', 'Mustermann', 'Berlin','1234567890', '"3,4"', 'xyz', '1', ''], - ['', 'John', 'Doe', 'Washington','75/99/8-2', '3', 'abc', '1', ''], - ['', 'Fred', 'Bloggs', 'London', '', '', '', '', ''], - ['', '', 'Executive Board', '', '', '5', '', '', '1'], + ['Dr.', 'Max', 'Mustermann', 'Berlin','1234567890', '"3,4"', 'xyz', '1', '1', ''], + ['', 'John', 'Doe', 'Washington','75/99/8-2', '3', 'abc', '1', '1', ''], + ['', 'Fred', 'Bloggs', 'London', '', '', '', '', '', ''], + ['', '', 'Executive Board', '', '', '5', '', '', '', '1'], ]; var csvString = csvRows.join("%0A"); @@ -1373,14 +1384,15 @@ angular.module('OpenSlidesApp.users.site', [ gettext('Can manage users'); // config strings in users/config_variables.py - gettext('[Place for your welcome and help text.]'); - gettext('Sort users by first name'); - gettext('Disable for sorting by last name'); + gettext('General'); + gettext('Sort name of participants by'); gettext('Participants'); - gettext('Sorting'); + gettext('First name'); + gettext('Last name'); + gettext('PDF'); gettext('Welcome to OpenSlides'); gettext('Title for access data and welcome PDF'); - gettext('PDF'); + gettext('[Place for your welcome and help text.]'); gettext('Help text for access data and welcome PDF'); gettext('System URL'); gettext('Used for QRCode in PDF of access data.'); diff --git a/openslides/users/static/templates/users/user-import.html b/openslides/users/static/templates/users/user-import.html index c5b0e8f4d..dda506e74 100644 --- a/openslides/users/static/templates/users/user-import.html +++ b/openslides/users/static/templates/users/user-import.html @@ -68,7 +68,7 @@

Please note: