Skip to content

Commit 219d28f

Browse files
authored
Merge pull request #218 from brain-image-library/feature/consortia-frfr
WIP - Feature/consortia
2 parents ed1305b + 7e12b2b commit 219d28f

File tree

7 files changed

+118
-29
lines changed

7 files changed

+118
-29
lines changed

ingest/admin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from django.utils.translation import ugettext_lazy
99

1010
from django.db.models import F
11-
from .models import ImageMetadata, Collection, People, Project, DescriptiveMetadata, Contributor, Instrument, Dataset, Specimen, Image, EventsLog, Sheet, ProjectPeople, Funder, Publication
11+
from .models import ImageMetadata, Collection, People, Project, DescriptiveMetadata, Contributor, Instrument, Dataset, Specimen, Image, EventsLog, Sheet, ProjectPeople, Funder, Publication, Consortium
1212
admin.site.site_header = 'Brain Image Library Admin Portal'
1313
class ContributorsInline(admin.TabularInline):
1414
model = Contributor
@@ -24,6 +24,8 @@ class SpecimensInline(admin.TabularInline):
2424
model = Specimen
2525
class ImagesInline(admin.TabularInline):
2626
model = Image
27+
class ConsortiaInline(admin.TabularInline):
28+
model = Consortium
2729
admin.site.disable_action('delete_selected')
2830
@admin.action(description='Mark selected Collection(s) as Validated and Submitted')
2931
def mark_as_validated_and_submitted(modeladmin, request, queryset):
@@ -115,3 +117,6 @@ class EventsLogAdmin(admin.ModelAdmin):
115117
@admin.register(ProjectPeople)
116118
class ProjectPeople(admin.ModelAdmin):
117119
list_display = ("id", "project_id", "people_id", "is_po", "is_po", "doi_role")
120+
@admin.register(Consortium)
121+
class Consortium(admin.ModelAdmin):
122+
list_display = ("id", "short_name", "long_name")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 3.2.18 on 2023-06-01 15:23
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', '0014_metadataversion'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Consortium',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('short_name', models.CharField(max_length=256)),
19+
('long_name', models.CharField(max_length=1000)),
20+
],
21+
),
22+
migrations.CreateModel(
23+
name='ProjectConsortium',
24+
fields=[
25+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26+
('consortium', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ingest.consortium')),
27+
('project', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='ingest.project')),
28+
],
29+
),
30+
]

ingest/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def __str__(self):
1818
funded_by = models.CharField(max_length=256)
1919
is_biccn = models.BooleanField(default=False)
2020

21+
class Consortium(models.Model):
22+
short_name = models.CharField(max_length=256)
23+
long_name = models.CharField(max_length=1000)
24+
25+
class ProjectConsortium(models.Model):
26+
project = models.ForeignKey(Project, on_delete=models.SET_NULL, blank=False, null=True)
27+
consortium = models.ForeignKey(Consortium, on_delete=models.SET_NULL, null = True, blank=True)
28+
2129
class People(models.Model):
2230
def __str__(self):
2331
return self.name

