Skip to content

Commit

Permalink
Merge pull request #127 from UUDigitalHumanitieslab/feature/upgrade-d…
Browse files Browse the repository at this point in the history
…jango

Feature/upgrade django
  • Loading branch information
tijmenbaarda authored Mar 15, 2023
2 parents c7597cd + 0a1d2c8 commit 926ef59
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 77 deletions.
27 changes: 18 additions & 9 deletions edpop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

from pathlib import Path
import os

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


# Quick-start development settings - unsuitable for production
Expand Down Expand Up @@ -67,7 +68,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],#['./vre/templates/vre', './vre/templates/login'],
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -97,22 +98,29 @@
}
}

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME':
'django.contrib.auth.password_validation.'
'UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME':
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME':
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
'NAME':
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

Expand All @@ -137,10 +145,11 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


LOGIN_URL = '/login/'

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand All @@ -166,6 +175,6 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
BASE_DIR / 'vre' / 'static',
)
STATIC_URL = '/static/'
12 changes: 6 additions & 6 deletions edpop/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.urls import include, path
from django.contrib import admin
from django.contrib.auth import views as auth_views

urlpatterns = [
url(r'^$', auth_views.login, name='login'),
url(r'^vre/', include('vre.urls')),
url(r'^admin/', admin.site.urls),
url(r'^login/$', auth_views.login, name='login'),
url(r'^logout/$', auth_views.logout, name='logout'),
path('', auth_views.LoginView.as_view(), name='login'),
path('vre/', include('vre.urls')),
path('admin/', admin.site.urls),
path('login/', auth_views.LoginView.as_view(), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
]
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pytest==7.1.3
# via
# -r requirements-test.in
# pytest-django
pytest-django==3.10.0
pytest-django==4.5.2
# via -r requirements-test.in
six==1.16.0
# via -r requirements-test.in
Expand Down
4 changes: 2 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
django
django-contrib-postgres
django-json-widget
django-filter
djangorestframework
psycopg2>=2.8,<2.9
psycopg2
requests
lxml
beautifulsoup4
sruthi
47 changes: 30 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,43 @@
#
# pip-compile requirements.in
#
beautifulsoup4==4.6.0
asgiref==3.5.2
# via django
backports-zoneinfo==0.2.1
# via django
beautifulsoup4==4.11.1
# via -r requirements.in
certifi==2017.11.5
certifi==2022.9.24
# via requests
chardet==3.0.4
charset-normalizer==2.1.1
# via requests
django==1.11.29
# via -r requirements.in
django-contrib-postgres==0.0.1
django==4.1.2
# via
# -r requirements.in
# django-filter
# djangorestframework
django-filter==22.1
# via -r requirements.in
django-filter==1.1.0
django-json-widget==1.1.1
# via -r requirements.in
django-json-widget==0.1.1
djangorestframework==3.14.0
# via -r requirements.in
djangorestframework==3.7.7
# via -r requirements.in
idna==2.6
future==0.18.2
# via django-json-widget
idna==3.4
# via requests
lxml==4.1.1
lxml==4.9.1
# via -r requirements.in
psycopg2==2.9.4
# via -r requirements.in
psycopg2==2.8.6
pytz==2022.4
# via djangorestframework
requests==2.28.1
# via -r requirements.in
pytz==2017.2
soupsieve==2.3.2.post1
# via beautifulsoup4
sqlparse==0.4.3
# via django
requests==2.18.4
urllib3==1.22 # via requests
-e git+https://github.com/UUDigitalHumanitieslab/sruthi@backport-python34#egg=sruthi
urllib3==1.26.12
# via requests
sruthi==1.0.0
4 changes: 2 additions & 2 deletions vre/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.views import APIView
from rest_framework.viewsets import ViewSetMixin
from rest_framework.response import Response
from rest_framework.decorators import list_route
from rest_framework.decorators import action
from rest_framework.renderers import JSONRenderer


Expand Down Expand Up @@ -47,7 +47,7 @@ class ListMineMixin(object):
that belong to a research group of the current user.
"""

@list_route()
@action(detail=False)
def mine(self, request):
# get_queryset takes care of the reduced queryset
return self.list(request)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.1.2 on 2023-03-15 15:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('vre', '0004_auto_20210605_1116'),
]

operations = [
migrations.AlterField(
model_name='annotation',
name='content',
field=models.JSONField(verbose_name=dict),
),
migrations.AlterField(
model_name='annotation',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='collection',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='record',
name='content',
field=models.JSONField(verbose_name=dict),
),
migrations.AlterField(
model_name='record',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='researchgroup',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
25 changes: 7 additions & 18 deletions vre/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from django.db import models
from django.contrib import admin
from django.contrib.auth.models import Group, User
from django.contrib.auth.decorators import user_passes_test
from django.contrib.postgres.fields import JSONField
from django.contrib.auth.models import User


class ResearchGroup(models.Model):
Expand Down Expand Up @@ -45,30 +42,22 @@ class Record(models.Model):
"""
uri = models.CharField(max_length=200, blank=True)
collection = models.ManyToManyField(Collection)
content = JSONField(default='VRE Record')
content = models.JSONField(dict)

def __str__(self):
return self.uri


'''
class AnnotationAdmin(admin.modelAdmin):
""" set permissions to edit annotations """
# each group sharing the same record has their own annotation
# they can see, but not edit other groups' annotations
pass
'''

class Annotation(models.Model):
""" Import the fields of a given record, and stores annotations to its fields,
as well as extra information.
""" Import the fields of a given record, and stores annotations to its
fields, as well as extra information.
An annotation is related to exactly one record.
One record can have multiple annotations.
An annotation is also linked to exactly one research group,
but multiple groups can add annotations."""
record = models.ForeignKey(Record)
managing_group = models.ForeignKey(ResearchGroup)
content = JSONField(default='VRE Annotation')
record = models.ForeignKey(Record, on_delete=models.CASCADE)
managing_group = models.ForeignKey(ResearchGroup, on_delete=models.CASCADE)
content = models.JSONField(dict)

def __str__(self):
return '{} ({})'.format(self.record.uri, self.managing_group.name)
8 changes: 2 additions & 6 deletions vre/sru_query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import requests
import os
import csv
import logging

Expand All @@ -15,11 +14,8 @@
VD16_URI = 'http://gateway-bayern.de/{}' # Spaces should be replaced by +
VD17_URI = 'https://kxp.k10plus.de/DB=1.28/CMD?ACT=SRCHA&IKT=8079&TRM=%27{}%27'
VD18_URI = 'https://kxp.k10plus.de/DB=1.65/SET=1/TTL=1/CMD?ACT=SRCHA&IKT=1016&SRT=YOP&TRM={}&ADI_MAT=B&MATCFILTER=Y&MATCSET=Y&ADI_MAT=T&REC=*'
READABLE_FIELDS_FILE = os.path.join(
settings.BASE_DIR,
"vre",
"M21_readable_fields.csv",
)
READABLE_FIELDS_FILE = settings.BASE_DIR / 'vre' \
/ "M21_readable_fields.csv"

RECORDS_PER_PAGE = 15

Expand Down
17 changes: 10 additions & 7 deletions vre/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url, include
from django.urls import path, include
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from rest_framework import routers
Expand All @@ -10,14 +10,17 @@
api_router.register(r'collections', api.CollectionViewSet)
api_router.register(r'records', api.RecordViewSet)
api_router.register(r'annotations', api.AnnotationViewSet)
api_router.register(r'search', api.SearchViewSet, base_name='search')
api_router.register(r'add-selection', api.AddRecordsViewSet, base_name='add-selection')
api_router.register(r'search', api.SearchViewSet, basename='search')
api_router.register(r'add-selection',
api.AddRecordsViewSet,
basename='add-selection')

urlpatterns = [
url(r'^api/', include(api_router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^$', views.index, name='index'),
url(r'^(?P<database_id>[a-zA-Z0-9]+)/$', views.index, name='index'),
path('api/', include(api_router.urls)),
path('api-auth/',
include('rest_framework.urls', namespace='rest_framework')),
path('', views.index, name='index'),
path('<slug:id>', views.index, name='index'),
]

urlpatterns += staticfiles_urlpatterns()
16 changes: 7 additions & 9 deletions vre/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import json

from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render, render_to_response
from django.core import serializers
from django.shortcuts import render
from rest_framework.renderers import JSONRenderer

from .models import Record, ResearchGroup, Collection
from .models import ResearchGroup, Collection
from .serializers import CollectionSerializer, ResearchGroupSerializer

CERL_SRU_URL = "http://sru.cerl.org/thesaurus"
Expand All @@ -24,8 +19,11 @@ def index(request, database_id=None):
prefetched_collections = CollectionSerializer(user_collections, many=True)
prefetched_groups = ResearchGroupSerializer(all_groups, many=True)
response_dict = {
'prefetched_collections': JSONRenderer().render(prefetched_collections.data),
'prefetched_groups': JSONRenderer().render(prefetched_groups.data)}
'prefetched_collections':
JSONRenderer().render(prefetched_collections.data).decode(),
'prefetched_groups':
JSONRenderer().render(prefetched_groups.data).decode()
}
if database_id:
response_dict['id'] = database_id
return render(
Expand Down

0 comments on commit 926ef59

Please sign in to comment.