Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ESAP API Gateway
Manage
Activity
Members
Labels
Plan
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASTRON SDC
ESCAPE WP5
ESAP API Gateway
Commits
2a55802e
Commit
2a55802e
authored
4 years ago
by
Hugh Dickinson
Browse files
Options
Downloads
Patches
Plain Diff
Initial implementation of user profile.
parent
ccacfdff
No related branches found
No related tags found
2 merge requests
!43
Esap gateway query
,
!42
Esap gateway rucio
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
esap/accounts/api/serializers.py
+45
-0
45 additions, 0 deletions
esap/accounts/api/serializers.py
esap/accounts/api/views.py
+10
-9
10 additions, 9 deletions
esap/accounts/api/views.py
esap/accounts/models.py
+2
-2
2 additions, 2 deletions
esap/accounts/models.py
with
57 additions
and
11 deletions
esap/accounts/api/serializers.py
+
45
−
0
View file @
2a55802e
...
...
@@ -36,6 +36,51 @@ class EsapShoppingItemSerializer(serializers.HyperlinkedModelSerializer):
class
EsapUserProfileSerializer
(
serializers
.
HyperlinkedModelSerializer
):
shopping_cart
=
EsapShoppingItemSerializer
(
many
=
True
,
# view_name="shopping-items",
read_only
=
False
,
# queryset=EsapShoppingItem.objects.all(),
)
def
update
(
self
,
instance
,
validated_data
):
# Do not allow the user name to be updated - it is the primary key
_
=
validated_data
.
pop
(
"
user_name
"
,
None
)
for
m2m_field
in
[
"
software_repositories
"
,
"
compute_resources
"
,
"
shopping_cart
"
,
]:
field_data
=
validated_data
.
pop
(
m2m_field
,
None
)
if
field_data
is
not
None
:
if
len
(
field_data
[
0
])
==
0
:
raise
RuntimeError
(
f
"
WTF!
{
validated_data
}
"
)
field_instances
=
[
getattr
(
instance
,
m2m_field
).
model
.
objects
.
create
(
item_data
=
str
(
dict
(
field_datum
))
)
for
field_datum
in
field_data
]
getattr
(
instance
,
m2m_field
).
add
(
*
field_instances
)
for
key
,
value
in
validated_data
.
items
():
setattr
(
instance
,
key
,
value
)
instance
.
save
()
return
instance
def
to_internal_value
(
self
,
data
):
internal_value
=
super
().
to_internal_value
(
data
)
for
m2m_field
in
[
"
software_repositories
"
,
"
compute_resources
"
,
"
shopping_cart
"
,
]:
field_data
=
data
.
get
(
m2m_field
,
None
)
if
field_data
is
not
None
:
internal_value
.
update
({
m2m_field
:
field_data
})
return
internal_value
class
Meta
:
model
=
EsapUserProfile
fields
=
[
...
...
This diff is collapsed.
Click to expand it.
esap/accounts/api/views.py
+
10
−
9
View file @
2a55802e
from
rest_framework
import
viewsets
from
rest_framework
import
permissions
from
.serializers
import
*
from
..models
import
*
...
...
@@ -10,7 +11,7 @@ class EsapQuerySchemaViewSet(viewsets.ModelViewSet):
queryset
=
EsapQuerySchema
.
objects
.
all
().
order_by
(
"
schema_name
"
)
serializer_class
=
EsapQuerySchemaSerializer
permission_classes
=
[]
permission_classes
=
[
permissions
.
AllowAny
]
class
EsapComputeResourceViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -20,7 +21,7 @@ class EsapComputeResourceViewSet(viewsets.ModelViewSet):
queryset
=
EsapComputeResource
.
objects
.
all
().
order_by
(
"
resource_name
"
)
serializer_class
=
EsapComputeResourceSerializer
permission_classes
=
[]
permission_classes
=
[
permissions
.
AllowAny
]
class
EsapSoftwareRepositoryViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -30,7 +31,7 @@ class EsapSoftwareRepositoryViewSet(viewsets.ModelViewSet):
queryset
=
EsapSoftwareRepository
.
objects
.
all
().
order_by
(
"
repository_name
"
)
serializer_class
=
EsapSoftwareRepositorySerializer
permission_classes
=
[]
permission_classes
=
[
permissions
.
AllowAny
]
class
EsapShoppingItemViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -40,7 +41,7 @@ class EsapShoppingItemViewSet(viewsets.ModelViewSet):
queryset
=
EsapShoppingItem
.
objects
.
all
()
serializer_class
=
EsapShoppingItemSerializer
permission_classes
=
[]
permission_classes
=
[
permissions
.
AllowAny
]
class
EsapUserProfileViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -50,9 +51,9 @@ class EsapUserProfileViewSet(viewsets.ModelViewSet):
queryset
=
EsapUserProfile
.
objects
.
all
().
order_by
(
"
user_name
"
)
serializer_class
=
EsapUserProfileSerializer
permission_classes
=
[]
permission_classes
=
[
permissions
.
AllowAny
]
def
get_queryset
(
self
):
# Returns nothing if no user_name supplied instead of all
user_name
=
self
.
request
.
query_params
.
get
(
"
user_name
"
,
None
)
return
EsapUserProfile
.
objects
.
filter
(
user_name
=
user_name
)
#
def get_queryset(self):
#
# Returns nothing if no user_name supplied instead of all
#
user_name = self.request.query_params.get("user_name", None)
#
return EsapUserProfile.objects.filter(user_name=user_name)
This diff is collapsed.
Click to expand it.
esap/accounts/models.py
+
2
−
2
View file @
2a55802e
...
...
@@ -69,7 +69,7 @@ class EsapShoppingItem(models.Model):
class
EsapUserProfile
(
models
.
Model
):
user_name
=
models
.
CharField
(
"
Username
"
,
max_length
=
50
)
user_name
=
models
.
CharField
(
"
Username
"
,
max_length
=
50
,
primary_key
=
True
)
full_name
=
models
.
CharField
(
"
Full Name
"
,
max_length
=
100
,
null
=
True
)
user_email
=
models
.
EmailField
(
"
User Email
"
)
query_schema
=
models
.
ForeignKey
(
...
...
@@ -86,7 +86,7 @@ class EsapUserProfile(models.Model):
to
=
EsapComputeResource
,
verbose_name
=
"
Compute Resources
"
,
blank
=
True
)
shopping_cart
=
models
.
ManyToManyField
(
to
=
EsapShoppingItem
,
verbose_name
=
"
Shopping Cart
"
,
blank
=
True
to
=
EsapShoppingItem
,
verbose_name
=
"
Shopping Cart
"
,
blank
=
True
,
)
def
__unicode__
(
self
):
...
...
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