Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
osp
tools.ethertoff
Commits
f0cdddc5
Commit
f0cdddc5
authored
Nov 29, 2019
by
gijs
Browse files
Implemented participant reference in event
parent
9576abd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
generator/models.py
View file @
f0cdddc5
from
.
import
fields
from
.utils
import
debug
,
CMAGENTA
,
keyFilter
,
try_attributes
,
render_to_string
from
.utils
import
debug
,
warn
,
CMAGENTA
,
keyFilter
,
try_attributes
,
render_to_string
import
os.path
import
re
import
random
...
...
@@ -402,8 +402,19 @@ def parseReferenceMetadata (raw):
else
:
return
(
None
,
raw
.
strip
())
def
resolveContentType
(
attr
,
model
):
if
attr
in
model
.
metadata
and
(
is_link
(
model
.
metadata
[
attr
])):
return
model
.
metadata
[
attr
].
contentType
elif
knownContentType
(
attr
):
return
attr
else
:
warn
(
"Unknown contenttype '{}'"
.
format
(
attr
))
return
None
def
parseReference
(
match
,
collector
=
None
,
source
=
None
):
contentType
=
match
.
group
(
1
).
strip
().
lower
()
referenceName
=
match
.
group
(
1
).
strip
().
lower
()
contentType
=
resolveContentType
(
referenceName
,
source
)
# match.group(1).strip().lower()
label
=
match
.
group
(
2
).
strip
()
metadata
,
display_label
=
parseReferenceMetadata
(
match
.
group
(
3
))
if
match
.
group
(
3
)
else
(
None
,
None
)
debug
()
...
...
@@ -425,19 +436,28 @@ def parseReference(match, collector=None, source=None):
# fill it with the metadata that was inserted on the reference
target
.
fill
(
metadata
)
debug
(
'FOUND TARGET'
,
target
)
debug
(
"Found target '{}' of type '{}'"
.
format
(
target
,
contentType
)
)
# Here we should create the link between the source and the target
# setattr(source, contentType, target)
if
target
.
contentType
in
source
.
metadata
and
is_link
(
source
.
metadata
[
target
.
contentType
]):
if
referenceName
in
source
.
metadata
and
is_link
(
source
.
metadata
[
referenceName
]):
## FIXME what if it's an existing reverse
link
=
source
.
metadata
[
target
.
contentTyp
e
].
makeLink
(
source
,
target
,
inline
=
True
,
label
=
display_label
)
elif
target
.
contentTyp
e
+
's'
in
source
.
metadata
and
is_multi_link
(
source
.
metadata
[
target
.
contentTyp
e
+
's'
]):
link
=
source
.
metadata
[
referenceNam
e
].
makeLink
(
source
,
target
,
inline
=
True
,
label
=
display_label
)
elif
referenceNam
e
+
's'
in
source
.
metadata
and
is_multi_link
(
source
.
metadata
[
referenceNam
e
+
's'
]):
## FIXME what if it's an existing reverse?
link
=
source
.
metadata
[
target
.
contentTyp
e
+
's'
].
makeLink
(
source
,
target
,
inline
=
True
,
label
=
display_label
)
link
=
source
.
metadata
[
referenceNam
e
+
's'
].
makeLink
(
source
,
target
,
inline
=
True
,
label
=
display_label
)
else
:
link
=
None
# Here we should create the link between the source and the target
# setattr(source, contentType, target)
# if target.contentType in source.metadata and is_link(source.metadata[target.contentType]):
# ## FIXME what if it's an existing reverse
# link = source.metadata[target.contentType].makeLink(source, target, inline=True, label=display_label)
# elif target.contentType + 's' in source.metadata and is_multi_link(source.metadata[target.contentType + 's']):
# ## FIXME what if it's an existing reverse?
# link = source.metadata[target.contentType + 's'].makeLink(source, target, inline=True, label=display_label)
# else:
# link = None
# link = Link(source, target)
collector
.
append
(
target
)
...
...
Write
Preview
Supports
Markdown
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