Exemplo n.º 1
0
def admin(request):
    if User.superuser_exist():
        user = request.user
        if user.is_authenticated():
            messages.add_message(request, messages.ERROR,
                                 'Cannot initialize the application. System admin already exists.')
        return HttpResponseRedirect(reverse('index'))

    if request.method == 'POST':
        form = GrantAdminForm(request.POST)
        if form.is_valid():
            try:
                user = form.save(commit=False)
                user.is_active = True
                user.is_staff = True
                user.is_superuser = True
                user.save()
                messages.add_message(request, messages.SUCCESS, 'Admin privileges granted!')
                return HttpResponseRedirect(reverse('appsetup:index'))
            except (ValidationError, ) as e:
                messages.add_message(request, messages.ERROR, 'Failed to save user: %s' % e)
    else:
        form = GrantAdminForm()
    users = User.objects.all()
    return render(request, 'appsetup/admin.html',
                  {'form': form, 'users': users, 'current_dn': request.META['REMOTE_USER']}, )
Exemplo n.º 2
0
def index(request):
    show_admin = not User.superuser_exist()
    show_filesystems = FileSystem.can_setup(request.user)
    return render(request, 'appsetup/index.html', {'show_setup_admin': show_admin,
                                                   'show_setup_filesystems': show_filesystems,
    })