Moving stuff out of shared
This commit is contained in:
parent
d35fdccf58
commit
65082feecb
3 changed files with 23 additions and 26 deletions
|
@ -17,6 +17,7 @@ import config
|
||||||
from config import DB
|
from config import DB
|
||||||
from core import gc
|
from core import gc
|
||||||
from core.activitypub import Box
|
from core.activitypub import Box
|
||||||
|
from core.activitypub import _add_answers_to_question
|
||||||
from core.activitypub import post_to_outbox
|
from core.activitypub import post_to_outbox
|
||||||
from core.inbox import process_inbox
|
from core.inbox import process_inbox
|
||||||
from core.meta import MetaKey
|
from core.meta import MetaKey
|
||||||
|
@ -24,7 +25,6 @@ from core.meta import _meta
|
||||||
from core.notifications import set_inbox_flags
|
from core.notifications import set_inbox_flags
|
||||||
from core.outbox import process_outbox
|
from core.outbox import process_outbox
|
||||||
from core.shared import MY_PERSON
|
from core.shared import MY_PERSON
|
||||||
from core.shared import _add_answers_to_question
|
|
||||||
from core.shared import _Response
|
from core.shared import _Response
|
||||||
from core.shared import back
|
from core.shared import back
|
||||||
from core.shared import p
|
from core.shared import p
|
||||||
|
|
|
@ -2,6 +2,8 @@ import binascii
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
from datetime import timezone
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import List
|
from typing import List
|
||||||
|
@ -16,6 +18,7 @@ from little_boxes import activitypub as ap
|
||||||
from little_boxes import strtobool
|
from little_boxes import strtobool
|
||||||
from little_boxes.activitypub import _to_list
|
from little_boxes.activitypub import _to_list
|
||||||
from little_boxes.activitypub import clean_activity
|
from little_boxes.activitypub import clean_activity
|
||||||
|
from little_boxes.activitypub import format_datetime
|
||||||
from little_boxes.backend import Backend
|
from little_boxes.backend import Backend
|
||||||
from little_boxes.errors import ActivityGoneError
|
from little_boxes.errors import ActivityGoneError
|
||||||
|
|
||||||
|
@ -26,7 +29,6 @@ from config import ID
|
||||||
from config import ME
|
from config import ME
|
||||||
from config import USER_AGENT
|
from config import USER_AGENT
|
||||||
from core.meta import Box
|
from core.meta import Box
|
||||||
from core.shared import _add_answers_to_question
|
|
||||||
from core.tasks import Tasks
|
from core.tasks import Tasks
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -561,6 +563,25 @@ def build_ordered_collection(
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def _add_answers_to_question(raw_doc: Dict[str, Any]) -> None:
|
||||||
|
activity = raw_doc["activity"]
|
||||||
|
if (
|
||||||
|
ap._has_type(activity["type"], ap.ActivityType.CREATE)
|
||||||
|
and "object" in activity
|
||||||
|
and ap._has_type(activity["object"]["type"], ap.ActivityType.QUESTION)
|
||||||
|
):
|
||||||
|
for choice in activity["object"].get("oneOf", activity["object"].get("anyOf")):
|
||||||
|
choice["replies"] = {
|
||||||
|
"type": ap.ActivityType.COLLECTION.value,
|
||||||
|
"totalItems": raw_doc["meta"]
|
||||||
|
.get("question_answers", {})
|
||||||
|
.get(_answer_key(choice["name"]), 0),
|
||||||
|
}
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
if format_datetime(now) >= activity["object"]["endTime"]:
|
||||||
|
activity["object"]["closed"] = activity["object"]["endTime"]
|
||||||
|
|
||||||
|
|
||||||
def add_extra_collection(raw_doc: Dict[str, Any]) -> Dict[str, Any]:
|
def add_extra_collection(raw_doc: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
if raw_doc["activity"]["type"] != ap.ActivityType.CREATE.value:
|
if raw_doc["activity"]["type"] != ap.ActivityType.CREATE.value:
|
||||||
return raw_doc
|
return raw_doc
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
|
||||||
from datetime import timezone
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
|
@ -14,13 +11,11 @@ from flask import session
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from flask_wtf.csrf import CSRFProtect
|
from flask_wtf.csrf import CSRFProtect
|
||||||
from little_boxes import activitypub as ap
|
from little_boxes import activitypub as ap
|
||||||
from little_boxes.activitypub import format_datetime
|
|
||||||
from poussetaches import PousseTaches
|
from poussetaches import PousseTaches
|
||||||
|
|
||||||
from config import DB
|
from config import DB
|
||||||
from config import ME
|
from config import ME
|
||||||
from core import activitypub
|
from core import activitypub
|
||||||
from core.activitypub import _answer_key
|
|
||||||
|
|
||||||
# _Response = Union[flask.Response, werkzeug.wrappers.Response, str, Any]
|
# _Response = Union[flask.Response, werkzeug.wrappers.Response, str, Any]
|
||||||
_Response = Any
|
_Response = Any
|
||||||
|
@ -193,22 +188,3 @@ def paginated_query(db, q, limit=25, sort_key="_id"):
|
||||||
older_than = str(outbox_data[-1]["_id"])
|
older_than = str(outbox_data[-1]["_id"])
|
||||||
|
|
||||||
return outbox_data, older_than, newer_than
|
return outbox_data, older_than, newer_than
|
||||||
|
|
||||||
|
|
||||||
def _add_answers_to_question(raw_doc: Dict[str, Any]) -> None:
|
|
||||||
activity = raw_doc["activity"]
|
|
||||||
if (
|
|
||||||
ap._has_type(activity["type"], ap.ActivityType.CREATE)
|
|
||||||
and "object" in activity
|
|
||||||
and ap._has_type(activity["object"]["type"], ap.ActivityType.QUESTION)
|
|
||||||
):
|
|
||||||
for choice in activity["object"].get("oneOf", activity["object"].get("anyOf")):
|
|
||||||
choice["replies"] = {
|
|
||||||
"type": ap.ActivityType.COLLECTION.value,
|
|
||||||
"totalItems": raw_doc["meta"]
|
|
||||||
.get("question_answers", {})
|
|
||||||
.get(_answer_key(choice["name"]), 0),
|
|
||||||
}
|
|
||||||
now = datetime.now(timezone.utc)
|
|
||||||
if format_datetime(now) >= activity["object"]["endTime"]:
|
|
||||||
activity["object"]["closed"] = activity["object"]["endTime"]
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue