23
23
GREEN = "\033 [32m"
24
24
NOBOLD = "\033 [0m"
25
25
26
+ COLUMN_NAMES = (
27
+ "first_name" ,
28
+ "last_name" ,
29
+ "email" ,
30
+ "council_area" ,
31
+ "type_of_volunteering" ,
32
+ "assigned_section" ,
33
+ )
34
+
35
+ USECOLS = (
36
+ "First name" ,
37
+ "Last name" ,
38
+ "Email" ,
39
+ "Council Area" ,
40
+ "Type of Volunteering" ,
41
+ "Assigned Section" ,
42
+ )
43
+
26
44
27
45
class Command (BaseCommand ):
28
46
help = "import volunteers"
@@ -45,24 +63,6 @@ class Command(BaseCommand):
45
63
"local_climate_policy_programme" : 15 ,
46
64
}
47
65
48
- column_names = [
49
- "first_name" ,
50
- "last_name" ,
51
- "email" ,
52
- "council_area" ,
53
- "type_of_volunteering" ,
54
- "assigned_section" ,
55
- ]
56
-
57
- usecols = [
58
- "First name" ,
59
- "Last name" ,
60
- "Email" ,
61
- "Council Area" ,
62
- "Type of Volunteering" ,
63
- "Assigned Section" ,
64
- ]
65
-
66
66
def add_arguments (self , parser ):
67
67
parser .add_argument (
68
68
"-q" , "--quiet" , action = "store_true" , help = "Silence progress bars."
@@ -106,6 +106,12 @@ def add_arguments(self, parser):
106
106
help = "Marking session to use assignements with" ,
107
107
)
108
108
109
+ parser .add_argument (
110
+ "--section_count_in_data" ,
111
+ action = "store_true" ,
112
+ help = "use the section count in the csv and not the map" ,
113
+ )
114
+
109
115
parser .add_argument (
110
116
"--add_users" , action = "store_true" , help = "add users to database"
111
117
)
@@ -120,6 +126,17 @@ def add_arguments(self, parser):
120
126
help = "run everything and then undo changes. Helpful to check if assigment weighting is good" ,
121
127
)
122
128
129
+ def init (self , file , options ):
130
+ self .column_names = list (COLUMN_NAMES )
131
+ self .usecols = list (USECOLS )
132
+
133
+ if file is None :
134
+ file = self .volunteer_file
135
+
136
+ if options ["section_count_in_data" ]:
137
+ self .column_names .append ("section_count" )
138
+ self .usecols .append ("How many sections?" )
139
+
123
140
def get_df (self , filename ):
124
141
df = pd .read_csv (
125
142
filename ,
@@ -150,7 +167,10 @@ def set_authority_map(self, authority_map_file):
150
167
for _ , row in cols .iterrows ():
151
168
self .authority_map [row .bad_name ] = row .good_name
152
169
153
- def get_assignment_count (self , user_type ):
170
+ def get_assignment_count (self , user_type , row , section_count_in_data ):
171
+ if section_count_in_data :
172
+ return row ["section_count" ]
173
+
154
174
user_type = user_type .lower ().replace (" " , "_" )
155
175
156
176
num_councils = self .num_council_map .get (user_type )
@@ -171,7 +191,9 @@ def add_users_and_assignments(self, df, response_type, session, rt, options):
171
191
self .stdout .write (f"{ YELLOW } No user type for { row ['email' ]} { NOBOLD } " )
172
192
continue
173
193
174
- num_councils = self .get_assignment_count (user_type )
194
+ num_councils = self .get_assignment_count (
195
+ user_type , row , options ["section_count_in_data" ]
196
+ )
175
197
if num_councils is None :
176
198
self .stdout .write (
177
199
f"{ YELLOW } Don't know how many councils to assign for { row ['email' ]} { NOBOLD } "
@@ -296,9 +318,7 @@ def handle(
296
318
* args ,
297
319
** options ,
298
320
):
299
- if file is None :
300
- file = self .volunteer_file
301
-
321
+ self .init (file , options )
302
322
self .set_cols (col_names )
303
323
self .set_assignment_map (assignment_map )
304
324
self .set_authority_map (authority_map )
0 commit comments