Skip to content

Commit

Permalink
Merge pull request #195 from CogStack/django-update
Browse files Browse the repository at this point in the history
Django update to 5.0
  • Loading branch information
tomolopolis authored Jul 3, 2024
2 parents 062b509 + e9ad7cb commit 39d3c8f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 35 deletions.
3 changes: 3 additions & 0 deletions envs/env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ MEDCAT_CONFIG_FILE=/home/configs/base.txt
### Deployment Realm ###
ENV=non-prod

# Complete once this is deployed
CSRF_TRUSTED_ORIGINS=

### Django debug setting - to live-reload etc. ###
DEBUG=True

Expand Down
3 changes: 3 additions & 0 deletions envs/env-prod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ENV=prod
# SECRET KEY - edit this for prod deployments,
# SECRET_KEY=

# Complete once this is deployed
CSRF_TRUSTED_ORIGINS=

# Django Debug mode should be False for prod
DEBUG=False

Expand Down
20 changes: 20 additions & 0 deletions webapp/api/api/migrations/0078_alter_project_polymorphic_ctype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.0.6 on 2024-06-07 11:18

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0077_projectgroup_create_associated_projects'),
('contenttypes', '0002_remove_content_type_name'),
]

operations = [
migrations.AlterField(
model_name='project',
name='polymorphic_ctype',
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_%(app_label)s.%(class)s_set+', to='contenttypes.contenttype'),
),
]
14 changes: 14 additions & 0 deletions webapp/api/api/migrations/0079_merge_20240701_2259.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.28 on 2024-07-01 22:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api', '0078_metacatmodel_modelpack'),
('api', '0078_alter_project_polymorphic_ctype'),
]

operations = [
]
21 changes: 14 additions & 7 deletions webapp/api/api/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil

from django.core.exceptions import ObjectDoesNotExist
from django.db.models.fields.files import FileField
from django.db.models.signals import post_save, post_delete, pre_save
from django.dispatch import receiver
Expand Down Expand Up @@ -46,13 +47,19 @@ def save_exported_projects(sender, instance, **kwargs):

@receiver(post_delete, sender=ModelPack)
def remove_model_pack_assets(sender, instance, **kwargs):
if instance.concept_db:
instance.concept_db.delete(using=None, keep_parents=False)
if instance.vocab:
instance.vocab.delete(using=None, keep_parents=False)
if len(instance.meta_cats.all()) > 0:
for m_c in instance.meta_cats.all():
m_c.delete(using=None, keep_parents=False)
try:
if instance.concept_db:
instance.concept_db.delete(using=None, keep_parents=False)
except ObjectDoesNotExist:
pass # if a ConceptDB of a model pack is removed, this will cascade ModelPack removal.
try:
if instance.vocab:
instance.vocab.delete(using=None, keep_parents=False)
if len(instance.meta_cats.all()) > 0:
for m_c in instance.meta_cats.all():
m_c.delete(using=None, keep_parents=False)
except ObjectDoesNotExist:
pass # if a vocab of a model pack is removed, this will cascade ModelPack removal.
try:
# rm the model pack unzipped dir & model pack zip
shutil.rmtree(instance.model_pack.path.replace(".zip", ""))
Expand Down
8 changes: 6 additions & 2 deletions webapp/api/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@

log = logging.getLogger(__name__)

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

environ_origins = os.environ.get('CSRF_TRUSTED_ORIGINS', None)
trusted_origins = [] if environ_origins is None else environ_origins.split(',')
CSRF_TRUSTED_ORIGINS = ['https://127.0.0.1:8001', 'http://localhost:8001'] + trusted_origins

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
SECURE_CROSS_ORIGIN_OPENER_POLICY = None

# SECURITY WARNING: keep the secret key used in production secret!
realm = os.environ.get('ENV', 'non-prod')
Expand Down
15 changes: 0 additions & 15 deletions webapp/api/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""MedCATtrainer URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.contrib.auth import views as pw_views
from django.urls import path, include, re_path
Expand Down
6 changes: 3 additions & 3 deletions webapp/frontend/src/components/common/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ export default {
components: {LoadingOverlay, Modal},
props: {
projectItems: Array,
isAdmin: Boolean
isAdmin: Boolean,
cdbSearchIndexStatus: Object,
cdbLoaded: Object,
},
data () {
return {
Expand Down Expand Up @@ -213,8 +215,6 @@ export default {
modelCacheLoadError: false,
metricsJobId: null,
saving: false,
cdbSearchIndexStatus: {},
cdbLoaded: {},
clearModelModal: false,
selectedProjects: [],
loadingProjects: false
Expand Down
8 changes: 6 additions & 2 deletions webapp/frontend/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
<p>{{selectedProjectGroup.description}}</p>
</div>
<div slot="body">
<project-list :project-items="selectedProjectGroup.items" :is-admin="isAdmin"></project-list>
<project-list :project-items="selectedProjectGroup.items" :is-admin="isAdmin"
:cdb-search-index-status="cdbSearchIndexStatus" :cdb-loaded="cdbLoaded"></project-list>
</div>
</modal>
</div>
<project-list v-if="!projectGroupView" :project-items="projects.items" :is-admin="isAdmin"></project-list>
<project-list v-if="!projectGroupView" :project-items="projects.items" :is-admin="isAdmin"
:cdb-search-index-status="cdbSearchIndexStatus" :cdb-loaded="cdbLoaded"></project-list>
</div>

</template>
Expand Down Expand Up @@ -69,6 +71,8 @@ export default {
loadingProjects: false,
isAdmin: false,
selectedProjectGroup: null,
cdbSearchIndexStatus: {},
cdbLoaded: {},
}
},
created () {
Expand Down
12 changes: 6 additions & 6 deletions webapp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--extra-index-url https://download.pytorch.org/whl/cpu/
uwsgi~=2.0
Django~=2.2
django-filter~=2.4
Django~=5.0
django-filter~=24.2
django-polymorphic~=3.0
djangorestframework~=3.10
django-background-tasks~=1.2
openpyxl~=3.0
medcat~=1.12
djangorestframework~=3.15
django-background-tasks-updated~=1.2
openpyxl~=3.1
medcat~=1.12

0 comments on commit 39d3c8f

Please sign in to comment.