Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp
Commits
9ed01291
Commit
9ed01291
authored
6 years ago
by
Jean-Baptiste
Browse files
Options
Downloads
Patches
Plain Diff
feature: add LDPModel class to manage instance path resolution
parent
dd4447d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!24
Resolve "Get URL of saved resource from its model"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
djangoldp/models.py
+29
-6
29 additions, 6 deletions
djangoldp/models.py
djangoldp/resolver.py
+0
-17
0 additions, 17 deletions
djangoldp/resolver.py
djangoldp/tests/tests_resolver.py
+7
-13
7 additions, 13 deletions
djangoldp/tests/tests_resolver.py
with
36 additions
and
36 deletions
djangoldp/models.py
+
29
−
6
View file @
9ed01291
...
@@ -5,19 +5,41 @@ from django.db import models
...
@@ -5,19 +5,41 @@ from django.db import models
class
LDPModel
(
models
.
Model
):
class
LDPModel
(
models
.
Model
):
ldp_path
=
None
ldp_path
=
None
def
full
_path
(
self
):
def
get_resource
_path
(
self
):
return
"
{}/{}
"
.
format
(
self
.
container
_path
(
),
self
.
pk
)
return
LDPModel
.
resource
_path
(
self
)
def
container_path
(
self
):
def
get_container_path
(
self
):
return
self
.
ldp_path
return
LDPModel
.
container_path
(
self
)
@classmethod
def
resource_path
(
cls
,
instance
):
return
"
{}{}
"
.
format
(
LDPModel
.
container_path
(
instance
),
instance
.
pk
)
@classmethod
def
container_path
(
cls
,
instance
):
if
isinstance
(
instance
,
cls
):
path
=
instance
.
ldp_path
else
:
from
django.urls
import
get_resolver
view_name
=
'
{}-list
'
.
format
(
instance
.
_meta
.
object_name
.
lower
())
path
=
'
/{}
'
.
format
(
get_resolver
().
reverse_dict
[
view_name
][
0
][
0
][
0
],
instance
.
pk
)
if
not
path
.
startswith
(
"
/
"
):
path
=
"
/{}
"
.
format
(
path
)
if
not
path
.
endswith
(
"
/
"
):
path
=
"
{}/
"
.
format
(
path
)
return
path
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
class
LDPSource
(
models
.
Model
):
class
LDPSource
(
models
.
Model
):
container
=
models
.
URLField
()
container
=
models
.
URLField
()
federation
=
models
.
CharField
(
max_length
=
255
)
federation
=
models
.
CharField
(
max_length
=
255
)
class
Meta
:
class
Meta
:
rdf_type
=
'
sib:source
'
rdf_type
=
'
sib:source
'
ordering
=
(
'
federation
'
,)
ordering
=
(
'
federation
'
,)
...
@@ -25,7 +47,7 @@ class LDPSource(models.Model):
...
@@ -25,7 +47,7 @@ class LDPSource(models.Model):
(
'
view_source
'
,
'
acl:Read
'
),
(
'
view_source
'
,
'
acl:Read
'
),
(
'
control_source
'
,
'
acl:Control
'
),
(
'
control_source
'
,
'
acl:Control
'
),
)
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"
{}: {}
"
.
format
(
self
.
federation
,
self
.
container
)
return
"
{}: {}
"
.
format
(
self
.
federation
,
self
.
container
)
...
@@ -37,6 +59,7 @@ class LDNotification(models.Model):
...
@@ -37,6 +59,7 @@ class LDNotification(models.Model):
type
=
models
.
CharField
(
max_length
=
255
)
type
=
models
.
CharField
(
max_length
=
255
)
summary
=
models
.
TextField
()
summary
=
models
.
TextField
()
date
=
models
.
DateTimeField
(
auto_now_add
=
True
)
date
=
models
.
DateTimeField
(
auto_now_add
=
True
)
class
Meta
:
class
Meta
:
permissions
=
(
permissions
=
(
(
'
view_todo
'
,
'
Read
'
),
(
'
view_todo
'
,
'
Read
'
),
...
...
This diff is collapsed.
Click to expand it.
djangoldp/resolver.py
deleted
100644 → 0
+
0
−
17
View file @
dd4447d7
class
LDPResolver
:
@classmethod
def
resource_url
(
cls
,
dummy
):
pass
@classmethod
def
container_url
(
cls
,
dummy
):
pass
@classmethod
def
resource_path
(
cls
,
dummy
):
pass
@classmethod
def
container_path
(
cls
,
dummy
):
pass
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_resolver.py
+
7
−
13
View file @
9ed01291
from
django.test
import
TestCase
from
django.test
import
TestCase
from
djangoldp.
resolver
import
LDP
Resolver
from
djangoldp.
models
import
LDP
Model
from
djangoldp.tests.models
import
Dummy
,
LDPDummy
from
djangoldp.tests.models
import
Dummy
,
LDPDummy
...
@@ -8,18 +8,12 @@ class UrlUtils(TestCase):
...
@@ -8,18 +8,12 @@ class UrlUtils(TestCase):
def
test_class_not_inheriting_ldp_model
(
self
):
def
test_class_not_inheriting_ldp_model
(
self
):
dummy
=
Dummy
.
objects
.
create
(
some
=
"
text
"
)
dummy
=
Dummy
.
objects
.
create
(
some
=
"
text
"
)
self
.
assertEquals
(
"
http://localhost/dummys/{}
"
.
format
(
dummy
.
pk
),
LDPResolver
.
resource_url
(
dummy
))
self
.
assertEquals
(
"
/dummys/
"
,
LDPModel
.
container_path
(
dummy
))
self
.
assertEquals
(
"
/dummys/{}
"
.
format
(
dummy
.
pk
),
LDPResolver
.
resource_path
(
dummy
))
self
.
assertEquals
(
"
/dummys/{}
"
.
format
(
dummy
.
pk
),
LDPModel
.
resource_path
(
dummy
))
self
.
assertEquals
(
"
http://localhost/dummys
"
,
LDPResolver
.
container_url
(
dummy
))
self
.
assertEquals
(
"
/dummys
"
,
LDPResolver
.
container_path
(
dummy
))
def
test_class_inheriting_ldp_model
(
self
):
def
test_class_inheriting_ldp_model
(
self
):
dummy
=
LDPDummy
.
objects
.
create
(
some
=
"
text
"
)
dummy
=
LDPDummy
.
objects
.
create
(
some
=
"
text
"
)
self
.
assertEquals
(
"
http://localhost/ldp-dummys/{}
"
.
format
(
dummy
.
pk
),
LDPResolver
.
resource_url
(
dummy
))
self
.
assertEquals
(
"
/ldp-dummys/
"
,
dummy
.
get_container_path
())
self
.
assertEquals
(
"
/ldp-dummys/{}
"
.
format
(
dummy
.
pk
),
LDPResolver
.
resource_path
(
dummy
))
self
.
assertEquals
(
"
/ldp-dummys/{}
"
.
format
(
dummy
.
pk
),
dummy
.
get_resource_path
())
self
.
assertEquals
(
"
http://localhost/ldp-dummys/{}
"
.
format
(
dummy
.
pk
),
dummy
.
resource_url
())
self
.
assertEquals
(
"
/ldp-dummys/
"
,
LDPModel
.
container_path
(
dummy
))
self
.
assertEquals
(
"
/ldp-dummys/{}
"
.
format
(
dummy
.
pk
),
dummy
.
resource_path
())
self
.
assertEquals
(
"
/ldp-dummys/{}
"
.
format
(
dummy
.
pk
),
LDPModel
.
resource_path
(
dummy
))
self
.
assertEquals
(
"
http://localhost/ldp-dummys
"
,
LDPResolver
.
container_url
(
dummy
))
self
.
assertEquals
(
"
/ldp-dummys
"
,
LDPResolver
.
container_path
(
dummy
))
self
.
assertEquals
(
"
http://localhost/dummys/
"
,
dummy
.
container_url
())
self
.
assertEquals
(
"
/ldp-dummys
"
,
dummy
.
container_path
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment