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))
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))
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), )
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))
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)
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')
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))
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)
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)
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)
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()
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) )
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'],
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)
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)