Skip to content

Commit

Permalink
[sync] fix zou sync-full command
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBldy committed Jun 25, 2024
1 parent 8077521 commit e0426ad
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
4 changes: 0 additions & 4 deletions zou/app/blueprints/crud/organisation.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from zou.app.models.organisation import Organisation
from zou.app.utils import fields
from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource


class OrganisationsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Organisation)

def get(self):
return fields.serialize_list(Organisation.query.all())

def check_read_permissions(self):
return True

Expand Down
1 change: 1 addition & 0 deletions zou/app/models/attachment_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def present(self):
def create_from_import(cls, data):
data.pop("type", None)
data.pop("comment", None)
data.pop("chat_message", None)
previous_data = cls.get(data["id"])
if previous_data is None:
return cls.create(**data)
Expand Down
2 changes: 1 addition & 1 deletion zou/app/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def create_from_import(cls, data):
return previous_data

@classmethod
def create_from_import_list(cls, data_list):
def create_from_import_list(cls, data_list, pass_integrity_errors=False):
"""
Create a list of instances of the model based on data that comes from
the Zou API.
Expand Down
60 changes: 30 additions & 30 deletions zou/app/services/sync_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@
]

main_events = [
"person",
"organisation",
"project-status",
"department",
"studio",
"department",
"task-type",
"task-status",
"custom-action",
"organisation",
"project-status",
"asset-type",
"person",
"project",
]

Expand Down Expand Up @@ -408,35 +408,35 @@ def sync_entries(model_name, model, project=None):
"""
instances = []

if model_name in ["organisations", "persons"]:
path = model_name + "?relations=true"
if model_name == "persons":
path += "&with_pass_hash=true"
instances = gazu.client.fetch_all(path)
model.create_from_import_list(instances)
elif project:
page = 1
init = True
results = {"nb_pages": 2}
params = {
"relations": "true",
}
if model_name == "persons":
params["with_pass_hash"] = "true"
if project is not None and model_name in [
"projects",
"search-filters",
"search-filter-groups",
]:
project = gazu.project.get_project_by_name(project)
if model_name == "projects":
instances = [gazu.client.fetch_one(model_name, project.get("id"))]
params = {"id": project["id"]}
elif model_name in ["search-filters", "search-filter-groups"]:
instances = gazu.client.fetch_all(
model_name, params=dict(project_id=project.get("id"))
)
else:
instances = gazu.client.fetch_all(model_name)
model.create_from_import_list(instances)
else:
page = 1
init = True
results = {"nb_pages": 2}
while init or results["nb_pages"] >= page:
results = gazu.client.fetch_all(
"%s?relations=true&page=%d" % (model_name, page)
)
instances += results["data"]
page += 1
init = False
model.create_from_import_list(results["data"])
params = {"project_id": project["id"]}
while init or results["nb_pages"] >= page:
params["page"] = page
results = gazu.client.fetch_all(model_name, params=params)
if model_name == "task-status" and results["data"]:
results["data"] = [
r for r in results["data"] if not r["for_concept"]
]
instances += results["data"]
page += 1
init = False
model.create_from_import_list(results["data"])

logger.info("%s %s synced." % (len(instances), model_name))

Expand Down

0 comments on commit e0426ad

Please sign in to comment.