Package madrona :: Package manipulators :: Package management :: Package commands :: Module change_manipulator_geom
[hide private]

Source Code for Module madrona.manipulators.management.commands.change_manipulator_geom

 1  from django.core.management.base import BaseCommand, AppCommand 
 2  from optparse import make_option 
 3  from django.contrib.gis.utils import LayerMapping 
 4  from django.contrib.gis.gdal import DataSource 
 5  #from progressbar import Bar, Percentage, RotatingMarker, ProgressBar, ETA 
 6  from madrona.common.utils import get_class 
 7  import time 
 8   
 9  #omm_manipulator_list = ['EastOfTerritorialSeaLine', 'TerrestrialAndEstuaries', 'Terrestrial', 'Estuaries'] 
10   
11 -class Command(BaseCommand):
12 help = """Switches from one manipulator geometry to another, (eventually this command will re-process the AOIs and expiring report caches). 13 \n\tmanage.py change_manipulator_geom <pk> <manipulator or model>""" 14 args = '[pk, manipulator]' 15
16 - def handle(self, pk, manipulator, **options):
17 try: 18 manip_model = get_class(manipulator) 19 except: 20 raise Exception("The %s model could not be found. \nBe sure and provide the complete description: <module name>.models.<manipulator model name>" % manipulator) 21 22 # Turn them all off 23 regions = manip_model.objects.all() 24 for region in regions: 25 region.active = False 26 region.save() 27 28 # Now active the single study region 29 new_geom = manip_model.objects.get(pk=pk) 30 new_geom.active = True 31 new_geom.save() 32 33 print "%s is now the active %s manipulator" % (new_geom, manipulator)
34 35 # Eventually we'll implement this
36 - def handle2(self, pk, **options):
37 new_study_region = StudyRegion.objects.get(pk=pk) 38 old_study_region = StudyRegion.objects.current() 39 print """ 40 **************************************************************** 41 This management command does not actually do anything right now. 42 It is just a mockup of the desired interface. 43 **************************************************************** 44 """ 45 print """ 46 This process should not be done when the Madrona application is publicly 47 accessible. Please shutdown the server or redirect users to a maintenance page 48 """ 49 answer = raw_input("Type 'yes' to continue, or 'no' to cancel: ") 50 if answer == 'yes': 51 print "" 52 # Get difference between old study region and new 53 print "calculating difference between the specified study region and the one currently active..." 54 diff = old_study_region.geometry.sym_difference(new_study_region.geometry) 55 print """ 56 current study region: %s 57 area: %s 58 59 new study region: %s 60 area: %s 61 62 difference between study regions: 63 area: %s 64 sections: %s 65 66 User Shapes Affected:""" % (old_study_region.name, old_study_region.geometry.area, new_study_region.name, new_study_region.geometry.area, diff.area, len(diff)) 67 68 # find models that need to be reclipped somehow 69 # for model in models: 70 # print "%s: %s" % (model.__class__.__name__, model.objects.filter(geometry_intersects=diff).count(), ) 71 72 print " Mpas: 90" 73 print "" 74 print "Are you sure you would like the switch to the new study region?" 75 answer = raw_input("Type 'yes' to continue, or 'no' to cancel: ") 76 if answer == 'yes': 77 # new_study_region.active = True 78 # new_study_region.save() 79 print "Processing shapes:" 80 widgets = [Bar('-'), ' ', Percentage(), ' | ', ETA(),] 81 pbar = ProgressBar(widgets=widgets, maxval=50).start() 82 for i in range(50): 83 # Re-run the appropriate manipulators 84 time.sleep(0.1) 85 pbar.update(i + 1) 86 print "Done processing shapes." 87 print "Would you like to send an email notifying users that their shapes have changed?" 88 email = raw_input("Type 'yes' or 'no': ") 89 if email == 'yes': 90 print "sending emails..." 91 time.sleep(2) 92 print "This process is complete. You can now resume public access to the application." 93 94 else: 95 print "cancelling..." 96 else: 97 print "cancelling..."
98