-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat update schemas #803
Feat update schemas #803
Changes from 10 commits
122d735
58212eb
ef0f63d
6deb2eb
c4dd341
1074137
c430ea9
b07e814
508cd9f
a5f6dd6
0f5014d
0a2e52c
b44be94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>. | ||
# | ||
|
||
from typing import List, Union | ||
from typing import List, Union, Optional | ||
|
||
from geojson_pydantic import Feature | ||
from pydantic import BaseModel | ||
|
@@ -50,26 +50,33 @@ class BETAProjectUpload(BaseModel): | |
xform_title: Union[str, None] | ||
odk_central: ODKCentral | ||
hashtags: Union[List[str], None] | ||
organisation_id: int = None | ||
organisation_id: Optional[int] | ||
# city: str | ||
# country: str | ||
|
||
|
||
class Feature(BaseModel): | ||
id: int | ||
project_id: int | ||
task_id: Optional[int] | ||
geometry: Optional[Feature] | ||
|
||
|
||
class ProjectSummary(BaseModel): | ||
id: int = -1 | ||
priority: ProjectPriority = ProjectPriority.MEDIUM | ||
priority_str: str = priority.name | ||
title: str = None | ||
location_str: str = None | ||
description: str = None | ||
num_contributors: int = None | ||
total_tasks: int = None | ||
tasks_mapped: int = None | ||
tasks_validated: int = None | ||
tasks_bad: int = None | ||
hashtags: List[str] = None | ||
organisation_id: int = None | ||
organisation_logo: str = None | ||
title: Optional[str] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't gone through all of the docs for Pydantic V2, but I think the syntax might be:
|
||
location_str: Optional[str] | ||
description: Optional[str] | ||
total_tasks: Optional[int] | ||
tasks_mapped: Optional[int] | ||
num_contributors: Optional[int] | ||
tasks_validated: Optional[int] | ||
tasks_bad: Optional[int] | ||
hashtags: Optional[List[str]] | ||
organisation_id: Optional[int] | ||
organisation_logo: Optional[str] | ||
|
||
|
||
class ProjectBase(BaseModel): | ||
|
@@ -79,20 +86,15 @@ class ProjectBase(BaseModel): | |
project_info: List[ProjectInfo] | ||
status: ProjectStatus | ||
# location_str: str | ||
outline_geojson: Feature = None | ||
project_tasks: List[tasks_schemas.Task] = None | ||
xform_title: str = None | ||
hashtags: List[str] = None | ||
organisation_id: int = None | ||
# outline_geojson: Optional[Feature] | ||
project_tasks: Optional[List[tasks_schemas.Task]] | ||
xform_title: Optional[str] | ||
hashtags: Optional[List[str]] | ||
organisation_id: Optional[int] | ||
|
||
|
||
class ProjectOut(ProjectBase): | ||
pass | ||
|
||
|
||
|
||
class Feature(BaseModel): | ||
id: int | ||
project_id: int | ||
task_id: int = None | ||
geometry: Feature |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,18 @@ async def get_task_count_in_project(db: Session, project_id: int): | |
|
||
def get_task_lists(db: Session, project_id: int): | ||
"""Get a list of tasks for a project.""" | ||
query = f"""select id from tasks where project_id = {project_id}""" | ||
result = db.execute(query) | ||
tasks = [task[0] for task in result.fetchall()] | ||
return tasks | ||
query = text(""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the SQL wrapped in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have used sqlalchemy db session. it was not required in the previous stage. But, it is required since your latest update. It might be because of pydantic?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it's not related to pydantic, but there is no harm having the |
||
SELECT id | ||
FROM tasks | ||
WHERE project_id = :project_id | ||
""") | ||
|
||
# Then execute the query with the desired parameter | ||
result = db.execute(query, {"project_id": project_id}) | ||
|
||
# Fetch the result | ||
task_ids = [row.id for row in result] | ||
return task_ids | ||
|
||
|
||
def get_tasks( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to avoid using SQLAlchemy, as we will remove it in the future.
The raw SQL equivalent is probably best 👍