Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow setting name format per event
closes #2455
  • Loading branch information
mvidalgarcia committed May 15, 2019
1 parent 896b786 commit 0628d3d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions indico/modules/events/layout/__init__.py
Expand Up @@ -12,10 +12,12 @@

from indico.core import signals
from indico.core.logger import Logger
from indico.core.settings.converters import EnumConverter
from indico.modules.events.features.base import EventFeature
from indico.modules.events.logs import EventLogKind, EventLogRealm
from indico.modules.events.models.events import EventType
from indico.modules.events.settings import EventSettingsProxy, ThemeSettingsProxy
from indico.modules.users import NameFormat
from indico.util.i18n import _
from indico.web.flask.util import url_for
from indico.web.menu import SideMenuItem
Expand All @@ -26,6 +28,7 @@
'is_searchable': True,
'show_nav_bar': True,
'show_social_badges': True,
'name_format': None,
'show_banner': False,
'header_text_color': '',
'header_background_color': '',
Expand All @@ -38,6 +41,8 @@
'use_custom_menu': False,
'timetable_by_room': False,
'timetable_detailed': False,
}, converters={
'name_format': EnumConverter(NameFormat)
})

theme_settings = ThemeSettingsProxy()
Expand Down
7 changes: 6 additions & 1 deletion indico/modules/events/layout/forms.py
Expand Up @@ -15,9 +15,10 @@
from indico.core.config import config
from indico.modules.events.layout import theme_settings
from indico.modules.events.layout.util import get_css_file_data, get_logo_data, get_plugin_conference_themes
from indico.modules.users import NameFormat
from indico.util.i18n import _
from indico.web.forms.base import IndicoForm
from indico.web.forms.fields import EditableFileField, FileField
from indico.web.forms.fields import EditableFileField, FileField, IndicoEnumSelectField
from indico.web.forms.validators import HiddenUnless, UsedIf
from indico.web.forms.widgets import CKEditorWidget, ColorPickerWidget, SwitchWidget

Expand Down Expand Up @@ -46,6 +47,8 @@ class ConferenceLayoutForm(IndicoForm):
show_banner = BooleanField(_("\"Now happening\""), widget=SwitchWidget(on_label=_("ON"), off_label=_("OFF")),
description=_("Show a banner with the current entries from the timetable"))
show_social_badges = BooleanField(_("Show social badges"), widget=SwitchWidget())
name_format = IndicoEnumSelectField(_('Name format'), enum=NameFormat, none=_('Inherit from user preferences'),
description=_('Format in which names are displayed'))

# Style
header_text_color = StringField(_("Text colour"), widget=ColorPickerWidget())
Expand Down Expand Up @@ -85,6 +88,8 @@ def validate_use_custom_css(self, field):


class LectureMeetingLayoutForm(IndicoForm):
name_format = IndicoEnumSelectField(_('Name format'), enum=NameFormat, none=_('Inherit from user preferences'),
description=_('Format in which names are displayed'))
timetable_theme = SelectField(_('Timetable theme'), [DataRequired()])

def __init__(self, *args, **kwargs):
Expand Down
Expand Up @@ -9,7 +9,8 @@
{%- block content %}
{% call simple_form(form, save_reminder=true, back_button=false) %}
{% call form_fieldset(_('General')) %}
{{ form_rows(form, fields=('is_searchable', 'show_nav_bar', 'show_banner', 'show_social_badges')) }}
{{ form_rows(form, fields=('is_searchable', 'show_nav_bar', 'show_banner', 'show_social_badges',
'name_format')) }}
{% endcall %}
{% call form_fieldset(_('Header Style')) %}
{{ form_rows(form, fields=('header_text_color', 'header_background_color')) }}
Expand Down
7 changes: 5 additions & 2 deletions indico/modules/users/models/users.py
Expand Up @@ -10,7 +10,7 @@
import itertools
from operator import attrgetter

from flask import flash, has_request_context, session
from flask import flash, g, has_request_context, session
from flask_multipass import IdentityRetrievalFailed
from sqlalchemy.event import listens_for
from sqlalchemy.ext.associationproxy import association_proxy
Expand Down Expand Up @@ -131,7 +131,10 @@ def display_full_name(self):


def format_display_full_name(user, obj):
name_format = user.settings.get('name_format') if user else NameFormat.first_last
from indico.modules.events.layout import layout_settings
name_format = layout_settings.get(g.rh.event, 'name_format') if 'rh' in g and hasattr(g.rh, 'event') else None
if name_format is None:
name_format = user.settings.get('name_format') if user else NameFormat.first_last
upper = name_format in (NameFormat.first_last_upper, NameFormat.f_last_upper, NameFormat.last_f_upper,
NameFormat.last_first_upper)
if name_format in (NameFormat.first_last, NameFormat.first_last_upper):
Expand Down

0 comments on commit 0628d3d

Please sign in to comment.