Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-python
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
perxis
perxis-python
Commits
54f1a865
Commit
54f1a865
authored
1 year ago
by
Podosochnyy Maxim
Browse files
Options
Downloads
Patches
Plain Diff
Из PerxisDataProvider вынесена логика работы с item и referrence
parent
548a5a91
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!63
Из PerxisDataProvider вынесена логика работы с item и referrence
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
perxis/provider.py
+187
-44
187 additions, 44 deletions
perxis/provider.py
with
187 additions
and
44 deletions
perxis/provider.py
+
187
−
44
View file @
54f1a865
...
...
@@ -13,28 +13,50 @@ DEFAULT_PAGE_SIZE: int = 100
DEFAULT_PART_SIZE
:
int
=
1024
*
5
class
PerxisDataProvider
:
class
PerxisReferencesWrapper
:
__references
:
references_pb2_grpc
.
ReferencesStub
def
__init__
(
self
,
channel
:
GrpcChannel
,
space_id
:
str
,
env_id
:
str
,
)
->
None
:
self
.
channel
=
channel
self
.
space_id
=
space_id
self
.
env_id
=
env_id
self
.
items_stub
=
items_pb2_grpc
.
ItemsStub
(
self
.
channel
.
channel
)
self
.
references_stub
=
references_pb2_grpc
.
ReferencesStub
(
self
.
channel
.
channel
)
self
,
references
:
references_pb2_grpc
.
ReferencesStub
,
):
self
.
__references
=
references
async
def
get_references
(
self
,
references
:
list
[
Reference
],
space_id
:
str
,
env_id
:
str
)
->
items_pb2
.
GetResponse
:
"""
Метод получения связей.
"""
result
=
await
self
.
__references
.
Get
(
references_pb2
.
GetRequest
(
space_id
=
space_id
,
env_id
=
env_id
,
references
=
[
references_pb2
.
Reference
(
id
=
ref
.
id
,
collection_id
=
ref
.
collection_id
)
for
ref
in
references
],
)
)
return
result
class
PerxisItemsWrapper
:
__items
:
items_pb2_grpc
.
ItemsStub
def
__init__
(
self
,
items
:
items_pb2_grpc
.
ItemsStub
,
):
self
.
__items
=
items
async
def
create
(
self
,
data
:
Struct
,
collection_id
:
str
self
,
data
:
Struct
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
)
->
items_pb2
.
CreateResponse
:
"""
Сохранение данных формы в системе Perxis.
"""
result
=
await
self
.
items
_stub
.
Create
(
result
=
await
self
.
__
items
.
Create
(
items_pb2
.
CreateRequest
(
item
=
items_pb2
.
Item
(
space_id
=
self
.
space_id
,
env_id
=
self
.
env_id
,
space_id
=
space_id
,
env_id
=
env_id
,
collection_id
=
collection_id
,
data
=
data
,
)
...
...
@@ -42,14 +64,14 @@ class PerxisDataProvider:
)
return
result
async
def
update
(
self
,
item_id
:
str
,
data
:
Struct
,
collection_id
:
str
)
->
Empty
:
async
def
update
(
self
,
item_id
:
str
,
data
:
Struct
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
)
->
Empty
:
"""
Метод обновления записи в коллекции.
"""
result
=
await
self
.
items
_stub
.
Update
(
result
=
await
self
.
__
items
.
Update
(
items_pb2
.
UpdateRequest
(
item
=
items_pb2
.
Item
(
id
=
item_id
,
space_id
=
self
.
space_id
,
env_id
=
self
.
env_id
,
space_id
=
space_id
,
env_id
=
env_id
,
collection_id
=
collection_id
,
data
=
data
,
)
...
...
@@ -60,21 +82,24 @@ class PerxisDataProvider:
async
def
find
(
self
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
,
filters
:
list
[
str
]
|
None
=
None
,
sort_by
:
list
[
str
]
|
None
=
None
,
fields
:
list
[
str
]
|
None
=
None
,
page_num
:
int
|
None
=
None
,
page_size
:
int
|
None
=
DEFAULT_PAGE_SIZE
,
)
->
items_pb2
.
FindResponse
:
"""
Метод поиска записей в коллекции.
"""
result
=
await
self
.
items
_stub
.
Find
(
result
=
await
self
.
__
items
.
Find
(
items_pb2
.
FindRequest
(
space_id
=
self
.
space_id
,
env_id
=
self
.
env_id
,
space_id
=
space_id
,
env_id
=
env_id
,
collection_id
=
collection_id
,
filter
=
items_pb2
.
Filter
(
q
=
filters
or
[]),
options
=
items_pb2
.
FindOptions
(
options
=
common_pb2
.
FindOptions
(
sort
=
sort_by
,
page_num
=
page_num
,
page_size
=
page_size
sort
=
sort_by
,
page_num
=
page_num
,
page_size
=
page_size
,
fields
=
fields
or
[]
)
),
)
...
...
@@ -84,6 +109,8 @@ class PerxisDataProvider:
async
def
find_published
(
self
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
,
filters
:
list
[
str
]
|
None
=
None
,
fields
:
list
[
str
]
|
None
=
None
,
sort_by
:
list
[
str
]
|
None
=
None
,
...
...
@@ -91,10 +118,10 @@ class PerxisDataProvider:
page_size
:
int
|
None
=
DEFAULT_PAGE_SIZE
,
)
->
items_pb2
.
FindResponse
:
"""
Метод поиска опубликованных записей в коллекции.
"""
result
=
await
self
.
items
_stub
.
FindPublished
(
result
=
await
self
.
__
items
.
FindPublished
(
items_pb2
.
FindPublishedRequest
(
space_id
=
self
.
space_id
,
env_id
=
self
.
env_id
,
space_id
=
space_id
,
env_id
=
env_id
,
collection_id
=
collection_id
,
filter
=
items_pb2
.
Filter
(
q
=
filters
or
[]),
options
=
items_pb2
.
FindPublishedOptions
(
...
...
@@ -112,6 +139,8 @@ class PerxisDataProvider:
async
def
fetch_all_published
(
self
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
,
filters
:
list
[
str
]
|
None
=
None
,
fields
:
list
[
str
]
|
None
=
None
,
sort_by
:
list
[
str
]
|
None
=
None
,
...
...
@@ -124,6 +153,8 @@ class PerxisDataProvider:
"
sort_by
"
:
sort_by
,
"
fields
"
:
fields
,
"
page_size
"
:
page_size
,
"
space_id
"
:
space_id
,
"
env_id
"
:
env_id
}
message
=
await
self
.
find_published
(
**
kwargs
)
yield
message
...
...
@@ -137,28 +168,28 @@ class PerxisDataProvider:
for
page_num
in
range
(
1
,
pages
+
1
):
yield
await
self
.
find_published
(
page_num
=
page_num
,
**
kwargs
)
async
def
unpublish
(
self
,
item_id
:
str
,
collection_id
:
str
)
->
Empty
:
async
def
unpublish
(
self
,
item_id
:
str
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
)
->
Empty
:
"""
Метод снятия с публикации записи в коллекции.
"""
result
=
await
self
.
items
_stub
.
Unpublish
(
result
=
await
self
.
__
items
.
Unpublish
(
items_pb2
.
UnpublishRequest
(
item
=
items_pb2
.
Item
(
id
=
item_id
,
space_id
=
self
.
space_id
,
env_id
=
self
.
env_id
,
space_id
=
space_id
,
env_id
=
env_id
,
collection_id
=
collection_id
,
)
)
)
return
result
async
def
publish
(
self
,
item_id
:
str
,
collection_id
:
str
)
->
Empty
:
async
def
publish
(
self
,
item_id
:
str
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
)
->
Empty
:
"""
Метод публикации записи в коллекции.
"""
result
=
await
self
.
items
_stub
.
Publish
(
result
=
await
self
.
__
items
.
Publish
(
items_pb2
.
PublishRequest
(
item
=
items_pb2
.
Item
(
id
=
item_id
,
space_id
=
self
.
space_id
,
env_id
=
self
.
env_id
,
space_id
=
space_id
,
env_id
=
env_id
,
collection_id
=
collection_id
,
)
)
...
...
@@ -168,7 +199,10 @@ class PerxisDataProvider:
async
def
fetch_all
(
self
,
collection_id
:
str
,
space_id
:
str
,
env_id
:
str
,
filters
:
list
[
str
]
|
str
=
None
,
fields
:
list
[
str
]
|
None
=
None
,
sort_by
:
list
[
str
]
|
str
=
None
,
page_size
:
int
|
None
=
DEFAULT_PAGE_SIZE
,
)
->
items_pb2
.
FindResponse
:
...
...
@@ -176,8 +210,11 @@ class PerxisDataProvider:
items
=
[]
storage_data
=
await
self
.
find
(
collection_id
=
collection_id
,
space_id
=
space_id
,
env_id
=
env_id
,
page_size
=
page_size
,
filters
=
filters
,
fields
=
fields
,
)
items
.
extend
(
storage_data
.
items
)
...
...
@@ -190,28 +227,134 @@ class PerxisDataProvider:
for
page_num
in
range
(
1
,
pages
+
1
):
storage_data
=
await
self
.
find
(
collection_id
=
collection_id
,
space_id
=
space_id
,
env_id
=
env_id
,
filters
=
filters
,
sort_by
=
sort_by
,
page_num
=
page_num
,
page_size
=
page_size
,
fields
=
fields
,
)
items
.
extend
(
storage_data
.
items
)
return
items_pb2
.
FindResponse
(
items
=
items
,
total
=
len
(
items
))
class
PerxisDataProvider
:
def
__init__
(
self
,
channel
:
GrpcChannel
,
space_id
:
str
,
env_id
:
str
,
)
->
None
:
self
.
channel
=
channel
self
.
space_id
=
space_id
self
.
env_id
=
env_id
self
.
references_wrapper
=
PerxisReferencesWrapper
(
references
=
references_pb2_grpc
.
ReferencesStub
(
self
.
channel
.
channel
)
)
self
.
items_wrapper
=
PerxisItemsWrapper
(
items
=
items_pb2_grpc
.
ItemsStub
(
self
.
channel
.
channel
),
)
async
def
create
(
self
,
data
:
Struct
,
collection_id
:
str
)
->
items_pb2
.
CreateResponse
:
result
=
await
self
.
items_wrapper
.
create
(
data
,
collection_id
,
self
.
space_id
,
self
.
env_id
)
return
result
async
def
update
(
self
,
item_id
:
str
,
data
:
Struct
,
collection_id
:
str
)
->
Empty
:
result
=
await
self
.
items_wrapper
.
update
(
item_id
,
data
,
collection_id
,
self
.
space_id
,
self
.
env_id
)
return
result
async
def
find
(
self
,
collection_id
:
str
,
filters
:
list
[
str
]
|
None
=
None
,
sort_by
:
list
[
str
]
|
None
=
None
,
page_num
:
int
|
None
=
None
,
page_size
:
int
|
None
=
DEFAULT_PAGE_SIZE
,
)
->
items_pb2
.
FindResponse
:
result
=
await
self
.
items_wrapper
.
find
(
collection_id
,
self
.
space_id
,
self
.
env_id
,
filters
,
sort_by
,
page_num
,
page_size
)
return
result
async
def
find_published
(
self
,
collection_id
:
str
,
filters
:
list
[
str
]
|
None
=
None
,
fields
:
list
[
str
]
|
None
=
None
,
sort_by
:
list
[
str
]
|
None
=
None
,
page_num
:
int
|
None
=
None
,
page_size
:
int
|
None
=
DEFAULT_PAGE_SIZE
,
)
->
items_pb2
.
FindResponse
:
result
=
await
self
.
items_wrapper
.
find_published
(
collection_id
,
self
.
space_id
,
self
.
env_id
,
filters
,
fields
,
sort_by
,
page_num
,
page_size
)
return
result
async
def
fetch_all_published
(
self
,
collection_id
:
str
,
filters
:
list
[
str
]
|
None
=
None
,
fields
:
list
[
str
]
|
None
=
None
,
sort_by
:
list
[
str
]
|
None
=
None
,
page_size
:
int
|
None
=
DEFAULT_PAGE_SIZE
,
)
->
items_pb2
.
FindResponse
:
"""
Метод поиска всех опубликованных записей в коллекции.
"""
kwargs
=
{
"
collection_id
"
:
collection_id
,
"
filters
"
:
filters
,
"
sort_by
"
:
sort_by
,
"
fields
"
:
fields
,
"
page_size
"
:
page_size
,
}
message
=
await
self
.
find_published
(
**
kwargs
)
yield
message
if
pages
:
=
message
.
total
//
page_size
:
if
message
.
total
%
page_size
:
pages
+=
1
else
:
pages
=
1
for
page_num
in
range
(
1
,
pages
+
1
):
yield
await
self
.
find_published
(
page_num
=
page_num
,
**
kwargs
)
async
def
unpublish
(
self
,
item_id
:
str
,
collection_id
:
str
)
->
Empty
:
result
=
await
self
.
items_wrapper
.
unpublish
(
item_id
,
collection_id
,
self
.
space_id
,
self
.
env_id
)
return
result
async
def
publish
(
self
,
item_id
:
str
,
collection_id
:
str
)
->
Empty
:
result
=
await
self
.
items_wrapper
.
publish
(
item_id
,
collection_id
,
self
.
space_id
,
self
.
env_id
)
return
result
async
def
fetch_all
(
self
,
collection_id
:
str
,
filters
:
list
[
str
]
|
str
=
None
,
sort_by
:
list
[
str
]
|
str
=
None
,
page_size
:
int
|
None
=
DEFAULT_PAGE_SIZE
,
)
->
items_pb2
.
FindResponse
:
result
=
await
self
.
items_wrapper
.
fetch_all
(
collection_id
,
self
.
space_id
,
self
.
env_id
,
filters
,
sort_by
,
page_size
)
return
result
async
def
get_references
(
self
,
references
:
list
[
Reference
]
)
->
items_pb2
.
GetResponse
:
"""
Метод получения связей.
"""
result
=
await
self
.
references_stub
.
Get
(
references_pb2
.
GetRequest
(
space_id
=
self
.
space_id
,
env_id
=
self
.
env_id
,
references
=
[
references_pb2
.
Reference
(
id
=
ref
.
id
,
collection_id
=
ref
.
collection_id
)
for
ref
in
references
],
)
result
=
await
self
.
references_wrapper
.
get_references
(
references
,
self
.
space_id
,
self
.
env_id
)
return
result
...
...
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