def fillup_db(): DB['rooms'].append(Room(42, 1, 'closed', 1000)) DB['rooms'].append(Room(7, 1, 'available', 50)) DB['rooms'].append(Room(69, 7, 'available', 9000)) DB['rooms'].append(Room(11, 3, 'closed', 10)) DB['tenants'].append(Tenant('Neo', 'zz0101', 33, 'M', { "city": "Zeon", "street": "Street 255" }, 42)) DB['tenants'].append(Tenant('Janis', 'bb2222', 40, 'W', { "city": "Los Angeles", "street": "Beverly Hills, 90210" }, 7)) DB['tenants'].append(Tenant('Sherlock', 'cc3333', 51, 'M', { "city": "London", "street": "Bakerstreet, 221B" }, 11)) DB['staff'].append(Staff('Taylor', 'aa1111', 'waiter', 100)) DB['staff'].append(Staff('Hannibal', 'et0000', 'cook', 1000)) DB['staff'].append(Staff('Hilton', 'ad1234', 'Administrator', 9000))
def get(self): tenant_key = self.request.get('tenant_key') tenant = Tenant.get(tenant_key) path = os.path.join(os.path.dirname(__file__), 'templates/checkList.html') template_values = {'tenant':tenant} resp = template.render(path, template_values) return self.response.out.write(resp)
def get(self, uuid): user = self.user_info admin = user.get('isAdmin') real_uuid = uuid tenant = Tenant.query(Tenant.uuid == real_uuid).get() notes = tenant.notes lista = [] for note in notes: real_note = TenantNote.query(Tenant.key == note).get() lista.append(real_note) if admin is True: template_values = { #'list_list': list_list, 'user': user, 'lista': lista, 'admin': admin, } else: template_values = { #'list_list': list_list, 'user': user, 'lista': lista, } path = os.path.join(os.path.dirname(__file__), 'templates/viewnotes.html') self.response.write(template.render(path, template_values))
def tenant(tenant_id): if request.method == 'POST': tenant = Tenant.query.filter_by(id=tenant_id).first() if tenant is None: tenant = Tenant(id=tenant_id) db_session.add(tenant) db_session.commit() return jsonify(tenant.as_dict()), 201 else: return jsonify(tenant.as_dict()) else: tenant = Tenant.query.filter_by(id=tenant_id).first() if tenant is None: return Response("No tenant found!", status=404) else: return jsonify(tenant.as_dict())
def main(): tenant_list = all_tenant() for tenant in tenant_list: if can_insert(tenant['id']): tn = Tenant(tenant['id'], tenant['name'], tenant['user_id']) db.add(tn) print "tenant :", tenant['name'], " added to db" db.flush() db.commit()
def delete(self): tenant_key = self.request.get('tenant_key') tenantToCheckout = Tenant.get(tenant_key) # tenant-key = tenant.key tenantToCheckout.createCheckoutActivityRecord() tenantToCheckout.unRegisterRoom() self.response.headers['Content-Type'] = 'application/json' response = {'checkoutSuccessNotice':'The tenant has checked out successfully!'} jsonResponse = simplejson.dumps(response) return self.response.out.write(jsonResponse)
async def put(self, tenant: (models.Tenant, 'id'), new_tenant: models.Tenant): new_tenant.name = new_tenant.name.strip() _changes = [] if tenant.name != new_tenant.name: tenant.name = new_tenant.name _changes.append('name') if _changes: await tenant.save() return {'changes': _changes}
def __init__(self, args): self.args = args self.tenant = Tenant( self.args.username, self.args.api_key, Tenant.SMALL, # this doesn't mean anything for our purposes self.args.auth_endpoint, ) self.tenant.get_token() print "%s has token %s" % (self.tenant.id, self.tenant.get_token()) self.client = DesignateClient( client=HttpSession(self.args.endpoint), tenant=self.tenant, use_project_id=self.args.no_repose, tenant_id_in_url=not self.args.no_repose, )
def save(self, commit=True): tenant = Tenant(rent_date=self.cleaned_data['rentDate'],\ remind_date=self.cleaned_data['remindDate'],rent_money=self.cleaned_data['rentMoney'],\ house_number=self.cleaned_data['houseNumber'],unit=self.cleaned_data['unit'],\ community=self.cleaned_data['community'],mobile_number=self.cleaned_data['mobileNumber'],\ sex=self.cleaned_data['sex'],name=self.cleaned_data['name']) tenant.status = '1' tenant.user_id = self.userId tenant.done_date = datetime.datetime.now() if commit: tenant.save()
def post(self, uuid): tenant = Tenant.query(Tenant.uuid == uuid).get() tenant.address = self.request.get('address') tenant.cell = self.request.get('cell') tenant.email = self.request.get('email') tenant.contact_phone = self.request.get('contact_phone') tenant.contact_person = self.request.get('contact_person') unconverted_date = self.request.get('kurcina') if unconverted_date: converted_date = datetime.strptime(unconverted_date, '%d-%m-%Y') tenant.lease_expire = converted_date tenant.put() self.redirect('/tenants')
def get(self, uuid): tenant = Tenant.query(Tenant.uuid == uuid).get() tenant_id = tenant.key.id() tenant_key = ndb.Key(Tenant, tenant_id) building_tenant = Building.query(Building.tenants == tenant_key).get() if tenant: tenant.key.delete() building_tenant.tenants.remove(tenant_key) building_tenant.put() self.redirect('/tenants') else: self.abort(404)
def post(self): data = data_valid_for('POST') logging.debug(data) tenants_already_exist = list( filter(lambda t: data['passport_id'] == t.passport_id, DB['tenants'])) if not tenants_already_exist: DB['tenants'].append(Tenant(**data)) new_passport_id = str(DB['tenants'][-1].passport_id) location = {"Location": f'/api/v0.1/tenants/{new_passport_id}'} return {"message": "tenant was added successfully"}, 201, location msg = f"tenant with passport_id {data['passport_id']} already exists" return {"message": msg}, 400
def get(self): user = self.user_info if user.get('isAdmin') is True: q = Tenant.query() tenants = q.fetch() template_values = { 'tenants': tenants, 'admin': 'admin', 'user': user, } path = os.path.join(os.path.dirname(__file__), 'templates/a-dashboard.html') self.response.write(template.render(path, template_values)) else: self.abort(403)
def get(self): tenant_key = self.request.get('tenant_key') tenant = Tenant.get(tenant_key) room = Room() vacantRooms=room.getVacantRooms() if vacantRooms: tenant_data_list = tenant.getTenantProfile() rooms_data_list = room.getRoomsProfile(vacantRooms) data_list = [] data_list.append({'tenantProfile': tenant_data_list, 'roomsProfile': rooms_data_list}) output_json = json.dumps(data_list) self.response.out.write(output_json) else: noVacancyResponse = {'noVacancyResponse':'Sorry, All rooms are occupied!'} noVacancyResponse_json = simplejson.dumps(noVacancyResponse) return self.response.out.write(noVacancyResponse_json)
def save(self,commit=True): tenant = Tenant(rent_date=self.cleaned_data['rentDate'],\ remind_date=self.cleaned_data['remindDate'],rent_money=self.cleaned_data['rentMoney'],\ house_number=self.cleaned_data['houseNumber'],unit=self.cleaned_data['unit'],\ community=self.cleaned_data['community'],mobile_number=self.cleaned_data['mobileNumber'],\ sex=self.cleaned_data['sex'],name=self.cleaned_data['name']) tenant.status = '1' tenant.user_id=self.userId tenant.done_date=datetime.datetime.now() if commit: tenant.save()
def get(self, uuid): user = self.user_info admin = user.get('isAdmin') tenant = Tenant.query(Tenant.uuid == uuid).get() if admin is True: template_values = { 'tenant': tenant, 'user': user, 'admin': admin, } else: template_values = { 'tenant': tenant, 'user': user, } path = os.path.join(os.path.dirname(__file__), 'templates/add-note.html') self.response.write(template.render(path, template_values))
def get(self, uuid): building = Building.query(Building.uuid == uuid).get() tenant = Tenant.query(Tenant.building_uuid == uuid).get() landlord = Landlord.query(Landlord.building_uuid == uuid).get() if building: building.key.delete() if tenant: tenant.key.delete() else: self.redirect("/viewbuildings-list") if landlord: landlord.key.delete() else: self.redirect("/viewbuildings-list") self.redirect("/viewbuildings-list") else: self.abort(403)
def userRegisteration(request: User, db: Session = Depends(get_db)): id_uid = id_uuids() organization = Organization(id=id_uid, name=request.organization_name) db.add(organization) db.commit() db.refresh(organization) id_uid = id_uuids() tenant = Tenant(id=id_uid, name=request.tenant_name, company_logo=request.company_logo, organization_id=organization.id) db.add(tenant) db.commit() db.refresh(tenant) role = db.query( models.Role).filter(models.Role.name == "tenentAdmin").first() if role: print(role.id) else: role = Role(id=id_uid, name="tenentAdmin") db.add(role) db.commit() db.refresh(role) # atuo generate password a = randoms() password = str(a) Tenantuser = TenantUser(id=id_uid, username=request.username, role_id=role.id, password=password, tenant_id=tenant.id) db.add(Tenantuser) db.commit() db.refresh(Tenantuser) return {organization, tenant, Tenantuser}
def get(self, uuid): user = self.user_info tenant = Tenant.query(Tenant.uuid == uuid).get() admin = user.get('isAdmin') unconverted_date = tenant.lease_expire converted_date = datetime.strftime(unconverted_date, '%d-%m-%Y') if admin is True: template_values = { 'user': user, 'admin': admin, 'tenant': tenant, 'converted_date': converted_date, } else: template_values = { 'user': user, 'tenant': tenant } path = os.path.join(os.path.dirname(__file__), 'templates/edit-tenant.html') self.response.write(template.render(path, template_values))
def userRegisteration(request: User, db: Session = Depends(get_db)): id_uid = id_uuids() organization = Organization(id=id_uid, name=request.organization_name) db.add(organization) db.commit() db.refresh(organization) id_uid = id_uuids() tenant = Tenant(id=id_uid, name=request.tenant_name, organization_id=organization.id) db.add(tenant) db.commit() db.refresh(tenant) role = db.query(models.Role).filter(models.Role.name == "admin").first() if role: role_id = role.id else: role_id = Role(id=id_uid, name="tenentAdmin") db.add(role_id) db.commit() db.refresh(role_id) print(role_id) tenantuser = TenantUser(id=id_uid, username=request.username, first_name=request.firstname, last_name=request.lastname, email=request.email, role_id=role_id, tenant_id=tenant.id) db.add(tenantuser) db.commit() db.refresh(tenantuser) return {organization, tenant, tenantuser}
def get(self): user = self.user_info admin = user.get('isAdmin') real_user_id = user.get('user_id') key = ndb.Key(User, real_user_id) files = Tenant.query(Tenant.user == key) tenants = files.order(-Tenant.tenant_name).fetch() if admin is True: template_values = { #'list_list': list_list, 'user': user, 'tenants': tenants, 'admin': admin, } else: template_values = { #'list_list': list_list, 'user': user, 'tenants': tenants } path = os.path.join(os.path.dirname(__file__), 'templates/dashboard.html') self.response.write(template.render(path, template_values))
def get(self, uuid): user = self.user_info building = Building.query(Building.uuid == uuid).get() serve_me = images.get_serving_url(building.picture, size=None, crop=False, secure_url=None) tenants = [] if building.tenants: for tenant in building.tenants: kurac = tenant.id() tenant = Tenant.get_by_id(kurac) tenants.append(tenant) else: tenant = None if building.landlord: smajser = building.landlord.id() landlord = Landlord.get_by_id(smajser) else: landlord = None admin = user.get('isAdmin') if admin is True: template_values = { 'landlord': landlord, 'serve_me': serve_me, 'building': building, 'user': user, 'admin': admin, 'tenants': tenants, } else: template_values = { 'landlord': landlord, 'serve_me': serve_me, 'building': building, 'user': user, } path = os.path.join(os.path.dirname(__file__), 'templates/view-building.html') self.response.write(template.render(path, template_values))
def get(self, uuid): user = self.user_info admin = user.get('isAdmin') files = Tenant.query(Tenant.building_uuid == uuid) building = Building.query(Building.uuid == uuid).get() tenants = files.order(-Tenant.contact_person).fetch() if admin is True: template_values = { #'list_list': list_list, 'user': user, 'building': building, 'tenants': tenants, 'admin': admin, } else: template_values = { #'list_list': list_list, 'user': user, 'building': building, 'tenants': tenants, } path = os.path.join(os.path.dirname(__file__), 'templates/dashboard-2.html') self.response.write(template.render(path, template_values))
def post(self, uuid): user = self.user_info print user user_uuid = user.get('uuid') user_object = User.query(User.uuid == user_uuid).get() real_key = user_object.key.id() real_user_key = ndb.Key(User, real_key) building = Building.query(Building.user == real_user_key).get() building.last_updated = datetime.now() building.put() note = TenantNote() tenant = Tenant.query(Tenant.uuid == uuid).get() tenant_id = tenant.key.id() note.tenant = ndb.Key(Tenant, tenant_id) note.tenant_uuid = uuid note.text = self.request.get('description') real_note = note.put() real_note_key = real_note.id() idzor = real_note_key mrav = ndb.Key(TenantNote, idzor) tenant.notes.append(mrav) tenant.put() self.redirect('/tenants')
def post(self, uuid): tenant = Tenant() tenant.uuid = uuid1().get_hex() tenant.tenant_name = self.request.get('tenant_name') tenant.address = self.request.get('address') tenant.cell = self.request.get('cell') tenant.email = self.request.get('email') tenant.contact_person = self.request.get('contact_person') tenant.contact_phone = self.request.get('contact_phone') unconverted_date = self.request.get('kurcina') converted_date = datetime.strptime(unconverted_date, '%d-%m-%Y') tenant.lease_expire = converted_date users.get_current_user() user = self.user_info tenant.brokers_name = user.get('user_name') user_id = user.get('user_id') tenant.user = ndb.Key(User, user_id) tenant.building_uuid = uuid building = Building.query(Building.uuid == uuid).get() building_id = building.key.id() tenant.building = ndb.Key(Building, building_id) marcipan = tenant.put() time.sleep(2) kurcina = marcipan.id() mrgud = ndb.Key(Tenant, kurcina) building.tenants.append(mrgud) building.last_updated = datetime.now() building.put() time.sleep(2) self.redirect('/viewtenants/' + uuid)
def get(self): tenant_key = self.request.get('tenant_key') tenant = Tenant.get(tenant_key) data_list = tenant.getTenantProfile() output_json = json.dumps(data_list) self.response.out.write(output_json)
async def post(self, tenant: models.Tenant): tenant.name = tenant.name.strip() await tenant.save() return {'id': str(tenant.id)}, base.http.status.CREATED
def get(self): tenant_key = self.request.get('tenant_key') tenant = Tenant.get(tenant_key) checkout_data_list = tenant.getRentalStatusInfo() output_json = json.dumps(checkout_data_list) self.response.out.write(output_json)
#Push sample data with GraphQL #Drop existing tables if any before running #initialize db with first tenants and sensors import random from models import engine, db_session, Base, Tenant, Data, Sensor Base.metadata.create_all(bind=engine) #add first user kate = Tenant(name='kate') db_session.add(kate) #add second user kate_multitenancy = Tenant(name='kate_multitenancy') db_session.add(kate_multitenancy) #add sensors t = Sensor(name='temperature') db_session.add(t) e = Sensor(name='electricity') db_session.add(e) p = Sensor(name='pressure') db_session.add(p) users = [kate, kate_multitenancy] sensors = [e,p,t] #add 100 entries n = 100 for i in range(n):
def validate_checkdomain(request): TenantObj = Tenant().getUserBySubdomain(request.GET.get('company_domain')) if TenantObj == None: return HttpResponse(json.dumps(True)) return HttpResponse(json.dumps(False))
# save a report when the test finishes persistence.setup_persistence() locust.config.RESET_STATS_AFTER_HATCHING = CONFIG.reset_stats # use digaas to externally poll the nameserver(s) to record zone propagation # times through Designate's stack if CONFIG.use_digaas and not insight.is_slave(): _digaas_client = digaas_integration.DigaasClient(CONFIG.digaas_endpoint) digaas_integration.setup(_digaas_client) if not insight.is_master(): # TODO: the tenant id is actually the username. it should be named so. SMALL_TENANTS = [ Tenant(id=id, api_key=api_key, type=Tenant.SMALL) for id, api_key in CONFIG.small_tenants ] LARGE_TENANTS = [ Tenant(id=id, api_key=api_key, type=Tenant.LARGE) for id, api_key in CONFIG.large_tenants ] ALL_TENANTS = SMALL_TENANTS + LARGE_TENANTS # the greenlet_manager keeps track of greenlets spawned for polling # todo: it's hard to ensure cleanup_greenlets gets run before the stats # are persisted to a file... # ensure cleanup when the test is stopped locust.events.locust_stop_hatching += \ lambda: GreenletManager.get().cleanup_greenlets()
class TenantPrepper(object): def __init__(self, args): self.args = args self.tenant = Tenant( self.args.username, self.args.api_key, Tenant.SMALL, # this doesn't mean anything for our purposes self.args.auth_endpoint, ) self.tenant.get_token() print "%s has token %s" % (self.tenant.id, self.tenant.get_token()) self.client = DesignateClient( client=HttpSession(self.args.endpoint), tenant=self.tenant, use_project_id=self.args.no_repose, tenant_id_in_url=not self.args.no_repose, ) def run(self): # self.increase_quotas() zones = self.ensure_zones_are_created() recordsets = self.ensure_recordsets_are_created(zones) def increase_quotas(self): payload = { "quota": { "zones": 99999999, "recordset_records": 99999999, "zone_records": 99999999, "zone_recordsets": 99999999, } } resp = self.client.patch_quotas(self.tenant.tenant_id, json.dumps(payload)) check_resp(resp) print '%s increased quotas' % self.tenant.tenant_id def ensure_zones_are_created(self): # try to fetch the number of zones we need zones = self.list_zones(limit=self.args.n_zones) print "%s has at least %s zones already (need %s total)" % ( self.tenant.id, len(zones), self.args.n_zones) # if we don't have enough zones, create some more if len(zones) < self.args.n_zones: n_missing_zones = self.args.n_zones - len(zones) print "%s is creating %s additional zones" % ( self.tenant.id, n_missing_zones) additional_zones = self.create_zones(number=n_missing_zones) zones.extend(additional_zones) return zones def ensure_recordsets_are_created(self, zones): recordsets = [] for zone in zones: records_for_zone = self.ensure_recordsets_are_created_for_zone(zone) recordsets.extend(records_for_zone) return recordsets def ensure_recordsets_are_created_for_zone(self, zone): # try to fetch the number of recordsets we want recordsets = self.list_a_recordsets(zone, limit=self.args.n_recordsets_per_zone) print "%s: zone %s already has at least %s A recordsets (need %s)" % ( self.tenant.id, zone.name, len(recordsets), self.args.n_recordsets_per_zone) # if not enough recordsets, create some more if len(recordsets) < self.args.n_recordsets_per_zone: n_missing_recordsets = self.args.n_recordsets_per_zone - len(recordsets) print "%s is creating %s additional recordsets on zone %s" % ( self.tenant.id, n_missing_recordsets, zone.name) additional_recordsets = self.create_recordsets(zone, number=n_missing_recordsets) print 'created %s additional_recordets' % len(additional_recordsets) recordsets.extend(additional_recordsets) return recordsets def create_zones(self, number): return [self.create_zone() for _ in xrange(number)] def create_zone(self): zone_name, email = random_zone_email() payload = { "name": zone_name, "email": email, "ttl": 7200 } resp = self.client.post_zone(data=json.dumps(payload)) check_resp(resp) zone = Zone(resp.json()['id'], resp.json()['name']) print '%s: Created zone %s' % (self.tenant.id, zone.name) return zone def create_recordsets(self, zone, number): return [self.create_recordset(zone) for _ in xrange(number)] def create_recordset(self, zone): record_name = "{0}.{1}".format(randomize("record"), zone.name) payload = { "name" : record_name, "type" : "A", "ttl" : 3600, "records" : [ random_ip() ] } resp = self.client.post_recordset(zone.id, data=json.dumps(payload)) check_resp(resp) recordset = Recordset( zone = zone, id = resp.json()['id'], data = resp.json()['records'][0], type = resp.json()['type']) print '%s: Created recordset %s' % (self.tenant.id, record_name) return recordset def list_zones(self, limit): frontier = PaginationFrontier([self.tenant]) found_zones = [] while not frontier.is_empty(): link, tenant = frontier.pop_next_zone_link() if not link: return found_zones path, params = frontier.parse_url(link) params['sort_key'] = 'id' print "%s: GET %s" % (self.tenant.id, link) resp = self.client.get(path, params=params) check_resp(resp) zones = resp.json()['zones'] links = resp.json()['links'] if 'next' in links: next_link = links['next'] frontier.add_zone_link(next_link, tenant) for z in zones: zone = Zone(z['id'], z['name']) found_zones.append(zone) if len(found_zones) >= limit: return found_zones return found_zones def list_a_recordsets(self, zone, limit): frontier = PaginationFrontier([self.tenant]) found_recordsets = [] initial_link = '/v2/zones/%s/recordsets' % zone.id frontier.add_recordset_link(zone, initial_link, self.tenant) while not frontier.is_empty(): zone, link, tenant = frontier.pop_next_recordset_link() if not link: return found_recordsets path, params = frontier.parse_url(link) params['sort_key'] = 'id' print "%s: GET %s" % (self.tenant.id, link) resp = self.client.get(path, params=params) check_resp(resp) recordsets = resp.json()['recordsets'] links = resp.json()['links'] if 'next' in links: next_link = links['next'] frontier.add_recordset_link(zone, next_link, tenant) for r in recordsets: if r['type'].upper() != 'A': continue recordset = Recordset(zone, r['id'], r['records'][0], r['type']) found_recordsets.append(recordset) if len(found_recordsets) >= limit: return found_recordsets return found_recordsets