def rename(newlabel, unitid): from rentfox.model.property import Property unit = meta.Session.query(Unit).filter(Unit.deleted==None).filter_by(id=unitid).first() unit.label = newlabel meta.Session.commit() session.save() # update index property = Property.get_property(unit.propertyid) text = ' '.join([str(newlabel), str(newlabel), str(newlabel), str(property.name), str(property.address)]) index_update = IndexUpdate() index_update.updateItem('unit', unitid) index_update.updateData(text) index_update.update()
def create(propertyid, label, index): newUnit = Unit() newUnit.id = str(uuid.uuid1()) newUnit.propertyid = propertyid newUnit.label = label meta.Session.add(newUnit) from rentfox.model.property import Property # index for searching later property = Property.get_property(propertyid) type = 'unit' id = newUnit.id text = ' '.join([str(label), str(label), str(label), str(property.name), str(property.address)]) terms = [ {'type':'company', 'id':request.environ.get('COMPANY_ID')}, {'type':'property', 'id':propertyid}, {'type':'unit', 'id':id} ] index.index(type, id, text, terms)
def find(self): q = request.GET['q'] if not valid.search(q): return json.dumps({'errors':[{'selector':'', "message":"Search only accepts letters and numbers. Please try again."}]}) page = int(request.GET['page']) limit = int(request.GET['limit']) filter = str(request.GET['filter']) username = request.environ.get('REMOTE_USER') property_access_list = Property.get_property_ids_of_username(username) s = Search(q) s.filter('company', request.environ.get('COMPANY_ID')) s.filter('property', property_access_list) s.filter('deleted', '0') if filter != 'all': s.filter('type', filter) matches = s.find(page, limit) partial_results = matches['results'] results = [] for result in partial_results: type = result['type'] uuid = result['uuid'] try: if type == 'property': property = Property.get_property(uuid) results.append({'type': type, 'id': uuid, 'title': property.name, 'link': '/property/view/{0}'.format(property.id), 'description': '{0}, {1}, {2} {3}'.format(property.address, property.city, property.state, property.zip)}) elif type == 'unit': unit = Unit.get_unit(uuid) property = Property.get_property(unit.propertyid) results.append({'type': type, 'id': uuid, 'title': '{0} #{1}'.format(property.name, unit.label), 'link': '/unit/view/{0}'.format(unit.id), 'description': '{0} #{1}, {2}, {3} {4}'.format(property.address, unit.label, property.city, property.state, property.zip)}) elif type == 'tenant': tenant = Tenant.get(uuid) details = [] if tenant.email: details.append(tenant.email) if tenant.phone: details.append(tenant.phone) contact_info = '<br />'.join(details) results.append({'type': type, 'id': uuid, 'title': '{0} {1}'.format(tenant.first_name, tenant.last_name), 'link': '/tenant/view/{0}'.format(tenant.id), 'description': contact_info}) elif type == 'contact': contact = Contact.get(uuid) details = [] if contact.email: details.append(contact.email) if contact.phone: details.append(contact.phone) contact_info = '<br />'.join(details) address = '<br />{0}, {1}'.format(contact.address, contact.city) if contact.address and contact.city else '' description = '<br />{0}'.format(contact.description) if contact.description else '' results.append({'type': type, 'id': uuid, 'title': contact.label, 'description': '{0}{1}{2}'.format(contact_info, address, description)}) except: pass return json.dumps({'results':results, 'start':matches['start'], 'end':matches['end'], 'page':matches['page'], 'total':matches['total']})