Skip to content

Commit c5454fa

Browse files
committed
project form now pulling in project associations
1 parent a44ff49 commit c5454fa

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

ingest/static/ingest/createproject.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function create_new_project() {
55
const name = document.getElementById("name");
66
const funded_by = document.getElementById("funded_by");
77
const consortia_ids = [];
8+
let parent_project;
89

910
let options = document.getElementsByTagName('select')[0]
1011
for (let i=0, length=options.length; i<length; i++) {
@@ -15,10 +16,21 @@ function create_new_project() {
1516
}
1617
}
1718

19+
let parent_project_options = document.getElementsByTagName('select')[1]
20+
for (let i=0, length=parent_project_options.length; i<length; i++) {
21+
let opt = parent_project_options[i];
22+
23+
if (opt.selected) {
24+
parent_project = opt.value;
25+
}
26+
}
27+
28+
console.log(parent_project)
1829
output_rows.push({
1930
"name": name.value,
2031
"funded_by": funded_by.value,
21-
"consortia_ids": consortia_ids
32+
"consortia_ids": consortia_ids,
33+
"parent_project": parent_project
2234
})
2335

2436

ingest/templates/ingest/manage_projects.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ <h1>Manage Projects</h1>
1919
<th>Name</th>
2020
<th>Funded By</th>
2121
<th>Consortia Affiliation</th>
22+
<th>Parent Project Affiliation</th>
2223
<th>Personnel</th>
2324
<th>Submissions</th>
2425
</tr>
@@ -29,6 +30,7 @@ <h1>Manage Projects</h1>
2930
<td>{{ project.name }}</td>
3031
<td>{{ project.funded_by }}</td>
3132
<td>{{ project.short_names }}</td>
33+
<td>{{ project.parent_project }}</td>
3234

3335
<td><a href="{% url 'ingest:view_project_people' project.id %}">View Personnel</td>
3436
<td><a href="{% url 'ingest:view_project_collections' project.id %}">View Submissions</td>

ingest/templates/ingest/project_form.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ <h1>Create a new project</h1>
3535
{% endfor %}
3636
</select>
3737
</div>
38+
<br>
39+
<label for="parent_project" style="margin-top:15px;">Project Affiliation:</label>
40+
<p>Is this a sub-project of another project? Select your project's parent project.</p>
41+
<div style="margin-left: 50px;">
42+
<select style="min-width: 540px;">
43+
<option></option>
44+
{% for a in allprojects %}
45+
<option value={{a.id}}>{{a.name}}: ({{a.funded_by}})</option>
46+
{% endfor %}
47+
</select>
48+
</div>
3849
</form>
3950
<div>
4051

ingest/views.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .field_list import required_metadata
2929
from .filters import CollectionFilter
3030
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
3232
from .tables import CollectionTable, DescriptiveMetadataTable, CollectionRequestTable
3333
import uuid
3434
import datetime
@@ -212,6 +212,7 @@ def manageProjects(request):
212212
short_name = Consortium.objects.get(id=c.id).short_name
213213
project.short_names.append(short_name)
214214
project.short_names = ', '.join(project.short_names)
215+
# project.parent_project = ProjectAssociation.objects.get(project_id=project.id)
215216
return render(request, 'ingest/manage_projects.html', {'allprojects':allprojects, 'pi':pi})
216217

217218
# this functions allows pi to see all the collections
@@ -240,27 +241,36 @@ def project_form(request):
240241
current_user = request.user
241242
people = People.objects.get(auth_user_id_id = current_user.id)
242243
project_person = ProjectPeople.objects.filter(people_id = people.id).all()
244+
allprojects=[]
245+
for row in project_person:
246+
project_id = row.project_id_id
247+
project = Project.objects.get(id=project_id)
248+
allprojects.append(project)
249+
243250
consortia = Consortium.objects.all
244251
for attribute in project_person:
245252
if attribute.is_pi:
246253
pi = True
247254
else:
248255
pi = False
249-
return render(request, 'ingest/project_form.html', {'pi':pi, 'consortia':consortia})
256+
return render(request, 'ingest/project_form.html', {'pi':pi, 'allprojects':allprojects, 'consortia':consortia})
250257

251258
# takes the data from project_form
252259
@login_required
253260
def create_project(request):
254261
new_project = json.loads(request.body)
262+
print(new_project)
255263
items = []
256264
for item in new_project:
257265
items.append(item['funded_by'])
258266
items.append(item['name'])
259267
items.append(item['consortia_ids'])
268+
items.append(item['parent_project'])
260269

261270
funded_by = item['funded_by']
262271
name = item['name']
263272
consortia_ids = item['consortia_ids']
273+
parent_project = item['parent_project']
264274

265275
# write project to the project table
266276
project = Project(funded_by=funded_by, name=name)
@@ -272,6 +282,9 @@ def create_project(request):
272282
project_consortium = ProjectConsortium(project_id=proj_id, consortium_id=c)
273283
project_consortium.save()
274284

285+
project_association = ProjectAssociation(project_id=proj_id, parent_project_id=int(parent_project))
286+
project_association.save()
287+
275288

276289
# create a project_people row for this pi so they can view project on pi dashboard
277290
project_id_id = project.id

manage_projects.html

Whitespace-only changes.

0 commit comments

Comments
 (0)