Skip to content

Commit 29c3ae2

Browse files
authored
Merge pull request #223 from brain-image-library/feature/parent-project-associations
Feature/parent project associations
2 parents 6b13dea + 0f64308 commit 29c3ae2

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.2.18 on 2023-06-26 11:18
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('ingest', '0017_merge_20230608_1210'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='ProjectAssociation',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('parent_project', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='parent_project', to='ingest.project')),
19+
('project', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='project', to='ingest.project')),
20+
],
21+
),
22+
]

ingest/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class ProjectConsortium(models.Model):
2626
project = models.ForeignKey(Project, on_delete=models.SET_NULL, blank=False, null=True)
2727
consortium = models.ForeignKey(Consortium, on_delete=models.SET_NULL, null = True, blank=True)
2828

29+
class ProjectAssociation(models.Model):
30+
project = models.ForeignKey(Project, related_name='project', on_delete=models.SET_NULL, blank=False, null=True)
31+
parent_project = models.ForeignKey(Project, related_name='parent_project', on_delete=models.SET_NULL, blank=False, null=True)
32+
2933
class People(models.Model):
3034
def __str__(self):
3135
return self.name

ingest/static/ingest/createproject.js

Lines changed: 12 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,20 @@ 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+
1828
output_rows.push({
1929
"name": name.value,
2030
"funded_by": funded_by.value,
21-
"consortia_ids": consortia_ids
31+
"consortia_ids": consortia_ids,
32+
"parent_project": parent_project
2233
})
2334

2435

ingest/templates/ingest/manage_projects.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ <h1>Manage Projects</h1>
1919
<th>Name</th>
2020
<th>Funded By</th>
2121
<th>Consortia Affiliation</th>
22+
<th>Parent Project Affiliation</th>
23+
<th>Child Project Affiliations</th>
2224
<th>Personnel</th>
2325
<th>Submissions</th>
2426
</tr>
@@ -29,6 +31,8 @@ <h1>Manage Projects</h1>
2931
<td>{{ project.name }}</td>
3032
<td>{{ project.funded_by }}</td>
3133
<td>{{ project.short_names }}</td>
34+
<td>{{ project.parent_project_names }}</td>
35+
<td>{{ project.child_project_names }}</td>
3236

3337
<td><a href="{% url 'ingest:view_project_people' project.id %}">View Personnel</td>
3438
<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: 31 additions & 3 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
@@ -209,9 +209,25 @@ def manageProjects(request):
209209
project_consortia = ProjectConsortium.objects.filter(project_id=project.id).all()
210210
project.short_names = []
211211
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
213213
project.short_names.append(short_name)
214214
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+
215231
return render(request, 'ingest/manage_projects.html', {'allprojects':allprojects, 'pi':pi})
216232

217233
# this functions allows pi to see all the collections
@@ -240,27 +256,36 @@ def project_form(request):
240256
current_user = request.user
241257
people = People.objects.get(auth_user_id_id = current_user.id)
242258
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+
243265
consortia = Consortium.objects.all
244266
for attribute in project_person:
245267
if attribute.is_pi:
246268
pi = True
247269
else:
248270
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})
250272

251273
# takes the data from project_form
252274
@login_required
253275
def create_project(request):
254276
new_project = json.loads(request.body)
277+
print(new_project)
255278
items = []
256279
for item in new_project:
257280
items.append(item['funded_by'])
258281
items.append(item['name'])
259282
items.append(item['consortia_ids'])
283+
items.append(item['parent_project'])
260284

261285
funded_by = item['funded_by']
262286
name = item['name']
263287
consortia_ids = item['consortia_ids']
288+
parent_project = item['parent_project']
264289

265290
# write project to the project table
266291
project = Project(funded_by=funded_by, name=name)
@@ -272,6 +297,9 @@ def create_project(request):
272297
project_consortium = ProjectConsortium(project_id=proj_id, consortium_id=c)
273298
project_consortium.save()
274299

300+
project_association = ProjectAssociation(project_id=proj_id, parent_project_id=int(parent_project))
301+
project_association.save()
302+
275303

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

manage_projects.html

Whitespace-only changes.

0 commit comments

Comments
 (0)