Ejemplo n.º 1
0
 def delete(propertyid):
     from rentfox.model.pulse import Pulse
     from rentfox.model.lease import Lease
     from rentfox.model.contact_type import Contact_type
     
     property = Property.get_property(propertyid)
     recycleId = Recycle.create("Property deleted: {0}".format(property.name))
     
     #set property, units, floorplans to deleted
     property.deleted = recycleId
     Unit.deleteByPropertyId(propertyid, recycleId)
     Floorplan.deleteByPropertyId(propertyid, recycleId)
     Lease.deleteByPropertyId(propertyid, recycleId)
     
     meta.Session.commit()
     session.save()
     
     index_update = IndexUpdate()
     index_update.updateItem('property', propertyid)
     index_update.updateTerm('deleted', 0, recycleId)
     index_update.update()
Ejemplo n.º 2
0
 def foxAlert():        
     companyid = request.environ.get('COMPANY_ID')
     username = request.environ.get('REMOTE_USER')
     propertyids = Property.get_property_ids_of_username(username)
     
     mc = Memcache()
     key = 'foxalert:{0}'.format(username)
     fox_alert = mc.get(key)
     if fox_alert == 'Saved': return False
     
     if len(propertyids) == 0:
         return {
                 'title': "Welcome!",
                 'message':"I'm here to help you. Let's get started by creating a property!",
                 'button':"Let's get started!",
                 'link':'/property/setup'
                 }
     
     if Property.totalUnitsInProperties(propertyids) == 0:
         return {
                 'title': "Create a unit!",
                 'message':"I just realized you don't have any units... let's create one!",
                 'button':"Okay!",
                 'link':'/property/setup/{0}'.format(propertyids[0])
                 }
         
     units_with_floorplans = Company.getUnitsWithFloorplans(propertyids)
     if len(units_with_floorplans) == 0:
         units = Unit.get_units_of_properties(propertyids)
         unitid = units[0].id
         propertyid = units[0].propertyid
         return {
                 'title': "No floorplans yet?",
                 'message': "Your units need floorplans. Floorplans are cool because you can apply them to other units in the same building.",
                 "button": "Add Floorplans",
                 'link': '/property/setup/{0}/{1}'.format(propertyid,unitid)
                 }
     
     lease = Lease.get_earliest(propertyids)
     if not lease:
         unitid = units_with_floorplans[0].id
         return {
                 'title': "Got leases?",
                 'message': "Are you ready to add a lease to one of your units?",
                 "button": "Yes, take me there!",
                 'link': '/unit/view/{0}'.format(unitid)
                 }
     
     mc.set(key, 'Saved', time=86400)
     
     return False
Ejemplo n.º 3
0
 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']})