Skip to content

Commit

Permalink
Fallback host mapping and handling for broken MongoEngine; ref #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice Zoë Bevan–McGregor committed Jan 24, 2023
1 parent 494ef44 commit 1a94241
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions web/contentment/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __repr__(self):
return "{self.__class__.__name__}(0x{id})".format(self=self, id=id(self))

def __call__(self, context, obj, path):
#__import__('wdb').set_trace()
# TODO: Move into web.dispatch.meta as "FallbackDispatch".
# First, try with object dispatch. This handles custom root controller attachments such as statics.
try:
Expand Down
16 changes: 10 additions & 6 deletions web/contentment/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def _find_references(self, items, depth=0, finded_ids=None):
:param items: The iterable (dict, list, queryset)
:param depth: The current depth of recursion
"""
# if items and isinstance(items, list) and getattr(items[0], 'name', '') == 'child2':
# import pudb; pudb.set_trace()
reference_map = {}
if not items or depth >= self.max_depth:
return reference_map
Expand Down Expand Up @@ -137,9 +135,8 @@ def empty(self, *q_objs, **query):
Warning: If run on all assets this will only leave the root element intact. It would also be expensive.
"""

# import ipdb; ipdb.set_trace()

parents = self.clone().filter(*q_objs, **query)
parents = [i.id for i in parents] + [i.to_dbref() for i in parents]

# Optimization note: this doesn't need to worry about normalizing paths, thus the _from_doc_delete.
# TODO: Handle potential exception: signal handlers may preemptively delete included records. That's perfectly ok!
Expand Down Expand Up @@ -296,7 +293,12 @@ def insertAfter(self, sibling):
@property
def children(self):
"""Yield all direct children of this asset."""
return self.base_query(parent__in=self.clone())

parents = list(self.clone().only('id'))
references = [i.id for i in parents]
references += [i.to_dbref() for i in parents]

return self.base_query(parent__in=references)

@property
def contents(self):
Expand Down Expand Up @@ -592,7 +594,9 @@ def insertAfter(self, sibling):
@property
def children(self):
"""Yield all direct children of this asset."""
return self.tqs(id=self.id).children
parents = [self.id, self.to_dbref()]
return self.tqs(__raw__={'parent': {'$in': parents}})
#return self.tqs(id=self.id).children

@property
def contents(self):
Expand Down
2 changes: 1 addition & 1 deletion web/ext/contentment.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def start(self, context):

def prepare(self, context):
dom = context.request.host.partition(':')[0]
parts = MAP.get(dom, (dom, 'en', ''))
parts = MAP.get(dom, MAP[None]) # (dom, 'en', ''))
context.domain = parts[0]
context.lang = parts[1]
context.otherlang = parts[2]
Expand Down

0 comments on commit 1a94241

Please sign in to comment.