Skip to content

Commit 01f2be3

Browse files
committed
update branch with dev
2 parents 8fdc37a + 219d28f commit 01f2be3

File tree

7 files changed

+127
-30
lines changed

7 files changed

+127
-30
lines changed

ingest/admin.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
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,SWC
11+
12+
from .models import ImageMetadata, Collection, People, Project, DescriptiveMetadata, Contributor, Instrument, Dataset, Specimen, Image, EventsLog, Sheet, ProjectPeople, Funder, Publication, Consortium, SWC
13+
1214
admin.site.site_header = 'Brain Image Library Admin Portal'
1315
class ContributorsInline(admin.TabularInline):
1416
model = Contributor
@@ -24,8 +26,13 @@ class SpecimensInline(admin.TabularInline):
2426
model = Specimen
2527
class ImagesInline(admin.TabularInline):
2628
model = Image
29+
<<<<<<< HEAD
2730
class SWCSInline(admin.TabularInline):
2831
model = SWC
32+
=======
33+
class ConsortiaInline(admin.TabularInline):
34+
model = Consortium
35+
>>>>>>> dev
2936
admin.site.disable_action('delete_selected')
3037
@admin.action(description='Mark selected Collection(s) as Validated and Submitted')
3138
def mark_as_validated_and_submitted(modeladmin, request, queryset):
@@ -117,6 +124,12 @@ class EventsLogAdmin(admin.ModelAdmin):
117124
@admin.register(ProjectPeople)
118125
class ProjectPeople(admin.ModelAdmin):
119126
list_display = ("id", "project_id", "people_id", "is_po", "is_po", "doi_role")
127+
<<<<<<< HEAD
120128
@admin.register(SWC)
121129
class SWC(admin.ModelAdmin):
122-
list_display = ("id", "tracingFile", "sourceData", "sourceDataSample", "sourceDataSubmission", "coordinates", "coordinatesRegistration", "brainRegion", "brainRegionAtlas", "brainRegionAtlasName", "brainRegionAxonalProjection", "brainRegionDendriticProjection", "neuronType","segmentTags","proofreadingLevel", "notes", "sheet")
130+
list_display = ("id", "tracingFile", "sourceData", "sourceDataSample", "sourceDataSubmission", "coordinates", "coordinatesRegistration", "brainRegion", "brainRegionAtlas", "brainRegionAtlasName", "brainRegionAxonalProjection", "brainRegionDendriticProjection", "neuronType","segmentTags","proofreadingLevel", "notes", "sheet")
131+
=======
132+
@admin.register(Consortium)
133+
class Consortium(admin.ModelAdmin):
134+
list_display = ("id", "short_name", "long_name")
135+
>>>>>>> dev
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
@@ -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, 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
3232
from .tables import CollectionTable, DescriptiveMetadataTable, CollectionRequestTable
3333
import uuid
3434
import datetime
@@ -120,6 +120,7 @@ def modify_user(request, pk):
120120
else:
121121
pi = False
122122
person = People.objects.get(auth_user_id_id = pk)
123+
123124
all_project_people = ProjectPeople.objects.filter(people_id_id=person.id).all()
124125
for project_person in all_project_people:
125126
try:
@@ -203,8 +204,14 @@ def manageProjects(request):
203204
for row in project_person:
204205
project_id = row.project_id_id
205206
project = Project.objects.get(id=project_id)
206-
allprojects.append(project)
207-
207+
allprojects.append(project)
208+
209+
project_consortia = ProjectConsortium.objects.filter(project_id=project.id).all()
210+
project.short_names = []
211+
for c in project_consortia:
212+
short_name = Consortium.objects.get(id=c.id).short_name
213+
project.short_names.append(short_name)
214+
project.short_names = ', '.join(project.short_names)
208215
return render(request, 'ingest/manage_projects.html', {'allprojects':allprojects, 'pi':pi})
209216

210217
# this functions allows pi to see all the collections
@@ -233,30 +240,39 @@ def project_form(request):
233240
current_user = request.user
234241
people = People.objects.get(auth_user_id_id = current_user.id)
235242
project_person = ProjectPeople.objects.filter(people_id = people.id).all()
243+
consortia = Consortium.objects.all
236244
for attribute in project_person:
237245
if attribute.is_pi:
238246
pi = True
239247
else:
240248
pi = False
241-
return render(request, 'ingest/project_form.html', {'pi':pi})
249+
return render(request, 'ingest/project_form.html', {'pi':pi, 'consortia':consortia})
242250

243251
# takes the data from project_form
244252
@login_required
245253
def create_project(request):
246254
new_project = json.loads(request.body)
255+
print(new_project)
247256
items = []
248257
for item in new_project:
249258
items.append(item['funded_by'])
250-
items.append(item['is_biccn'])
251259
items.append(item['name'])
252-
260+
items.append(item['consortia_ids'])
261+
253262
funded_by = item['funded_by']
254-
is_biccn = item['is_biccn']
255263
name = item['name']
256-
264+
consortia_ids = item['consortia_ids']
265+
257266
# write project to the project table
258-
project = Project(funded_by=funded_by, is_biccn=is_biccn, name=name)
267+
project = Project(funded_by=funded_by, name=name)
259268
project.save()
269+
270+
proj_id = project.id
271+
272+
for c in consortia_ids:
273+
project_consortium = ProjectConsortium(project_id=proj_id, consortium_id=c)
274+
project_consortium.save()
275+
260276

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

0 commit comments

Comments
 (0)