Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
5d7b2a6a
Commit
5d7b2a6a
authored
7 months ago
by
Andreas Hubel
Browse files
Options
Downloads
Patches
Plain Diff
chore(api): expose slug + links on room
parent
ab6ca6bd
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/api/serializers.py
+17
-1
17 additions, 1 deletion
src/api/serializers.py
src/core/models/links.py
+8
-0
8 additions, 0 deletions
src/core/models/links.py
src/core/models/rooms.py
+8
-0
8 additions, 0 deletions
src/core/models/rooms.py
with
33 additions
and
1 deletion
src/api/serializers.py
+
17
−
1
View file @
5d7b2a6a
...
...
@@ -11,6 +11,7 @@ from core.models.assemblies import Assembly
from
core.models.badges
import
Badge
,
BadgeToken
,
BadgeTokenTimeConstraint
from
core.models.conference
import
Conference
,
ConferenceMember
,
ConferenceTrack
from
core.models.events
import
Event
from
core.models.links
import
Link
from
core.models.messages
import
DirectMessage
from
core.models.metanavi
import
MetaNavItem
from
core.models.rooms
import
Room
...
...
@@ -50,6 +51,20 @@ class ParameterisedHyperlinkedIdentityField(HyperlinkedIdentityField):
return
reverse
(
view_name
,
kwargs
=
kwargs
,
request
=
request
,
format
=
format
)
class
LinkRelatedField
(
serializers
.
RelatedField
):
"""
A read only field that represents its targets using their
plain string representation.
"""
def
__init__
(
self
,
**
kwargs
):
kwargs
[
'
read_only
'
]
=
True
super
().
__init__
(
**
kwargs
)
def
to_representation
(
self
,
value
:
Link
):
return
value
.
to_dict
()
class
ValidatingModelSerializer
(
serializers
.
ModelSerializer
):
def
validate
(
self
,
data
):
instance
=
self
.
Meta
.
model
(
**
{
field
:
value
for
field
,
value
in
data
.
items
()
if
field
in
self
.
Meta
.
model
.
_meta
.
fields
})
...
...
@@ -217,7 +232,7 @@ class BadgeTokenUpdateSerializer(BadgeTokenSerializer):
class
RoomSerializer
(
HubModelSerializer
):
assembly
=
serializers
.
SlugRelatedField
(
read_only
=
True
,
slug_field
=
'
slug
'
)
links
=
serializers
.
Str
in
g
RelatedField
(
links
=
L
in
k
RelatedField
(
many
=
True
,
read_only
=
True
,
)
...
...
@@ -228,6 +243,7 @@ class RoomSerializer(HubModelSerializer):
fields
=
[
'
id
'
,
'
name
'
,
'
slug
'
,
'
blocked
'
,
'
room_type
'
,
'
capacity
'
,
...
...
This diff is collapsed.
Click to expand it.
src/core/models/links.py
+
8
−
0
View file @
5d7b2a6a
...
...
@@ -62,6 +62,14 @@ class Link(models.Model):
except
ValidationError
:
raise
ValidationError
({
'
link
'
:
_
(
'
Link__link__must_be_url
'
)})
def
to_dict
(
self
):
return
{
'
type
'
:
self
.
link_type
,
'
name
'
:
self
.
name
,
'
uri
'
:
self
.
link
,
'
url
'
:
self
.
link
,
}
def
__str__
(
self
)
->
str
:
return
self
.
name
...
...
This diff is collapsed.
Click to expand it.
src/core/models/rooms.py
+
8
−
0
View file @
5d7b2a6a
...
...
@@ -501,5 +501,13 @@ class RoomLink(models.Model):
if
not
resolve_internal_url
(
self
.
link
,
fallback_as_is
=
False
):
raise
ValidationError
({
'
link
'
:
_
(
'
RoomLink__link__must_be_url
'
)})
def
to_dict
(
self
):
return
{
'
type
'
:
self
.
link_type
,
'
name
'
:
self
.
name
,
'
uri
'
:
self
.
link
,
'
url
'
:
self
.
link
,
# TODO rendered URL without local hub specific prefixes
}
def
__str__
(
self
):
return
self
.
name
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