ingest/static/ingest/createproject.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ function create_new_project() {
33
const output_rows = [];
44

55
const name = document.getElementById("name");
6-
const is_biccn = document.getElementById("is_biccn");
7-
const funded_my = document.getElementById("is_biccn");
6+
const funded_by = document.getElementById("funded_by");
7+
const consortia_ids = [];
8+
9+
let options = document.getElementsByTagName('select')[0]
10+
for (let i=0, length=options.length; i<length; i++) {
11+
let opt = options[i];
12+
13+
if (opt.selected) {
14+
consortia_ids.push(opt.value);
15+
console.log(opt.value);
16+
}
17+
}
18+
19+
console.log(consortia_ids)
820

921
output_rows.push({
1022
"name": name.value,
11-
"is_biccn": is_biccn.value,
12-
"funded_by": funded_by.value
23+
"funded_by": funded_by.value,
24+
"consortia_ids": consortia_ids
1325
})
1426

1527
console.log(output_rows)

ingest/templates/ingest/manage_projects.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>Manage Projects</h1>
1818
<tr>
1919
<th>Name</th>
2020
<th>Funded By</th>
21-
<th>Is BICCN?</th>
21+
<th>Consortia Affiliation</th>
2222
<th>Personnel</th>
2323
<th>Submissions</th>
2424
</tr>
@@ -28,7 +28,8 @@ <h1>Manage Projects</h1>
2828
<tr>
2929
<td>{{ project.name }}</td>
3030
<td>{{ project.funded_by }}</td>
31-
<td>{{ project.is_biccn }}</td>
31+
<td>{{ project.short_names }}</td>
32+
3233
<td><a href="{% url 'ingest:view_project_people' project.id %}">View Personnel</td>
3334
<td><a href="{% url 'ingest:view_project_collections' project.id %}">View Submissions</td>
3435
</tr>
Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{% extends 'ingest/base.html' %}
2-
{% block content %}
1+
{% extends 'ingest/wide.html' %}
32
{% load bootstrap4 %}
3+
{% block wide %}
4+
45
<script src="/static/ingest/createproject.js"></script>
56
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>
67
{% if pi %}
@@ -10,25 +11,41 @@
1011
{% endif %}
1112
<br>
1213
<h1>Create a new project</h1>
14+
<hr>
15+
16+
<br>
17+
<div style="min-width:600px">
1318

1419
<form id="CreateNewProject">
1520
{% csrf_token %}
21+
<label for="name">Project Name:</label><span style="color:red; margin-right:10px;">*</span>
22+
<input type="text" id="name" name="name" placeholder="Name of project">
1623

17-
<label for="name">Project Name:</label>
18-
<input type="text" id="name" name="name">
24+
<label for="funded_by" style="margin-top:15px;margin-left:55px;margin-right:10px;">Funded By:</label>
25+
<input type="text" id="funded_by" name="funded_by" placeholder="Grant number">
1926

20-
<label for="is_biccn">Is BICCN?:</label>
21-
<select name="is_biccn" id="is_biccn">
22-
<option value="True"> True </option>
23-
<option value="False"> False </option>
24-
</select>
25-
<label for="funded_by">Funded By:</label>
26-
<input type="text" id="funded_by" name="funded_by">
27+
<br>
28+
<label for="consortia" style="margin-top:15px;">Consortia Affiliation:</label>
29+
<p>Select your project's affiliation(s). Choose all that apply.</p>
30+
<div style="margin-left: 50px;">
31+
<p style="font-style:italic; margin-top: 20px;"> To choose multiple: Windows users: control-click | Mac users: command-click</p>
32+
<select multiple size={{consortia.count}} style="min-width: 540px;">
33+
{% for c in consortia %}
34+
<option value={{c.id}}>{{c.long_name}} ({{c.short_name}})</option>
35+
{% endfor %}
36+
</select>
37+
</div>
2738
</form>
28-
<button class="btn btn-primary" onclick="create_new_project();">Submit New Project</button>
29-
<hr>
39+
<div>
3040

41+
<br>
42+
43+
<p style="margin-top:15px;"><b>Required fields are marked with an <span style="color:red;">*</span>.</b></p>
44+
45+
<br>
46+
<button class="btn btn-primary" onclick="create_new_project();">Submit New Project</button>
3147
<a href="{% url 'ingest:index' %}">
3248
<button class="cancel btn btn btn-primary" value="ignore" formnovalidate="">Cancel</button>
3349
</a>
50+
3451
{% endblock %}

ingest/views.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .field_list import required_metadata
2828
from .filters import CollectionFilter
2929
from .forms import CollectionForm, ImageMetadataForm, DescriptiveMetadataForm, UploadForm, collection_send
30-
from .models import UUID, Collection, ImageMetadata, DescriptiveMetadata, Project, ProjectPeople, People, Project, EventsLog, Contributor, Funder, Publication, Instrument, Dataset, Specimen, Image, Sheet
30+
from .models import UUID, Collection, ImageMetadata, DescriptiveMetadata, Project, ProjectPeople, People, Project, EventsLog, Contributor, Funder, Publication, Instrument, Dataset, Specimen, Image, Sheet, Consortium, ProjectConsortium
3131
from .tables import CollectionTable, DescriptiveMetadataTable, CollectionRequestTable
3232
import uuid
3333
import datetime
@@ -119,6 +119,7 @@ def modify_user(request, pk):
119119
else:
120120
pi = False
121121
person = People.objects.get(auth_user_id_id = pk)
122+
122123
all_project_people = ProjectPeople.objects.filter(people_id_id=person.id).all()
123124
for project_person in all_project_people:
124125
try:
@@ -202,8 +203,14 @@ def manageProjects(request):
202203
for row in project_person:
203204
project_id = row.project_id_id
204205
project = Project.objects.get(id=project_id)
205-
allprojects.append(project)
206-
206+
allprojects.append(project)
207+
208+
project_consortia = ProjectConsortium.objects.filter(project_id=project.id).all()
209+
project.short_names = []
210+
for c in project_consortia:
211+
short_name = Consortium.objects.get(id=c.id).short_name
212+
project.short_names.append(short_name)
213+
project.short_names = ', '.join(project.short_names)
207214
return render(request, 'ingest/manage_projects.html', {'allprojects':allprojects, 'pi':pi})
208215

209216
# this functions allows pi to see all the collections
@@ -232,30 +239,39 @@ def project_form(request):
232239
current_user = request.user
233240
people = People.objects.get(auth_user_id_id = current_user.id)
234241
project_person = ProjectPeople.objects.filter(people_id = people.id).all()
242+
consortia = Consortium.objects.all
235243
for attribute in project_person:
236244
if attribute.is_pi:
237245
pi = True
238246
else:
239247
pi = False
240-
return render(request, 'ingest/project_form.html', {'pi':pi})
248+
return render(request, 'ingest/project_form.html', {'pi':pi, 'consortia':consortia})
241249

242250
# takes the data from project_form
243251
@login_required
244252
def create_project(request):
245253
new_project = json.loads(request.body)
254+
print(new_project)
246255
items = []
247256
for item in new_project:
248257
items.append(item['funded_by'])
249-
items.append(item['is_biccn'])
250258
items.append(item['name'])
251-
259+
items.append(item['consortia_ids'])
260+
252261
funded_by = item['funded_by']
253-
is_biccn = item['is_biccn']
254262
name = item['name']
255-
263+
consortia_ids = item['consortia_ids']
264+
256265
# write project to the project table
257-
project = Project(funded_by=funded_by, is_biccn=is_biccn, name=name)
266+
project = Project(funded_by=funded_by, name=name)
258267
project.save()
268+
269+
proj_id = project.id
270+
271+
for c in consortia_ids:
272+
project_consortium = ProjectConsortium(project_id=proj_id, consortium_id=c)
273+
project_consortium.save()
274+
259275

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

0 commit comments

Comments
 (0)