<commit_before>from subprocess import call

import batinfo
from django.conf import settings
from django.contrib import messages
from django.http import StreamingHttpResponse
from django.shortcuts import render
from django.utils.translation import ugettext as _

from ideascube.configuration import set_config
from ideascube.decorators import staff_member_required

from .backup import Backup
from .systemd import Manager, NoSuchUnit, UnitManagementError
from .wifi import (
    AvailableWifiNetwork, KnownWifiConnection, enable_wifi, WifiError)

# For unittesting purpose, we need to mock the Catalog class.
# However, the mock is made in a fixture and at this moment, we don't
# know where the mocked catalog will be used.
# So the fixture mocks 'ideascube.serveradmin.catalog.Catalog'.
# If we want to use the mocked Catalog here, we must not import the
# Catalog class directly but reference it from ideascube.serveradmin.catalog
# module.
from . import catalog as catalog_mod
from ideascube.configuration import get_config, set_config

@staff_member_required
def server_name(request):
    if request.method == 'POST':
        new_name = request.POST.get('server_name')

        if new_name:
            set_config('server', 'site-name', new_name, request.user)

        else:
            messages.error(request, _('Server name cannot be empty'))

    return render(request, 'serveradmin/name.html')

<commit_msg>admin: Notify after changing the server name<commit_after>from subprocess import call

import batinfo
from django.conf import settings
from django.contrib import messages
from django.http import StreamingHttpResponse
from django.shortcuts import render
from django.utils.translation import ugettext as _

from ideascube.configuration import set_config
from ideascube.decorators import staff_member_required

from .backup import Backup
from .systemd import Manager, NoSuchUnit, UnitManagementError
from .wifi import (
    AvailableWifiNetwork, KnownWifiConnection, enable_wifi, WifiError)

# For unittesting purpose, we need to mock the Catalog class.
# However, the mock is made in a fixture and at this moment, we don't
# know where the mocked catalog will be used.
# So the fixture mocks 'ideascube.serveradmin.catalog.Catalog'.
# If we want to use the mocked Catalog here, we must not import the
# Catalog class directly but reference it from ideascube.serveradmin.catalog
# module.
from . import catalog as catalog_mod
from ideascube.configuration import get_config, set_config

@staff_member_required
def server_name(request):
    if request.method == 'POST':
        new_name = request.POST.get('server_name')

        if new_name:
            set_config('server', 'site-name', new_name, request.user)
            messages.success(request, _('Server name changed successfully'))

        else:
            messages.error(request, _('Server name cannot be empty'))

    return render(request, 'serveradmin/name.html')


{'fraction_non_alphanumeric': 0.06564625850340136, 'fraction_numerical': 0.0, 'mean_word_length': 4.456400742115028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7033783', 'n_tokens_mistral': 796, 'n_tokens_neox': 778, 'n_words': 305}