28
28
from .field_list import required_metadata
29
29
from .filters import CollectionFilter
30
30
from .forms import CollectionForm , ImageMetadataForm , DescriptiveMetadataForm , UploadForm , collection_send
31
- from .models import UUID , Collection , ImageMetadata , DescriptiveMetadata , Project , ProjectPeople , People , Project , EventsLog , Contributor , Funder , Publication , Instrument , Dataset , Specimen , Image , Sheet , Consortium , ProjectConsortium , SWC
31
+ from .models import UUID , Collection , ImageMetadata , DescriptiveMetadata , Project , ProjectPeople , People , Project , EventsLog , Contributor , Funder , Publication , Instrument , Dataset , Specimen , Image , Sheet , Consortium , ProjectConsortium , SWC , ProjectAssociation
32
32
from .tables import CollectionTable , DescriptiveMetadataTable , CollectionRequestTable
33
33
import uuid
34
34
import datetime
@@ -209,9 +209,25 @@ def manageProjects(request):
209
209
project_consortia = ProjectConsortium .objects .filter (project_id = project .id ).all ()
210
210
project .short_names = []
211
211
for c in project_consortia :
212
- short_name = Consortium .objects .get (id = c .id ).short_name
212
+ short_name = Consortium .objects .get (id = c .consortium_id ).short_name
213
213
project .short_names .append (short_name )
214
214
project .short_names = ', ' .join (project .short_names )
215
+
216
+ proj_assocs = ProjectAssociation .objects .filter (project_id = project .id ).all ()
217
+ parent_proj_assocs = ProjectAssociation .objects .filter (parent_project_id = project .id ).all ()
218
+
219
+ project .parent_project_names = []
220
+ for p in proj_assocs :
221
+ parent_project_name = Project .objects .get (id = p .parent_project_id ).name
222
+ project .parent_project_names .append (parent_project_name )
223
+ project .parent_project_names = ', ' .join (project .parent_project_names )
224
+
225
+ project .child_project_names = []
226
+ for pa in parent_proj_assocs :
227
+ child_project_name = Project .objects .get (id = pa .project_id ).name
228
+ project .child_project_names .append (child_project_name )
229
+ project .child_project_names = ', ' .join (project .child_project_names )
230
+
215
231
return render (request , 'ingest/manage_projects.html' , {'allprojects' :allprojects , 'pi' :pi })
216
232
217
233
# this functions allows pi to see all the collections
@@ -240,27 +256,36 @@ def project_form(request):
240
256
current_user = request .user
241
257
people = People .objects .get (auth_user_id_id = current_user .id )
242
258
project_person = ProjectPeople .objects .filter (people_id = people .id ).all ()
259
+ allprojects = []
260
+ for row in project_person :
261
+ project_id = row .project_id_id
262
+ project = Project .objects .get (id = project_id )
263
+ allprojects .append (project )
264
+
243
265
consortia = Consortium .objects .all
244
266
for attribute in project_person :
245
267
if attribute .is_pi :
246
268
pi = True
247
269
else :
248
270
pi = False
249
- return render (request , 'ingest/project_form.html' , {'pi' :pi , 'consortia' :consortia })
271
+ return render (request , 'ingest/project_form.html' , {'pi' :pi , 'allprojects' : allprojects , ' consortia' :consortia })
250
272
251
273
# takes the data from project_form
252
274
@login_required
253
275
def create_project (request ):
254
276
new_project = json .loads (request .body )
277
+ print (new_project )
255
278
items = []
256
279
for item in new_project :
257
280
items .append (item ['funded_by' ])
258
281
items .append (item ['name' ])
259
282
items .append (item ['consortia_ids' ])
283
+ items .append (item ['parent_project' ])
260
284
261
285
funded_by = item ['funded_by' ]
262
286
name = item ['name' ]
263
287
consortia_ids = item ['consortia_ids' ]
288
+ parent_project = item ['parent_project' ]
264
289
265
290
# write project to the project table
266
291
project = Project (funded_by = funded_by , name = name )
@@ -272,6 +297,9 @@ def create_project(request):
272
297
project_consortium = ProjectConsortium (project_id = proj_id , consortium_id = c )
273
298
project_consortium .save ()
274
299
300
+ project_association = ProjectAssociation (project_id = proj_id , parent_project_id = int (parent_project ))
301
+ project_association .save ()
302
+
275
303
276
304
# create a project_people row for this pi so they can view project on pi dashboard
277
305
project_id_id = project .id
0 commit comments