コード例 #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
ファイル: users.py プロジェクト: Lezval/horizon
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 index(request):
    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        LOG.error('ApiException while getting tenant list', exc_info=True)
        messages.error(request, 'Unable to get tenant info: %s' % e.message)
コード例 #6
0
def create(request):
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        messages.error(request,
                       'Unable to retrieve tenant list: %s' % e.message)
        return redirect('syspanel_users')
コード例 #7
0
def index(request):
    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        LOG.error('ApiException while getting tenant list', exc_info=True)
        messages.error(request, 'Unable to get tenant info: %s' % e.message)
コード例 #8
0
ファイル: users.py プロジェクト: ashokcse/openstack-bill
def create(request):
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        messages.error(request, 'Unable to retrieve tenant list: %s' %
                                 e.message)
        return redirect('syspanel_users')
コード例 #9
0
ファイル: users.py プロジェクト: bcloudteam/horizon
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))
コード例 #10
0
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while getting tenant list')
        messages.error(request, _('Unable to get tenant info: %s') % e.message)
コード例 #11
0
ファイル: tenants.py プロジェクト: Lezval/horizon
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while getting tenant list')
        messages.error(request, _('Unable to get tenant info: %s') % e.message)
コード例 #12
0
ファイル: tenants.py プロジェクト: ashokcse/openstack-bill
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
    	for tenant in tenants :
		LOG.info('---tenetnt----%s   ' %tenant.__dict__)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while getting tenant list')
        messages.error(request, 'Unable to get tenant info: %s' % e.message)
コード例 #13
0
ファイル: tenants.py プロジェクト: young8/openstack-bill
def index(request):
    form, handled = DeleteTenant.maybe_handle(request)
    if handled:
        return handled

    tenant_delete_form = DeleteTenant()

    tenants = []
    try:
        tenants = api.tenant_list(request)
        for tenant in tenants:
            LOG.info('---tenetnt----%s   ' % tenant.__dict__)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while getting tenant list')
        messages.error(request, 'Unable to get tenant info: %s' % e.message)
コード例 #14
0
    def test_tenant_list(self):
        tenants = (TEST_RETURN, TEST_RETURN + "2")

        account_api = self.stub_account_api()

        account_api.tenants = self.mox.CreateMockAnything()
        account_api.tenants.list().AndReturn(tenants)

        self.mox.ReplayAll()

        ret_val = api.tenant_list(self.request)

        self.assertEqual(len(ret_val), len(tenants))
        for tenant in ret_val:
            self.assertIsInstance(tenant, api.Tenant)
            self.assertIn(tenant._apiresource, tenants)

        self.mox.VerifyAll()
コード例 #15
0
def create(request):
    tenants = api.tenant_list(request)

    if request.method == "POST":
        form = UserForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            # TODO Make this a real request
            try:
                api.user_create(request, user["id"], user["email"], user["password"], user["tenant_id"], True)

                messages.success(request, "%s was successfully created." % user["id"])
                return redirect("syspanel_users")

            except api_exceptions.ApiException, e:
                messages.error(request, "Error creating user: %s" % e.message)
                return redirect("syspanel_users")
        else:
            return render_to_response(
                "syspanel_user_create.html", {"form": form}, context_instance=template.RequestContext(request)
            )
コード例 #16
0
def create(request):
	
	  (date_start, date_end, datetime_start, datetime_end) = \
            _get_start_and_end_date(request)

     if date_start > _current_month():
        messages.error(request, 'No bill unit can be changed for previous months')
        date_end = date_end
        datetime_end = datetime_end


    dateform = forms.DateForm()
    dateform['date'].field.initial = date_end
    
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        messages.error(request, 'Unable to retrieve tenant list: %s' %
                                 e.message)
        return redirect('syspanel_bills')


    if request.method == "POST":
        form = BillForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            # TODO Make this a real request
            try:
                LOG.info('Creating user with name "%s"' % user['name'])
                new_user = api.user_create(request,
                                           user['name'],
コード例 #17
0
 def _check_tenant_all_bill(self):
     tenants = api.tenant_list(self.request)
     LOG.debug("Checking tenant bill")
     #TODO (nati) This code is slow. FIX this later
     for tenant in tenants:
         self._check_tenant_bill(tenant.id)
コード例 #18
0
def index(request):
    tenants = []
    try:
        tenants = api.tenant_list(request)
    except api_exceptions.ApiException, e:
        messages.error(request, 'Unable to get tenant info: %s' % e.message)
コード例 #19
0
ファイル: manager.py プロジェクト: jaypipes/dash_billing
 def _check_tenant_all_bill(self):
     tenants = api.tenant_list(self.request)
     LOG.debug("Checking tenant bill")
     #TODO (nati) This code is slow. FIX this later 
     for tenant in tenants:
        self._check_tenant_bill(tenant.id)