Example #1
0
 def delete(unitid):
     from rentfox.model.recycle import Recycle
     from rentfox.model.property import Property
     from rentfox.model.lease import Lease
     
     unit = meta.Session.query(Unit).filter_by(id=unitid).first()
     property_name = Property.get_name_by_id(unit.propertyid)
     
     recycleId = Recycle.create("Unit {0} deleted from {1}".format(unit.label, property_name))
     
     unit.deleted = recycleId
     Lease.deleteByUnitId(unitid, recycleId)
     
     meta.Session.commit()
     session.save()
     
     index_update = IndexUpdate()
     index_update.updateItem('unit', unitid)
     index_update.updateTerm('deleted', 0, recycleId)
     index_update.update()
Example #2
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()
Example #3
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
Example #4
0
 def delete_units(units, propertyid):
     
     from rentfox.model.property import Property
     from rentfox.model.recycle import Recycle
     from rentfox.model.lease import Lease
     
     count = 0
     
     property_name = Property.get_name_by_id(propertyid)
     recycleId = Recycle.create("Units deleted from {0}".format(property_name))
     
     index_update = IndexUpdate()
     
     if '-' in units:
         unitRange = units.split('-')
         start = unitRange[0]
         end = unitRange[1]
         
         # Special case: Allow for labels such as 12-B or C-2 to be deleted.
         if (start.isdigit() and end.isalpha())\
             or (end.isdigit() and start.isalpha()):
             
             existingUnits = Unit.get_units_list(propertyid)
             if str(units) in existingUnits:
                 
                 unit = Unit.get_unit_with_propertyid(units, propertyid)
                 unit.deleted = recycleId
                 
                 index_update.updateItem('unit', unit.id)
                 index_update.updateTerm('deleted', 0, recycleId)
                 index_update.update()
                 
                 Lease.deleteByUnitId(unit.id, recycleId)
                 count += 1
         else:
             existingUnits = Unit.get_units_list(propertyid)
             for unit in range(int(start), int(end) + 1):
                 if str(unit) in existingUnits:
                     unit = Unit.get_unit_with_propertyid(str(unit), propertyid)
                     unit.deleted = recycleId
                     
                     index_update.updateItem('unit', unit.id)
                     index_update.updateTerm('deleted', 0, recycleId)
                     index_update.update()
                     
                     Lease.deleteByUnitId(unit.id, recycleId)
                     count += 1
     elif ',' in units:
         unitList = units.split(',')
         existingUnits = Unit.get_units_list(propertyid)
         for unit in unitList:
             if str(unit) in existingUnits:
                 unit = Unit.get_unit_with_propertyid(str(unit), propertyid)
                 unit.deleted = recycleId
                 
                 index_update.updateItem('unit', unit.id)
                 index_update.updateTerm('deleted', 0, recycleId)
                 index_update.update()
                 
                 Lease.deleteByUnitId(unit.id, recycleId)
                 count += 1
     else:
         unit = Unit.get_unit_with_propertyid(units, propertyid)
         unit.deleted = recycleId
         
         index_update.updateItem('unit', unit.id)
         index_update.updateTerm('deleted', 0, recycleId)
         index_update.update()
         
         Lease.deleteByUnitId(unit.id, recycleId)
         count += 1
     
     if count == 0:
         Recycle.delete(recycleId)
         return False
         
     meta.Session.commit()
     session.save()