Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Django CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Utilities to link Django to RDF stores and inferencers.
Why: Allows semantic data models and rules to be used to generate rich views of content, and expose standardised access and query interfaces - such as SPARQL and the Linked Data Platform. Conversely, allow use of Django to manage content in RDF stores :-)

## compatibility
Tested with django 1.11 + python 2.7 and django 3.0 with python 3.8
Tested with python 3.10 + django 4.0.2

## Features
* RDF serializer for Django objects driven by editable mapping rules
Expand Down
39 changes: 39 additions & 0 deletions TODOs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# TODOs

## Django 4.X migration

There is an issue with the usage of ContentType.
In Django > 4 it should be used only at runtime:

s. https://stackoverflow.com/questions/43433406/sqlite3-operationalerror-no-such-table-django-content-type

This issue can occur if you have code that uses contenttypes database information at import time rather than at runtime. For example, if you added code that runs at the module level or class level along the lines of:

TERM_CONTENT_TYPE = ContentType.objects.get_for_model(Term)

but you only added this after running your initial migrations that created that content type tables, then the next person who runs the migrations on a fresh database will get this error.

In this case the solution is to move code like that into places that runs only when a method is called, like into a view or other method.



workaround :


sqlite3 <DB filename>

Create the table using the following command:

CREATE TABLE IF
NOT EXISTS "django_content_type" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"app_label" varchar(100) NOT NULL,
"model" varchar(100) NOT NULL
);

Finally run the migrations using the command below:

python manage.py migrate --fake-initial



6 changes: 6 additions & 0 deletions rdf_io/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class RdfIoConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'rdf_io'
4 changes: 2 additions & 2 deletions rdf_io/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.db import models
from django.conf import settings

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
# for django 1.7 +
from django.contrib.contenttypes.fields import GenericForeignKey
#from django.contrib.contenttypes.generic import GenericForeignKey
Expand Down Expand Up @@ -1121,4 +1121,4 @@ def _add_vals(gr, obj, subject, predicate, attr, is_resource ) :





35 changes: 33 additions & 2 deletions rdf_io/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,43 @@
'rdf_io',
)

MIDDLEWARE_CLASSES = (
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
]

# MIDDLEWARE_CLASSES = (
# 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.messages.middleware.MessageMiddleware',
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
# )

ROOT_URLCONF = 'rdf_io.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'rdf_io.wsgi.application'


Expand Down Expand Up @@ -81,3 +107,8 @@
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
4 changes: 4 additions & 0 deletions rdf_io/tests/test_viewspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
# from rdf_io.tests import ObjectMappingTestCase
from .test_mappings import SerialisationSetupTestCase

from rdf_io.signals import clear_signals

class RequestTestCase(SerialisationSetupTestCase):
""" Test case for a view request

"""
def setUp(self):
super(RequestTestCase,self).setUp()
self.factory = RequestFactory()
clear_signals()
#request = self.factory.get('/rdf_io/ctl_signals/off')


def test_ttl_serialise(self):
Expand Down
25 changes: 15 additions & 10 deletions rdf_io/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.urls import path
try:
from .views import ctl_signals,show_config,sync_remote,to_rdfbyid,pub_rdf, to_rdfbykey
except:
Expand All @@ -9,14 +9,19 @@

urlpatterns = [
# Examples:
# url(r'^$', 'rdf_io.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'to_rdf/(?P<model>[^\/]+)/id/(?P<id>\d+)$', to_rdfbyid, name='to_rdfbyid'),
url(r'to_rdf/(?P<model>[^\/]+)/key/(?P<key>.+)$', to_rdfbykey, name='to_rdfbykey'),
url(r'pub_rdf/(?P<model>[^\/]+)/(?P<id>\d+)$', pub_rdf, name='pub_rdf'),
# path(r'^$', 'rdf_io.views.home', name='home'),
# path(r'^blog/', include('blog.urls')),
#path('to_rdf/(?P<model>[^\/]+)/id/(?P<id>\d+)$', to_rdfbyid, name='to_rdfbyid'),
path('to_rdf/<str:model>/id/<int:id>/', to_rdfbyid, name='to_rdfbyid'),
#old: url('to_rdf/(?P<model>[^\/]+)/key/(?P<key>.+)$', to_rdfbykey, name='to_rdfbykey'),
path('to_rdf/<str:model>//key/<str:key>/', to_rdfbykey, name='to_rdfbykey'),
# old: url('pub_rdf/(?P<model>[^\/]+)/(?P<id>\d+)$', pub_rdf, name='pub_rdf'),
path('pub_rdf/<str:model>/<int:id>/', pub_rdf, name='pub_rdf'),
# management urls - add user auth
url(r'sync_remote/(?P<models>[^\/]+)$', sync_remote, name='sync_remote'),
url(r'show_config$', show_config, name='show_config'),
url(r'ctl_signals/(?P<cmd>[^\/]+)$', ctl_signals, name='ctl_signals'),
# url(r'^admin/', include(admin.site.urls)),
# old: url('sync_remote/(?P<models>[^\/]+)$', sync_remote, name='sync_remote'),
path('sync_remote/<str:model>/', sync_remote, name='sync_remote'),
path('show_config/', show_config, name='show_config'),
# old url ('ctl_signals/(?P<cmd>[^\/]+)$', ctl_signals, name='ctl_signals'),
path('ctl_signals/<str:cmd>/', ctl_signals, name='ctl_signals'),
# path(r'^admin/', include(admin.site.urls)),
]
2 changes: 1 addition & 1 deletion rdf_io/views/serialize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # -*- coding:utf-8 -*-
#from django.shortcuts import render, redirect
from django.shortcuts import render, redirect
from rdf_io.models import *
from ..protocols import push_to_store,inference,rdf_delete

Expand Down