@@ -14,15 +14,11 @@ class Command(BaseCommand):
1414 """Implementation for the `manage.py quicksetup` subcommand."""
1515
1616 def add_arguments (self , parser : argparse .ArgumentParser ):
17- """Define arguments for the `manage.py quicksetup` subcommand."""
18-
19- # Named (optional) arguments.
2017 parser .add_argument (
2118 "--noindex" ,
2219 action = "store_true" ,
23- help = "Flushes all existing database data before adding new objects ." ,
20+ help = "Skip building search indexes ." ,
2421 )
25-
2622 parser .add_argument (
2723 "--clean" ,
2824 action = "store_true" ,
@@ -56,15 +52,7 @@ def handle(self, *args, **options):
5652 self .stdout .write (self .style .ERROR (
5753 'QUICKSETUP FAILED - Fix foreign key constraint violations before proceeding.'
5854 ))
59- return # Exit without showing "API setup complete"
60-
61- if not options ['noindex' ]:
62- if settings .BUILD_V1_INDEX :
63- build_haystack_index ()
64- else :
65- self .stdout .write ("Skipping v1 index build because of --noindex" )
66- else :
67- self .stdout .write ('Skipping v1 database population.' )
55+ return
6856
6957 if settings .INCLUDE_V2_DATA :
7058 self .stdout .write ('Populating the v2 database...' )
@@ -77,73 +65,59 @@ def handle(self, *args, **options):
7765 self .stdout .write (self .style .ERROR (
7866 'QUICKSETUP FAILED - Fix foreign key constraint violations before proceeding.'
7967 ))
80- return # Exit without showing "API setup complete"
68+ return
8169
8270 if not options ['noindex' ]:
8371 if settings .BUILD_V2_INDEX :
84- self .stdout .write ('Building the v2 index with both v1 and v2 data .' )
85- build_v1v2_searchindex ()
72+ self .stdout .write ('Building the search index.. .' )
73+ build_search_index ()
8674 else :
87- self .stdout .write ('Skipping v2 index build because of --noindex.' )
75+ self .stdout .write ('Skipping index build because of --noindex.' )
8876
8977 self .stdout .write (self .style .SUCCESS ('API setup complete.' ))
9078
9179
92- def migrate_db () -> None :
93- """Migrate the local database as needed to incorporate new model updates.
94- This command is added primarily to assist in local development, because
95- checking out and changing branches results in unclean model/dbs."""
96-
80+ def migrate_db ():
9781 call_command ('makemigrations' )
9882 call_command ('migrate' )
9983
100- def is_dirty () -> None :
101- # TODO switch these over to server settings values.
102- is_dirty = False
103- if Path ('./server/ whoosh_index' ).is_dir ():
84+
85+ def is_dirty ():
86+ is_dirty = False
87+ if Path ('whoosh_index' ).is_dir ():
10488 print ("Found whoosh_index" )
105- is_dirty = True
89+ is_dirty = True
10690 if Path (settings .STATIC_ROOT ).is_dir ():
10791 print ("Found static root" )
108- is_dirty = True
92+ is_dirty = True
10993 if Path (settings .DATABASES ['default' ]['NAME' ]).exists ():
11094 print ("Found db file" )
111- is_dirty = True
95+ is_dirty = True
11296 return is_dirty
11397
114- def clean_dir () -> None :
115- if Path ('./server/whoosh_index' ).is_dir ():
116- shutil .rmtree (Path ('./server/whoosh_index' ))
98+
99+ def clean_dir ():
100+ if Path ('whoosh_index' ).is_dir ():
101+ shutil .rmtree (Path ('whoosh_index' ))
117102 if Path (settings .STATIC_ROOT ).is_dir ():
118103 shutil .rmtree (Path (settings .STATIC_ROOT ))
119104 if Path (settings .DATABASES ['default' ]['NAME' ]).exists ():
120105 Path (settings .DATABASES ['default' ]['NAME' ]).unlink ()
121- vector_index = Path ('server/vector_index.pkl' )
122- if vector_index .exists ():
123- vector_index .unlink ()
106+ if Path ('server/vector_index.pkl' ).exists ():
107+ Path ('server/vector_index.pkl' ).unlink ()
124108
125- def import_v1 () -> None :
126- """Import the v1 apps' database models."""
109+
110+ def import_v1 ():
127111 call_command ('import' , '--dir' , 'data/v1' )
128112
129113
130- def import_v2 () -> None :
131- """Import the v2 apps' database models."""
114+ def import_v2 ():
132115 call_command ('import' , '--dir' , 'data/v2' )
133116
134117
135- def collect_static () -> None :
136- """Collect static files in a single location."""
118+ def collect_static ():
137119 call_command ('collectstatic' , '--noinput' )
138120
139121
140- def build_haystack_index () -> None :
141- """Freshen the haystack search indexes. This is an internal haystack
142- API that is being called, and only applies to v1 data."""
143- print ("THIS ENTIRE COMMAND HAS BEEN DEPRECATED! EXPECT ERRORS." )
144- call_command ('update_index' , '--remove' )
145-
146- def build_v1v2_searchindex () -> None :
147- """Builds the custom search index defined in the api_v2 management
148- commands. Only adds the v1 data."""
149- call_command ('buildindex' ,'--v1' ,'--v2' )
122+ def build_search_index ():
123+ call_command ('buildindex' , '--v1' , '--v2' )
0 commit comments