def settings_advanced(request, event_url_name):
    event = get_object_or_404(Event, url_name=event_url_name)

    # check permission
    if not has_access(request.user, event, ACCESS_BADGES_EDIT):
        return nopermission(request)

    # check if badge system is active
    if not event.badges:
        return notactive(request)

    # form for settings
    form = BadgeSettingsForm(request.POST or None, request.FILES or None,
                             instance=event.badge_settings)

    # for for permissions
    permissions = event.badge_settings.badgepermission_set.all()

    if form.is_valid():
        form.save()

        return redirect('badges:settings_advanced', event_url_name=event.url_name)

    # render
    context = {'event': event,
               'form': form,
               'permissions': permissions}
    return render(request, 'badges/settings_advanced.html',
                  context)