def _assign_epistle_parent(e): #@TODO: REALLY need to put parent_info somewhere smarter, and/or not make this happen so much if e.parent: if e.parent_type == 'story': e.parent_info = queries.get_story_by_id(e.parent) elif e.parent_type == 'comment': e.parent_info = queries.get_comment_by_id(e.parent) elif e.parent_type == 'epistle' or e.parent_type == 'reply': e.parent_info = queries.get_epistle_by_id(e.parent) return e
def full(request): message = "" # @TODO: Change this to use slugs instead of literal guids sub_id = request.matchdict["sub_id"] sub_id = queries.get_story_id_from_slug(sub_id) dbsession = DBSession() p = request.session["safe_post"] prm = request.session["safe_params"] s = request.session logged_in = False if "logged_in" in s: # return {'message': 'Sorry, please log in first.', 'story': {}, 'comments': {}, 'success': False, 'code': 'ENOLOGIN'} logged_in = True # record the comment if "op" in prm and prm["op"] == "del" and logged_in: if "comment_id" in prm: c = queries.get_comment_by_id(prm["comment_id"]) if queries.is_user_allowed_admin_action(s["users.id"], str(c.id)): c.body = "[deleted]" c.deleted = True dbsession.add(c) s["message"] = "Comment deleted." if "op" in prm and prm["op"] == "edit" and logged_in: if "comment_id" in prm: c = queries.get_comment_by_id(prm["comment_id"]) if queries.is_user_allowed_admin_action(s["users.id"], str(c.id)): c.body = prm["body"] dbsession.add(c) s["message"] = "Comment updated." else: if "description-textarea" in request.session["safe_post"] and logged_in: sub = queries.get_story_by_id(sub_id) if queries.is_user_allowed_admin_action(s["users.id"], str(sub.id)): sub.description = prm["description-textarea"] dbsession.add(sub) s["message"] = "Description updated." if "body" in request.session["safe_post"] and logged_in: if p["parent_type"] == "story": in_reply_to = queries.get_story_by_id(p["comment_parent"]).submitter.id elif p["parent_type"] == "comment": c = queries.get_comment_by_id(p["comment_parent"]) in_reply_to = c.user_id c = Comment(sub_id, s["users.id"], p["comment_parent"], prm["body"], in_reply_to=in_reply_to) dbsession.add(c) dbsession.flush() v = Vote(sub_id, s["users.id"], 1, "comment", c.id) v.direction = 1 dbsession.add(v) s["message"] = "Comment added." # @TODO: Stop using SA queries in views, move them to individual models story = queries.get_story_by_id(sub_id) story.tally_votes() story_vote_dict = {} comment_vote_dict = {} if logged_in: # see queries.py; these two should not be separate. #@FIXME story_vote_dict = queries.get_user_votes_on_submission(s["users.id"], sub_id) comment_vote_dict = queries.get_user_votes_on_submissions_comments(s["users.id"], sub_id) page_num = 1 per_page = 30 if "sort.comment_default_order" in request.registry.settings: sort = request.registry.settings["sort.comment_default_order"] else: # do NOT change the hardcoded default, change in the ini as above sort = "top" next_page = None prev_page = None if "comment_sort" in prm: sort = prm["comment_sort"] if "page_num" in prm: try: page_num = int(prm["page_num"]) except: page_num = 1 # comments returns a dict; see queries.py if "comment_perma" not in prm: comments = queries.get_comments( sub_id, organize_parentage=True, page_num=page_num, per_page=per_page, sort=sort ) else: comments = queries.get_comments( sub_id, organize_parentage=True, page_num=page_num, per_page=per_page, sort=sort, target="comment", target_id=prm["comment_perma"], ) for c in comments["comments"]: # @TODO: Don't do this on every load on a real deployment c.tally_votes() if page_num > 1: prev_page = page_num - 1 if comments["max_comments"] > (page_num * per_page): next_page = page_num + 1 return { "story": story, "comments": comments, "success": True, "code": 0, "story_vote_dict": story_vote_dict, "comment_vote_dict": comment_vote_dict, "next_page": next_page, "prev_page": prev_page, }