wmgeolab / scope

4 stars 3 forks source link

Allow selection of multiple activity & actor codes. #80

Closed micrittenden closed 3 years ago

micrittenden commented 3 years ago

This section of the form should look similar to the formset used in the extracting_m module. Is it possible to have this type of formset within a broader form?

Since the activity_subcode(s) has(have) to correspond to the activity_code(s), is there a way to store each as a list in their respective field? E.g., if there are three activity codes for a hydroelectric dam which provides energy, connective infrastructure, and is good for the environment: activity_code: "A_1 - Development Projects, Humanitarian Aid, and Other Non-Military Support", "A_1 - Development Projects, Humanitarian Aid, and Other Non-Military Support", "A_1 - Development Projects, Humanitarian Aid, and Other Non-Military Support" activity_subcode: "A_1002 - Climate & Environment", "A_1004 - Energy & Technology (General)", "A_1011 - Public, Commercial, & Connective Infrastructure"

The above would similarly applied for actor code, name, and role. The only difference is that these fields are not dependent on each other even though they are related.

Here's a picture of very basic concept art for the UI.

karimbahgat commented 3 years ago

Just to document my answers: the way to group the actor code, name, and role is to make them a separate Activity model and link to it. Due to the messiness of javascript buttons for adding nested forms, I just set the formset to have 3 extra blank forms, which should be good for most cases. If more are needed, 3 extra forms will always show up after saving. Probably revisit later, but should work for now.

For the activity code/subcode, the broader code is already implied in the subcode which has a foreignkey to its parent code, so allowing to set both is just more work for the user and opens up for mismatch. Switched to only having a subcode ManyToManyField where the display value includes the parent code text to get a sense of the hierarchy, though this can probably be improved. The default widget here is a weird multiselectbox which we'll probably want to change later. We can probably make a widget that splits this into one or more dropdowns.