Пример #1
0
def update(request, user_id):
    if request.method == "POST":
        tenants = api.tenant_list(request)
        form = UserForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            updated = []
            if user['email']:
                updated.append('email')
                api.user_update_email(request, user['id'], user['email'])
            if user['password']:
                updated.append('password')
                api.user_update_password(request, user['id'], user['password'])
            if user['tenant_id']:
                updated.append('tenant')
                api.user_update_tenant(request, user['id'], user['tenant_id'])
            messages.success(
                request, 'Updated %s for %s.' % (', '.join(updated), user_id))
            return redirect('syspanel_users')
        else:
            # TODO add better error management
            messages.error(
                request, 'Unable to update user,\
                                    please try again.')

            return render_to_response(
                'django_openstack/syspanel/users/update.html', {
                    'form': form,
                    'user_id': user_id,
                },
                context_instance=template.RequestContext(request))

    else:
        u = api.user_get(request, user_id)
        tenants = api.tenant_list(request)
        try:
            # FIXME
            email = u.email
        except:
            email = ''

        try:
            tenant_id = u.tenantId
        except:
            tenant_id = None
        form = UserForm(initial={
            'id': user_id,
            'tenant_id': tenant_id,
            'email': email
        },
                        tenant_list=tenants)
        return render_to_response(
            'django_openstack/syspanel/users/update.html', {
                'form': form,
                'user_id': user_id,
            },
            context_instance=template.RequestContext(request))
Пример #2
0
def update(request, user_id):
    if request.method == "POST":
        tenants = api.tenant_list(request)
        form = UserForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            updated = []
            if user['email']:
                updated.append('email')
                api.user_update_email(request, user['id'], user['email'])
            if user['password']:
                updated.append('password')
                api.user_update_password(request, user['id'], user['password'])
            if user['tenant_id']:
                updated.append('tenant')
                api.user_update_tenant(request, user['id'], user['tenant_id'])
            messages.success(request,
                             'Updated %s for %s.'
                             % (', '.join(updated), user_id))
            return redirect('syspanel_users')
        else:
            # TODO add better error management
            messages.error(request, 'Unable to update user,\
                                    please try again.')

            return render_to_response(
            'syspanel_user_update.html',{
                'form': form,
                'user_id': user_id,
            }, context_instance = template.RequestContext(request))

    else:
        u = api.user_get(request, user_id)
        tenants = api.tenant_list(request)
        try:
            # FIXME
            email = u.email
        except:
            email = ''

        try:
            tenant_id = u.tenantId
        except:
            tenant_id = None
        form = UserForm(initial={'id': user_id,
                                 'tenant_id': tenant_id,
                                 'email': email},
                                 tenant_list=tenants)
        return render_to_response(
        'syspanel_user_update.html',{
            'form': form,
            'user_id': user_id,
        }, context_instance = template.RequestContext(request))
Пример #3
0
def update(request, user_id):
    if request.method == "POST":
        tenants = api.tenant_list(request)
        form = UserForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            updated = []
            if user["email"]:
                updated.append("email")
                api.user_update_email(request, user["id"], user["email"])
            if user["password"]:
                updated.append("password")
                api.user_update_password(request, user["id"], user["password"])
            if user["tenant_id"]:
                updated.append("tenant")
                api.user_update_tenant(request, user["id"], user["tenant_id"])
            messages.success(request, "Updated %s for %s." % (", ".join(updated), user_id))
            return redirect("syspanel_users")
        else:
            # TODO add better error management
            messages.error(
                request,
                "Unable to update user,\
                                    please try again.",
            )

            return render_to_response(
                "syspanel_user_update.html",
                {"form": form, "user_id": user_id},
                context_instance=template.RequestContext(request),
            )

    else:
        u = api.user_get(request, user_id)
        tenants = api.tenant_list(request)
        try:
            # FIXME
            email = u.email
        except:
            email = ""

        try:
            tenant_id = u.tenantId
        except:
            tenant_id = None
        form = UserForm(initial={"id": user_id, "tenant_id": tenant_id, "email": email}, tenant_list=tenants)
        return render_to_response(
            "syspanel_user_update.html",
            {"form": form, "user_id": user_id},
            context_instance=template.RequestContext(request),
        )
Пример #4
0
def update(request, user_id):
    if request.method == "POST":
        tenants = api.tenant_list(request)
        form = UserUpdateForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            updated = []
            if user['email']:
                updated.append('email')
                api.user_update_email(request, user['id'], user['email'])
            if user['password']:
                updated.append('password')
                api.user_update_password(request, user['id'], user['password'])
            if user['tenant_id']:
                updated.append('tenant')
                api.user_update_tenant(request, user['id'], user['tenant_id'])
            messages.success(
                request,
                _('Updated %(attrib)s for %(user)s.') % {
                    "attrib": ', '.join(updated),
                    "user": user_id
                })
            return redirect('syspanel_users')
        else:
            # TODO add better error management
            messages.error(request,
                           _('Unable to update user, please try again.'))

            return render_to_response(
                'django_openstack/syspanel/users/update.html', {
                    'form': form,
                    'user_id': user_id,
                },
                context_instance=template.RequestContext(request))

    else:
        u = api.user_get(request, user_id)
        tenants = api.tenant_list(request)
        form = UserUpdateForm(tenant_list=tenants,
                              initial={
                                  'id': user_id,
                                  'tenant_id': getattr(u, 'tenantId', None),
                                  'email': getattr(u, 'email', '')
                              })
        return render_to_response(
            'django_openstack/syspanel/users/update.html', {
                'form': form,
                'user_id': user_id,
            },
            context_instance=template.RequestContext(request))
Пример #5
0
def update(request, user_id):
    if request.method == "POST":
        tenants = api.tenant_list(request)
        form = UserUpdateForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            updated = []
            if user['email']:
                updated.append('email')
                api.user_update_email(request, user['id'], user['email'])
            if user['password']:
                updated.append('password')
                api.user_update_password(request, user['id'], user['password'])
            if user['tenant_id']:
                updated.append('tenant')
                api.user_update_tenant(request, user['id'], user['tenant_id'])
            messages.success(request,
                             _('Updated %(attrib)s for %(user)s.') %
                             {"attrib": ', '.join(updated), "user": user_id})
            return redirect('syspanel_users')
        else:
            # TODO add better error management
            messages.error(request,
                           _('Unable to update user, please try again.'))

            return render_to_response(
            'django_openstack/syspanel/users/update.html', {
                'form': form,
                'user_id': user_id,
            }, context_instance=template.RequestContext(request))

    else:
        user = api.user_get(request, user_id)
        tenants = api.tenant_list(request)
        form = UserUpdateForm(tenant_list=tenants,
                              initial={'id': user_id,
                                       'tenant_id': getattr(user,
                                                            'tenantId',
                                                            None),
                                       'email': getattr(user, 'email', '')})
        return render_to_response(
        'django_openstack/syspanel/users/update.html', {
            'form': form,
            'user_id': user_id,
        }, context_instance=template.RequestContext(request))
Пример #6
0
    def test_user_update_password(self):
        account_api = self.stub_account_api()
        account_api.users = self.mox.CreateMockAnything()
        account_api.users.update_password(TEST_USERNAME, TEST_PASSWORD).AndReturn(TEST_RETURN)

        self.mox.ReplayAll()

        ret_val = api.user_update_password(self.request, TEST_USERNAME, TEST_PASSWORD)

        self.assertIsInstance(ret_val, api.User)
        self.assertEqual(ret_val._apiresource, TEST_RETURN)

        self.mox.VerifyAll()