Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Rex Dri
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
32
Issues
32
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rex Dri
Rex Dri
Commits
7c38befd
Commit
7c38befd
authored
Sep 01, 2018
by
Florent Chehab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Centralized tag definition
parent
4553b543
Pipeline
#26844
passed with stages
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
108 additions
and
59 deletions
+108
-59
backend/load_data/assets/tags.json
backend/load_data/assets/tags.json
+1
-36
backend/migrations/0002_auto_20180901_1000.py
backend/migrations/0002_auto_20180901_1000.py
+34
-0
backend/models/module/basicModule.py
backend/models/module/basicModule.py
+2
-22
backend/models/tag/taggedItem.py
backend/models/tag/taggedItem.py
+2
-0
backend/models/tag/tagged_item_validation.py
backend/models/tag/tagged_item_validation.py
+10
-1
backend/models/tag/tags_config/__init__.py
backend/models/tag/tags_config/__init__.py
+2
-0
backend/models/tag/tags_config/photos.py
backend/models/tag/tags_config/photos.py
+39
-0
backend/models/tag/tags_config/usefull_links.py
backend/models/tag/tags_config/usefull_links.py
+18
-0
No files found.
backend/load_data/assets/tags.json
View file @
7c38befd
...
@@ -3,42 +3,7 @@
...
@@ -3,42 +3,7 @@
"name"
:
"photos"
,
"name"
:
"photos"
,
"config"
:
{
"config"
:
{
"photos"
:
{
"photos"
:
{
"type"
:
"array"
,
"type"
:
"photos"
,
"content"
:
{
"url"
:
{
"type"
:
"url"
,
"required"
:
true
,
"validators"
:
{
"extension"
:
[
"jpg"
,
"jpeg"
,
"png"
,
"svg"
]
}
},
"title"
:
{
"type"
:
"text"
,
"required"
:
true
,
"validators"
:
{
"max_length"
:
200
}
},
"licence"
:
{
"type"
:
"text"
,
"required"
:
false
,
"validators"
:
{
"max_length"
:
200
}
},
"description"
:
{
"type"
:
"text"
,
"required"
:
false
,
"validators"
:
{
"max_length"
:
500
}
}
},
"required"
:
true
"required"
:
true
}
}
}
}
...
...
backend/migrations/0002_auto_20180901_1000.py
0 → 100644
View file @
7c38befd
# Generated by Django 2.0.3 on 2018-09-01 08:00
import
django.contrib.postgres.fields.jsonb
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'backend'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'campustaggeditem'
,
name
=
'custom_content'
,
field
=
django
.
contrib
.
postgres
.
fields
.
jsonb
.
JSONField
(
default
=
dict
),
),
migrations
.
AddField
(
model_name
=
'citytaggeditem'
,
name
=
'custom_content'
,
field
=
django
.
contrib
.
postgres
.
fields
.
jsonb
.
JSONField
(
default
=
dict
),
),
migrations
.
AddField
(
model_name
=
'countrytaggeditem'
,
name
=
'custom_content'
,
field
=
django
.
contrib
.
postgres
.
fields
.
jsonb
.
JSONField
(
default
=
dict
),
),
migrations
.
AddField
(
model_name
=
'universitytaggeditem'
,
name
=
'custom_content'
,
field
=
django
.
contrib
.
postgres
.
fields
.
jsonb
.
JSONField
(
default
=
dict
),
),
]
backend/models/module/basicModule.py
View file @
7c38befd
...
@@ -2,27 +2,7 @@ from django.db import models
...
@@ -2,27 +2,7 @@ from django.db import models
from
backend.models.my_model
import
MyModelVersionned
,
MyModelVersionnedSerializer
,
MyModelVersionnedViewSet
from
backend.models.my_model
import
MyModelVersionned
,
MyModelVersionnedSerializer
,
MyModelVersionnedViewSet
from
django.contrib.postgres.fields
import
JSONField
from
django.contrib.postgres.fields
import
JSONField
from
backend.models.tag.tagged_item_validation
import
validate_content_against_config
from
backend.models.tag.tagged_item_validation
import
validate_content_against_config
from
backend.models.tag.tags_config
import
USEFULL_LINKS_CONFIG
USEFULL_LINKS_CONFIG
=
{
"usefull_links"
:
{
"type"
:
"array"
,
"content"
:
{
"url"
:
{
"type"
:
"url"
,
"required"
:
True
,
"validators"
:
{}
},
"description"
:
{
"type"
:
"text"
,
"required"
:
True
,
"validators"
:
{
"max_length"
:
500
}
}
},
"required"
:
True
}
}
class
BasicModule
(
MyModelVersionned
):
class
BasicModule
(
MyModelVersionned
):
...
@@ -38,7 +18,7 @@ class BasicModuleSerializer(MyModelVersionnedSerializer):
...
@@ -38,7 +18,7 @@ class BasicModuleSerializer(MyModelVersionnedSerializer):
def
validate
(
self
,
attrs
):
def
validate
(
self
,
attrs
):
content
=
{
'usefull_links'
:
attrs
[
'usefull_links'
]}
content
=
{
'usefull_links'
:
attrs
[
'usefull_links'
]}
config
=
USEFULL_LINKS_CONFIG
config
=
{
'usefull_links'
:
USEFULL_LINKS_CONFIG
}
validate_content_against_config
(
config
,
content
)
validate_content_against_config
(
config
,
content
)
return
attrs
return
attrs
...
...
backend/models/tag/taggedItem.py
View file @
7c38befd
...
@@ -2,10 +2,12 @@ from django.db import models
...
@@ -2,10 +2,12 @@ from django.db import models
from
backend.models.my_model
import
MyModelVersionned
,
MyModelVersionnedSerializer
,
MyModelVersionnedViewSet
from
backend.models.my_model
import
MyModelVersionned
,
MyModelVersionnedSerializer
,
MyModelVersionnedViewSet
from
.tag
import
Tag
from
.tag
import
Tag
from
.tagged_item_validation
import
tagged_item_validation
from
.tagged_item_validation
import
tagged_item_validation
from
django.contrib.postgres.fields
import
JSONField
class
TaggedItem
(
MyModelVersionned
):
class
TaggedItem
(
MyModelVersionned
):
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
'+'
,
on_delete
=
models
.
PROTECT
)
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
'+'
,
on_delete
=
models
.
PROTECT
)
custom_content
=
JSONField
(
default
=
dict
)
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
...
...
backend/models/tag/tagged_item_validation.py
View file @
7c38befd
from
.checks
import
check_required
from
.checks
import
check_required
from
.validators
import
validate_url
,
validate_text
from
.validators
import
validate_url
,
validate_text
from
rest_framework.validators
import
ValidationError
from
rest_framework.validators
import
ValidationError
from
.tags_config
import
PHOTOS_TAG_GONFIG
from
.tags_config
import
USEFULL_LINKS_CONFIG
def
tagged_item_validation
(
attrs
):
def
tagged_item_validation
(
attrs
):
...
@@ -19,15 +21,22 @@ def validate_content_against_config(config, content):
...
@@ -19,15 +21,22 @@ def validate_content_against_config(config, content):
field_submitted
=
content
[
field
]
field_submitted
=
content
[
field
]
field_config
=
config
[
field
]
field_config
=
config
[
field
]
field_type
=
field_config
[
'type'
]
field_type
=
field_config
[
'type'
]
if
field_type
==
'url'
:
if
field_type
==
'url'
:
validate_url
(
field_config
,
field_submitted
)
validate_url
(
field_config
,
field_submitted
)
elif
field_type
==
'text'
:
elif
field_type
==
'text'
:
validate_text
(
field_config
,
field_submitted
)
validate_text
(
field_config
,
field_submitted
)
elif
field_type
==
'photos'
:
validate_content_against_config
({
"photos"
:
PHOTOS_TAG_GONFIG
},
{
"photos"
:
field_submitted
})
elif
field_type
==
'usefull_links'
:
validate_content_against_config
({
"ul"
:
USEFULL_LINKS_CONFIG
},
{
"ul"
:
field_submitted
})
elif
field_type
==
'array'
:
elif
field_type
==
'array'
:
if
type
(
field_submitted
)
is
not
list
:
if
type
(
field_submitted
)
is
not
list
:
raise
ValidationError
(
"A array is required here !"
)
raise
ValidationError
(
"A
n
array is required here !"
)
for
item
in
field_submitted
:
for
item
in
field_submitted
:
validate_content_against_config
(
field_config
[
'content'
],
item
)
validate_content_against_config
(
field_config
[
'content'
],
item
)
else
:
else
:
...
...
backend/models/tag/tags_config/__init__.py
0 → 100644
View file @
7c38befd
from
.photos
import
PHOTOS_TAG_GONFIG
# noqa: F401
from
.usefull_links
import
USEFULL_LINKS_CONFIG
# noqa: F401
backend/models/tag/tags_config/photos.py
0 → 100644
View file @
7c38befd
PHOTOS_TAG_GONFIG
=
{
"type"
:
"array"
,
"required"
:
True
,
"content"
:
{
"url"
:
{
"type"
:
"url"
,
"required"
:
True
,
"validators"
:
{
"extension"
:
[
"jpg"
,
"jpeg"
,
"png"
,
"svg"
]
}
},
"title"
:
{
"type"
:
"text"
,
"required"
:
True
,
"validators"
:
{
"max_length"
:
200
}
},
"licence"
:
{
"type"
:
"text"
,
"required"
:
False
,
"validators"
:
{
"max_length"
:
200
}
},
"description"
:
{
"type"
:
"text"
,
"required"
:
False
,
"validators"
:
{
"max_length"
:
500
}
}
}
}
backend/models/tag/tags_config/usefull_links.py
0 → 100644
View file @
7c38befd
USEFULL_LINKS_CONFIG
=
{
"type"
:
"array"
,
"required"
:
True
,
"content"
:
{
"url"
:
{
"type"
:
"url"
,
"required"
:
True
,
"validators"
:
{}
},
"description"
:
{
"type"
:
"text"
,
"required"
:
True
,
"validators"
:
{
"max_length"
:
500
}
}
}
}
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