def delete_coop_post(review, pnm, handler): ctm = coop.Coop.get_by_id(int(review.ctmid)) if not ctm: return srverr(handler, 404, "Coop " + review.ctmid + " not found") penid = pnm.key().id() reason = handler.request.get('reason') or "" if review.penid != penid: if coop.member_level(penid, ctm) < 2: return srverr(handler, 400, "You may only remove your own membic") if not reason: return srverr(handler, 400, "Reason required") srcrev = Review.get_by_id(int(review.srcrev)) if not srcrev: return srverr(handler, 400, "Source membic " + str(review.srcrev) + " not found") rt = review.revtype revid = str(review.key().id()) topdict = {} if ctm.top20s: topdict = json.loads(ctm.top20s) if rt in topdict and topdict[rt] and revid in topdict[rt]: topdict[rt].remove(revid) ctm.top20s = json.dumps(topdict) # The reason here must be exactly "Removed Membic" so the client can # differentiate between removing a review and removing a member. coop.update_coop_admin_log(ctm, pnm, "Removed Membic", srcrev, reason) coop.update_coop_and_bust_cache(ctm) cached_delete(revid, Review) mctr.count_review_update("delete", review.penid, review.penname, review.ctmid, review.srcrev) return ctm
def write_coop_reviews(review, pnm, ctmidscsv): ctmidscsv = ctmidscsv or "" postnotes = [] for ctmid in csv_list(ctmidscsv): # get cooperative theme ctm = cached_get(intz(ctmid), coop.Coop) if not ctm: logging.info("write_coop_reviews: no Coop " + ctmid) continue penid = pnm.key().id() if not coop.member_level(penid, ctm): logging.info("write_coop_reviews: not member of " + ctmid) continue # get/create theme membic for update and write it to the db where = "WHERE ctmid = :1 AND srcrev = :2" vq = VizQuery(Review, where, int(ctmid), review.key().id()) revs = vq.fetch(1, read_policy=db.EVENTUAL_CONSISTENCY, deadline = 10) ctmrev = None if len(revs) > 0: ctmrev = revs[0] else: ctmrev = Review(penid=penid, revtype=review.revtype) debuginfo(" copying source review") copy_source_review(review, ctmrev, ctmid) mctr.synchronized_db_write(ctmrev) logging.info("write_coop_reviews wrote review for: Coop " + ctmid + " " + ctm.name) # update cache, recalculate recent and top membics for theme update_profile("coop", ctm, ctmrev, srcrev=review) # note the review was posted to this theme logging.info(" appending post note") postnotes.append(coop_post_note(ctm, ctmrev)) logging.info(" writing svcdata.postnotes " + str(postnotes)) write_coop_post_notes_to_svcdata(review, postnotes)