-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Robert Cronin <[email protected]>
- Loading branch information
1 parent
971d68b
commit c76ace5
Showing
19 changed files
with
944 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from sqlalchemy.orm import Session | ||
from odr_core.models.content import ContentReport | ||
from odr_core.schemas.content_report import ContentReportCreate, ContentReportUpdate | ||
from typing import List, Optional | ||
|
||
|
||
def create_content_report(db: Session, report: ContentReportCreate) -> ContentReport: | ||
db_report = ContentReport(**report.model_dump()) | ||
db.add(db_report) | ||
db.commit() | ||
db.refresh(db_report) | ||
return db_report | ||
|
||
|
||
def get_content_report(db: Session, report_id: int) -> Optional[ContentReport]: | ||
return db.query(ContentReport).filter(ContentReport.id == report_id).first() | ||
|
||
|
||
def get_content_reports(db: Session, skip: int = 0, limit: int = 100) -> List[ContentReport]: | ||
return db.query(ContentReport).offset(skip).limit(limit).all() | ||
|
||
|
||
def update_content_report(db: Session, report_id: int, report: ContentReportUpdate) -> Optional[ContentReport]: | ||
db_report = db.query(ContentReport).filter(ContentReport.id == report_id).first() | ||
if db_report: | ||
update_data = report.model_dump(exclude_unset=True) | ||
for key, value in update_data.items(): | ||
setattr(db_report, key, value) | ||
db.commit() | ||
db.refresh(db_report) | ||
return db_report | ||
|
||
|
||
def delete_content_report(db: Session, report_id: int) -> bool: | ||
db_report = db.query(ContentReport).filter(ContentReport.id == report_id).first() | ||
if db_report: | ||
db.delete(db_report) | ||
db.commit() | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from sqlalchemy.orm import Session | ||
from odr_core.models.content import ContentSet, ContentSetItem, Content | ||
from odr_core.schemas.content_set import ContentSetCreate, ContentSetUpdate | ||
from typing import List, Optional | ||
|
||
|
||
def create_content_set(db: Session, content_set: ContentSetCreate) -> ContentSet: | ||
db_content_set = ContentSet(**content_set.model_dump()) | ||
db.add(db_content_set) | ||
db.commit() | ||
db.refresh(db_content_set) | ||
return db_content_set | ||
|
||
|
||
def get_content_set(db: Session, content_set_id: int) -> Optional[ContentSet]: | ||
return db.query(ContentSet).filter(ContentSet.id == content_set_id).first() | ||
|
||
|
||
def get_content_sets(db: Session, skip: int = 0, limit: int = 100) -> List[ContentSet]: | ||
return db.query(ContentSet).offset(skip).limit(limit).all() | ||
|
||
|
||
def update_content_set(db: Session, content_set_id: int, content_set: ContentSetUpdate) -> Optional[ContentSet]: | ||
db_content_set = db.query(ContentSet).filter(ContentSet.id == content_set_id).first() | ||
if db_content_set: | ||
update_data = content_set.model_dump(exclude_unset=True) | ||
for key, value in update_data.items(): | ||
setattr(db_content_set, key, value) | ||
db.commit() | ||
db.refresh(db_content_set) | ||
return db_content_set | ||
|
||
|
||
def delete_content_set(db: Session, content_set_id: int) -> bool: | ||
db_content_set = db.query(ContentSet).filter(ContentSet.id == content_set_id).first() | ||
if db_content_set: | ||
db.delete(db_content_set) | ||
db.commit() | ||
return True | ||
return False | ||
|
||
|
||
def add_content_to_set(db: Session, content_set_id: int, content_id: int) -> bool: | ||
db_content_set_item = ContentSetItem(content_set_id=content_set_id, content_id=content_id) | ||
db.add(db_content_set_item) | ||
try: | ||
db.commit() | ||
return True | ||
except: # noqa | ||
db.rollback() | ||
return False | ||
|
||
|
||
def remove_content_from_set(db: Session, content_set_id: int, content_id: int) -> bool: | ||
db_content_set_item = db.query(ContentSetItem).filter( | ||
ContentSetItem.content_set_id == content_set_id, | ||
ContentSetItem.content_id == content_id | ||
).first() | ||
if db_content_set_item: | ||
db.delete(db_content_set_item) | ||
db.commit() | ||
return True | ||
return False | ||
|
||
|
||
def get_contents_in_set(db: Session, content_set_id: int, skip: int = 0, limit: int = 100) -> List[Content]: | ||
return db.query(Content).join(ContentSetItem).filter( | ||
ContentSetItem.content_set_id == content_set_id | ||
).offset(skip).limit(limit).all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from enum import Enum | ||
|
||
|
||
class ContentType(str, Enum): | ||
IMAGE = "image" | ||
VIDEO = "video" | ||
VOICE = "voice" | ||
MUSIC = "music" | ||
TEXT = "text" | ||
|
||
|
||
class ContentStatus(str, Enum): | ||
PENDING = "PENDING" | ||
AVAILABLE = "AVAILABLE" | ||
UNAVAILABLE = "UNAVAILABLE" | ||
DELISTED = "DELISTED" | ||
|
||
|
||
class ContentSourceType(str, Enum): | ||
URL = "url" | ||
PATH = "path" | ||
HUGGING_FACE = "hugging_face" | ||
|
||
|
||
class ReportStatus(str, Enum): | ||
PENDING = "pending" | ||
REVIEWED = "reviewed" | ||
RESOLVED = "resolved" | ||
|
||
|
||
class AnnotationSourceType(str, Enum): | ||
CONTENT_DESCRIPTION = "content_description" | ||
SPATIAL_ANALYSIS = "spatial_analysis" | ||
TAGS = "tags" | ||
OTHER = "other" | ||
|
||
|
||
class ReportType(str, Enum): | ||
ILLEGAL_CONTENT = "illegal_content" | ||
MALICIOUS_ANNOTATION = "malicious_annotation" | ||
OTHER = "other" | ||
|
||
|
||
class EmbeddingEngineType(str, Enum): | ||
IMAGE = "image" | ||
VIDEO = "video" | ||
VOICE = "voice" | ||
MUSIC = "music" | ||
TEXT = "text" | ||
|
||
|
||
class UserType(str, Enum): | ||
user = "user" | ||
bot = "bot" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pydantic import BaseModel | ||
from typing import Optional | ||
from datetime import datetime | ||
from odr_core.enums import ReportStatus | ||
|
||
|
||
class ContentReportBase(BaseModel): | ||
content_id: int | ||
reporter_id: int | ||
reason: str | ||
description: Optional[str] = None | ||
|
||
|
||
class ContentReportCreate(ContentReportBase): | ||
pass | ||
|
||
|
||
class ContentReportUpdate(BaseModel): | ||
reason: Optional[str] = None | ||
description: Optional[str] = None | ||
status: Optional[ReportStatus] = None | ||
|
||
|
||
class ContentReport(ContentReportBase): | ||
id: int | ||
status: ReportStatus | ||
created_at: datetime | ||
updated_at: datetime | ||
|
||
class Config: | ||
from_attributes = True |
Oops, something went wrong.