def edit(cid): "Edit the call, or delete it." call = get_call(cid) if not call: return utils.error("No such call.", flask.url_for("home")) if not allow_edit(call): return utils.error("You are not allowed to edit the call.") if utils.http_GET(): return flask.render_template( "call/edit.html", call=call, allow_identifier_edit=allow_identifier_edit(call), ) elif utils.http_POST(): try: with CallSaver(call) as saver: saver.set_identifier(flask.request.form.get("identifier")) saver.set_title(flask.request.form.get("title")) saver["description"] = flask.request.form.get("description") saver["home_description"] = ( flask.request.form.get("home_description").strip() or None ) saver["opens"] = utils.normalize_datetime( flask.request.form.get("opens") ) saver["closes"] = utils.normalize_datetime( flask.request.form.get("closes") ) saver["reviews_due"] = utils.normalize_datetime( flask.request.form.get("reviews_due") ) saver.edit_access(flask.request.form) call = saver.doc except ValueError as error: utils.flash_error(error) return flask.redirect(flask.url_for(".display", cid=call["identifier"])) elif utils.http_DELETE(): if not allow_delete(call): return utils.error("You are not allowed to delete the call.") utils.delete(call) utils.flash_message(f"Deleted call {call['identifier']}:{call['title']}.") return flask.redirect( flask.url_for("calls.owner", username=flask.g.current_user["username"]) )
def edit(gid): "Edit the grant dossier." grant = get_grant(gid) if grant is None: return utils.error("No such grant.") call = anubis.call.get_call(grant["call"]) if utils.http_GET(): if not allow_edit(grant): return utils.error( "You are not allowed to edit this grant dossier.") return flask.render_template("grant/edit.html", grant=grant, call=call) elif utils.http_POST(): if not allow_edit(grant): return utils.error( "You are not allowed to edit this grant dossier.") try: with GrantSaver(doc=grant) as saver: saver.set_fields_values(call.get("grant", []), form=flask.request.form) except ValueError as error: return utils.error(error) if saver.repeat_changed: url = flask.url_for(".edit", gid=grant["identifier"]) else: url = flask.url_for(".display", gid=grant["identifier"]) return flask.redirect(url) elif utils.http_DELETE(): if not allow_delete(grant): return utils.error( "You are not allowed to delete this grant dossier.") proposal = anubis.proposal.get_proposal(grant["proposal"]) with anubis.proposal.ProposalSaver(proposal) as saver: saver["grant"] = None utils.delete(grant) utils.flash_message("Deleted grant dossier.") return flask.redirect( flask.url_for("proposal.display", pid=proposal["identifier"]))
def edit(iuid): "Edit the decision." try: decision = get_decision(iuid) except KeyError: return utils.error("No such decision.", flask.url_for("home")) proposal = anubis.proposal.get_proposal(decision["proposal"]) call = anubis.call.get_call(decision["call"]) if utils.http_GET(): if not allow_edit(decision): return utils.error("You are not allowed to edit this decision.") return flask.render_template("decision/edit.html", decision=decision, proposal=proposal, call=call) elif utils.http_POST(): if not allow_edit(decision): return utils.error("You are not allowed to edit this decision.") try: # NOTE: Repeat field has not been implemented for decision. with DecisionSaver(doc=decision) as saver: saver.set_verdict(form=flask.request.form) saver.set_fields_values(call["decision"], form=flask.request.form) except ValueError as error: return utils.error(error) return flask.redirect(flask.url_for(".display", iuid=decision["_id"])) elif utils.http_DELETE(): if not allow_delete(decision): return utils.error("You are not allowed to delete this decision.") with anubis.proposal.ProposalSaver(proposal) as saver: saver["decision"] = None utils.delete(decision) utils.flash_message("Deleted decision.") return flask.redirect( flask.url_for("proposal.display", pid=proposal["identifier"]))
def edit(iuid): "Edit the review for the proposal." try: review = get_review(iuid) except KeyError: return utils.error("No such review.", flask.url_for("home")) proposal = anubis.proposal.get_proposal(review["proposal"]) call = anubis.call.get_call(review["call"]) if utils.http_GET(): if not allow_edit(review): return utils.error("You are not allowed to edit this review.") return flask.render_template("review/edit.html", review=review, proposal=proposal, call=call) elif utils.http_POST(): if not allow_edit(review): return utils.error("You are not allowed to edit this review.") try: # NOTE: Repeat field has not been implemented for review. with ReviewSaver(doc=review) as saver: saver.set_fields_values(call["review"], form=flask.request.form) except ValueError as error: return utils.error(error) return flask.redirect(flask.url_for(".display", iuid=review["_id"])) elif utils.http_DELETE(): if not allow_delete(review): return utils.error("You are not allowed to delete this review.") utils.delete(review) utils.flash_message("Deleted review.") return flask.redirect( flask.url_for("proposal.display", pid=review["proposal"]))
def edit(pid): "Edit the proposal." proposal = get_proposal(pid) if proposal is None: return utils.error("No such proposal.", flask.url_for("home")) call = anubis.call.get_call(proposal["call"]) if utils.http_GET(): if not allow_edit(proposal): return utils.error("You are not allowed to edit this proposal.") return flask.render_template("proposal/edit.html", proposal=proposal, call=call) elif utils.http_POST(): if not allow_edit(proposal): return utils.error("You are not allowed to edit this proposal.") try: with ProposalSaver(proposal) as saver: saver["title"] = flask.request.form.get("_title") or None saver.set_fields_values(call["proposal"], form=flask.request.form) except ValueError as error: return utils.error(error) # If a repeat field was changed, then redisplay edit page. if saver.repeat_changed: return flask.redirect( flask.url_for(".edit", pid=proposal["identifier"])) if flask.request.form.get("_save") == "submit": proposal = get_proposal(pid, refresh=True) # Get up-to-date info. try: with ProposalSaver(proposal) as saver: saver.set_submitted() # Tests whether allowed or not. except ValueError as error: utils.flash_error(error) else: utils.flash_message("Proposal saved and submitted.") send_submission_email(proposal) elif allow_submit(proposal) and not proposal.get("submitted"): utils.flash_warning("Proposal was saved but not submitted." " You must explicitly submit it!") return flask.redirect( flask.url_for(".display", pid=proposal["identifier"])) elif utils.http_DELETE(): if not allow_delete(proposal): return utils.error("You are not allowed to delete this proposal.") decision = anubis.decision.get_decision(proposal.get("decision")) if decision: utils.delete(decision) reviews = utils.get_docs_view("reviews", "proposal", proposal["identifier"]) for review in reviews: utils.delete(review) utils.delete(proposal) utils.flash_message(f"Deleted proposal {pid}.") if flask.g.am_admin or flask.g.am_staff: url = flask.url_for("proposals.call", cid=call["identifier"]) else: url = flask.url_for("proposals.user", username=proposal["user"]) return flask.redirect(url)