Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Django LDP
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
20
Issues
20
List
Boards
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Startin blox
djangoldp-packages
Django LDP
Commits
399b5d70
Commit
399b5d70
authored
Sep 23, 2019
by
Jean-Baptiste
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update: auto create local source if no source exists for this type
parent
3df810c3
Pipeline
#5512
passed with stage
in 1 minute and 25 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
4 deletions
+39
-4
README.md
README.md
+10
-0
djangoldp/__init__.py
djangoldp/__init__.py
+4
-1
djangoldp/apps.py
djangoldp/apps.py
+18
-0
djangoldp/models.py
djangoldp/models.py
+7
-3
No files found.
README.md
View file @
399b5d70
...
...
@@ -242,6 +242,16 @@ REST_FRAMEWORK = {
}
```
## Sources
To enable sources auto creation for all models, change
`djangoldp`
by
`djangoldp.apps.DjangoldpConfig`
, on
`INSTALLED_APPS`
```
python
INSTALLED_APPS
=
[
'djangoldp.apps.DjangoldpConfig'
,
]
```
## License
Licence MIT
djangoldp/__init__.py
View file @
399b5d70
from
django.db.models
import
options
__version__
=
'0.0.0'
options
.
DEFAULT_NAMES
+=
(
'lookup_field'
,
'rdf_type'
,
'rdf_context'
,
'auto_author'
,
'owner_field'
,
'view_set'
,
'container_path'
,
'permission_classes'
,
'serializer_fields'
,
'nested_fields'
,
'depth'
,
'anonymous_perms'
,
'authenticated_perms'
,
'owner_perms'
)
options
.
DEFAULT_NAMES
+=
(
'lookup_field'
,
'rdf_type'
,
'rdf_context'
,
'auto_author'
,
'owner_field'
,
'view_set'
,
'container_path'
,
'permission_classes'
,
'serializer_fields'
,
'nested_fields'
,
'depth'
,
'anonymous_perms'
,
'authenticated_perms'
,
'owner_perms'
)
djangoldp/apps.py
View file @
399b5d70
...
...
@@ -3,3 +3,21 @@ from django.apps import AppConfig
class
DjangoldpConfig
(
AppConfig
):
name
=
'djangoldp'
def
ready
(
self
):
self
.
create_local_source
()
def
create_local_source
(
self
):
from
djangoldp.models
import
LDPSource
,
Model
model_classes
=
{
cls
.
__name__
:
cls
for
cls
in
Model
.
__subclasses__
()}
for
class_name
in
model_classes
:
model_class
=
model_classes
[
class_name
]
if
model_class
is
LDPSource
:
continue
path
=
model_class
.
get_container_path
()
.
strip
(
"/"
)
try
:
existing_source
=
LDPSource
.
objects
.
get
(
federation
=
path
)
except
LDPSource
.
DoesNotExist
:
LDPSource
.
objects
.
create
(
federation
=
path
,
urlid
=
Model
.
absolute_url
(
model_class
))
djangoldp/models.py
View file @
399b5d70
...
...
@@ -34,10 +34,14 @@ class Model(models.Model):
return
cls
.
__clean_path
(
path
)
def
get_absolute_url
(
self
):
if
self
.
urlid
is
None
or
self
.
urlid
!=
''
:
return
'{}{}'
.
format
(
settings
.
BASE_URL
,
Model
.
resource_id
(
self
))
return
Model
.
absolute_url
(
self
)
@
classonlymethod
def
absolute_url
(
cls
,
instance_or_model
):
if
isinstance
(
instance_or_model
,
ModelBase
)
or
instance_or_model
.
urlid
is
None
or
instance_or_model
.
urlid
==
''
:
return
'{}{}'
.
format
(
settings
.
BASE_URL
,
Model
.
resource
(
instance_or_model
))
else
:
return
self
.
urlid
return
instance_or_model
.
urlid
def
get_container_id
(
self
):
return
Model
.
container_id
(
self
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment