58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
from .utils import fet, fetmember
|
|
from .utils import strip_html
|
|
from urllib.parse import urljoin,urlparse
|
|
import settings
|
|
|
|
def pull_post(slug, o):
|
|
post = fet.find_one({"slug": slug})
|
|
|
|
def create_text(p):
|
|
return "<b>" + \
|
|
p["title"]+ "</b>: "+ \
|
|
"(%s) " % p["public_date"] + \
|
|
urljoin(settings.TARGET,
|
|
p["url"]).rstrip("/")+" "+\
|
|
p["highlights"]
|
|
|
|
def create_highlights(h):
|
|
return str(strip_html(h.get("text_txt","")))
|
|
|
|
if post:
|
|
post["typ"] = "posts"
|
|
post["highlights"]=create_highlights(o["highlights"])
|
|
post["text"] = create_text(post)
|
|
if post["url"]: post["url"]= urljoin(settings.TARGET,post["url"]).rstrip("/")
|
|
if post["imageurl"]:post["image"]=urljoin(settings.TARGET,urlparse(post["imageurl"]).path)
|
|
return post
|
|
|
|
def pull_member(id, o):
|
|
member = fetmember.get(id)
|
|
if not member: return None
|
|
member["url"]=urljoin(settings.TARGET, "/member/%s" % id)
|
|
member["text"]="<b>"+member["firstname"]+" "+member["surname"]+"</b>"+" "+member["url"]
|
|
member["imageurl"]=member["image"]
|
|
member["title"] =member["firstname"]+" "+member["surname"]
|
|
return member
|
|
|
|
pull_original={"posts": pull_post,"member": pull_member}
|
|
|
|
|
|
def result_to_object(result):
|
|
docs=result.docs
|
|
highlights =result.highlighting
|
|
#objects=[(rr["id"],rr["id"].split("/")[1],rr["id"].) for rr in docs]
|
|
|
|
def split_id(url):
|
|
"Split the id into its parts /<typ>/<id> -> <typ>, <id> "
|
|
return {
|
|
"id": url["id"] ,
|
|
"typ": url["id"] .split("/")[1],
|
|
"term": url["id"] .split("/")[2]
|
|
}
|
|
|
|
def doc_to_object(r):
|
|
o=split_id(r)
|
|
o["highlights"]=highlights.get(o["id"])
|
|
o=pull_original[o["typ"]](o["term"],o)
|
|
return o
|
|
return [doc_to_object(d) for d in docs] |