class LiveUpdateJsonTemplate(ThingJsonTemplate): _data_attrs_ = ThingJsonTemplate.data_attrs( id="_id", body="body", body_html="body_html", author="author", stricken="stricken", embeds="embeds", mobile_embeds="mobile_embeds", ) def thing_attr(self, thing, attr): if attr == "_id": return str(thing._id) elif attr == "body_html": return filters.spaceCompress(filters.safemarkdown(thing.body, nofollow=True)) elif attr == "author": if not thing.author.deleted: return thing.author.name else: return None elif attr == "stricken": return bool(thing.stricken) return ThingJsonTemplate.thing_attr(self, thing, attr) def kind(self, wrapped): return "LiveUpdate"
class LiveUpdateEventJsonTemplate(ThingJsonTemplate): _data_attrs_ = ThingJsonTemplate.data_attrs( id="_id", state="state", viewer_count="viewer_count", viewer_count_fuzzed="viewer_count_fuzzed", total_views="total_views", title="title", nsfw="nsfw", description="description", description_html="description_html", resources="resources", resources_html="resources_html", websocket_url="websocket_url", ) def thing_attr(self, thing, attr): if attr == "_fullname": return "LiveUpdateEvent_" + thing._id elif attr == "viewer_count": if thing.state == "live": return thing.active_visitors else: return None elif attr == "viewer_count_fuzzed": if thing.state == "live": return thing.active_visitors_fuzzed else: return None elif attr == "total_views": # this requires an extra query, so we'll only show it in places # where we're just getting one event. if not hasattr(thing, "total_views"): return None return thing.total_views elif attr == "description_html": return filters.spaceCompress( filters.safemarkdown(thing.description, nofollow=True) or "") elif attr == "resources_html": return filters.spaceCompress( filters.safemarkdown(thing.resources, nofollow=True) or "") elif attr == "websocket_url": if thing.state == "live": return websockets.make_url("/live/" + thing._id, max_age=24 * 60 * 60) else: return None else: return ThingJsonTemplate.thing_attr(self, thing, attr) def kind(self, wrapped): return "LiveUpdateEvent"
class LiveUpdateEventJsonTemplate(ThingJsonTemplate): _data_attrs_ = ThingJsonTemplate.data_attrs( id="_id", state="state", viewer_count="viewer_count", viewer_count_fuzzed="viewer_count_fuzzed", title="title", nsfw="nsfw", description="description", description_html="description_html", resources="resources", resources_html="resources_html", websocket_url="websocket_url", ) def thing_attr(self, thing, attr): if attr == "_fullname": return "LiveUpdateEvent_" + thing._id elif attr == "viewer_count": if thing.state == "live": return thing.active_visitors else: return None elif attr == "viewer_count_fuzzed": if thing.state == "live": return thing.active_visitors_fuzzed else: return None elif attr == "description_html": return filters.spaceCompress( filters.safemarkdown(thing.description, nofollow=True) or "") elif attr == "resources_html": return filters.spaceCompress( filters.safemarkdown(thing.resources, nofollow=True) or "") elif attr == "websocket_url": if thing.state == "live": return websockets.make_url("/live/" + c.liveupdate_event._id, max_age=24 * 60 * 60) else: return None else: return ThingJsonTemplate.thing_attr(self, thing, attr) def kind(self, wrapped): return "LiveUpdateEvent"