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 madrona.studyregion.models import StudyRegion
6
7 import time
8
9
11 help = "Switches from one study region to another, reprocessing MPAs and expiring report caches."
12 args = '[pk]'
13
14 - def handle(self, pk, **options):
15
16 regions = StudyRegion.objects.all()
17 for region in regions:
18 region.active = False
19 region.save()
20
21
22 new_study_region = StudyRegion.objects.get(pk=pk)
23 new_study_region.active = True
24 new_study_region.save()
25
26 print "%s is now the active study region" % new_study_region
27
28
30 new_study_region = StudyRegion.objects.get(pk=pk)
31 old_study_region = StudyRegion.objects.current()
32 print """
33 ****************************************************************
34 This management command does not actually do anything right now.
35 It is just a mockup of the desired interface.
36 ****************************************************************
37 """
38 print """
39 This process should not be done when the Madrona application is publicly
40 accessible. Please shutdown the server or redirect users to a maintenance page
41 """
42 answer = raw_input("Type 'yes' to continue, or 'no' to cancel: ")
43 if answer == 'yes':
44 print ""
45
46 print "calculating difference between the specified study region and the one currently active..."
47 diff = old_study_region.geometry.sym_difference(new_study_region.geometry)
48 print """
49 current study region: %s
50 area: %s
51
52 new study region: %s
53 area: %s
54
55 difference between study regions:
56 area: %s
57 sections: %s
58
59 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))
60
61
62
63
64
65 print " Mpas: 90"
66 print ""
67 print "Are you sure you would like the switch to the new study region?"
68 answer = raw_input("Type 'yes' to continue, or 'no' to cancel: ")
69 if answer == 'yes':
70
71
72 print "Processing shapes:"
73 widgets = [Bar('-'), ' ', Percentage(), ' | ', ETA(),]
74 pbar = ProgressBar(widgets=widgets, maxval=50).start()
75 for i in range(50):
76
77 time.sleep(0.1)
78 pbar.update(i + 1)
79 print "Done processing shapes."
80 print "Would you like to send an email notifying users that their shapes have changed?"
81 email = raw_input("Type 'yes' or 'no': ")
82 if email == 'yes':
83 print "sending emails..."
84 time.sleep(2)
85 print "This process is complete. You can now resume public access to the application."
86
87 else:
88 print "cancelling..."
89 else:
90 print "cancelling..."
91