Skip to content

Commit 3af7d36

Browse files
Luke TuiteLuke Tuite
authored andcommitted
successfully saving consortia to projectconsortia table.. need to display still
1 parent 3c6db25 commit 3af7d36

File tree

6 files changed

+43
-15
lines changed

6 files changed

+43
-15
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")

ingest/migrations/0015_consortium_projectconsortium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Migration(migrations.Migration):
2323
name='ProjectConsortium',
2424
fields=[
2525
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26-
('constorium', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ingest.consortium')),
26+
('consortium', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ingest.consortium')),
2727
('project', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='ingest.project')),
2828
],
2929
),

ingest/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Consortium(models.Model):
2424

2525
class ProjectConsortium(models.Model):
2626
project = models.ForeignKey(Project, on_delete=models.SET_NULL, blank=False, null=True)
27-
constorium = models.ForeignKey(Consortium, on_delete=models.SET_NULL, null = True, blank=True)
27+
consortium = models.ForeignKey(Consortium, on_delete=models.SET_NULL, null = True, blank=True)
2828

2929
class People(models.Model):
3030
def __str__(self):

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ <h1>Manage Projects</h1>
2828
<tr>
2929
<td>{{ project.name }}</td>
3030
<td>{{ project.funded_by }}</td>
31-
<td>{{ project.is_biccn }}</td>
31+
{% for c in consortia %}
32+
<td>{{ c.short_name }}</td>
33+
{% endfor %}
3234
<td><a href="{% url 'ingest:view_project_people' project.id %}">View Personnel</td>
3335
<td><a href="{% url 'ingest:view_project_collections' project.id %}">View Submissions</td>
3436
</tr>

ingest/views.py

Lines changed: 16 additions & 7 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, Consortium
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
@@ -202,7 +202,8 @@ def manageProjects(request):
202202
for row in project_person:
203203
project_id = row.project_id_id
204204
project = Project.objects.get(id=project_id)
205-
allprojects.append(project)
205+
allprojects.append(project)
206+
206207

207208
return render(request, 'ingest/manage_projects.html', {'allprojects':allprojects, 'pi':pi})
208209

@@ -244,19 +245,27 @@ def project_form(request):
244245
@login_required
245246
def create_project(request):
246247
new_project = json.loads(request.body)
248+
print(new_project)
247249
items = []
248250
for item in new_project:
249251
items.append(item['funded_by'])
250-
items.append(item['is_biccn'])
251252
items.append(item['name'])
252-
253+
items.append(item['consortia_ids'])
254+
253255
funded_by = item['funded_by']
254-
is_biccn = item['is_biccn']
255256
name = item['name']
256-
257+
consortia_ids = item['consortia_ids']
258+
257259
# write project to the project table
258-
project = Project(funded_by=funded_by, is_biccn=is_biccn, name=name)
260+
project = Project(funded_by=funded_by, name=name)
259261
project.save()
262+
263+
proj_id = project.id
264+
265+
for c in consortia_ids:
266+
project_consortium = ProjectConsortium(project_id=proj_id, consortium_id=c)
267+
project_consortium.save()
268+
260269

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

0 commit comments

Comments
 (0)