Exemple #1
0
 def __exit__(self, etyp, einst, etb):
     if etyp is not None:
         return False
     self.finish()
     self.doc["doctype"] = self.DOCTYPE
     self.doc["modified"] = utils.get_time()
     flask.g.db.put(self.doc)
     self.wrapup()
     self.add_log()
Exemple #2
0
 def __init__(self, doc=None):
     if doc is None:
         self.original = {}
         self.doc = {"_id": utils.get_iuid(), "created": utils.get_time()}
         self.initialize()
     else:
         self.original = copy.deepcopy(doc)
         self.doc = doc
     self.prepare()
     # Special flag when a repeat field has changed value.
     # May be used to immediately redisplay the edit page
     # with changed number of input fields.
     self.repeat_changed = False
Exemple #3
0
 def add_log(self):
     """Add a log entry recording the the difference betweens the current and
     the original document, hiding values of specified keys.
     'added': list of keys for items added in the current.
     'updated': dictionary of items updated; original values.
     'removed': dictionary of items removed; original values.
     """
     added = list(set(self.doc).difference(self.original or {}))
     updated = dict([
         (k, self.original[k])
         for k in set(self.doc).intersection(self.original or {})
         if self.doc[k] != self.original[k]
     ])
     removed = dict([(k, self.original[k])
                     for k in set(self.original or {}).difference(self.doc)
                     ])
     for key in ["_id", "_rev", "modified"]:
         try:
             added.remove(key)
         except ValueError:
             pass
     updated.pop("_rev", None)
     updated.pop("modified", None)
     for key in self.HIDDEN_FIELDS:
         if key in updated:
             updated[key] = "***"
         if key in removed:
             removed[key] = "***"
     entry = {
         "_id": utils.get_iuid(),
         "doctype": constants.LOG,
         "docid": self.doc["_id"],
         "added": added,
         "updated": updated,
         "removed": removed,
         "timestamp": utils.get_time(),
     }
     if hasattr(flask.g, "current_user") and flask.g.current_user:
         entry["username"] = flask.g.current_user["username"]
     else:
         entry["username"] = None
     if flask.has_request_context():
         entry["remote_addr"] = str(flask.request.remote_addr)
         entry["user_agent"] = str(flask.request.user_agent)
     else:
         entry["remote_addr"] = None
         entry["user_agent"] = None
     flask.g.db.put(entry)
Exemple #4
0
def finalize(iuid):
    "Finalize the review for the proposal."
    try:
        review = get_review(iuid)
    except KeyError:
        return utils.error("No such review.", flask.url_for("home"))
    if not allow_finalize(review):
        return utils.error("You are not allowed to finalize this review.")

    if utils.http_POST():
        try:
            with ReviewSaver(doc=review) as saver:
                saver["finalized"] = utils.get_time()
        except ValueError as error:
            utils.flash_error(error)
        return flask.redirect(flask.url_for(".display", iuid=review["_id"]))
Exemple #5
0
def finalize(iuid):
    "Finalize the decision."
    try:
        decision = get_decision(iuid)
    except KeyError:
        return utils.error("No such decision.", flask.url_for("home"))
    if not allow_finalize(decision):
        return utils.error("You are not allowed to finalize this decision.")

    if utils.http_POST():
        try:
            with DecisionSaver(doc=decision) as saver:
                saver["finalized"] = utils.get_time()
        except ValueError as error:
            utils.flash_error(error)
        return flask.redirect(flask.url_for(".display", iuid=decision["_id"]))
Exemple #6
0
def lock(gid):
    "Lock the grant dossier to stop edits by the user."
    grant = get_grant(gid)
    if grant is None:
        return utils.error("No such grant.")
    if not allow_lock(grant):
        return utils.error("You are not allowed to lock this grant dossier.")

    if utils.http_POST():
        try:
            with GrantSaver(doc=grant) as saver:
                saver["locked"] = utils.get_time()
        except ValueError as error:
            utils.flash_error(error)
        return flask.redirect(
            flask.url_for(".display", gid=grant["identifier"]))
Exemple #7
0
 def set_submitted(self):
     if not allow_submit(self.doc):
         raise ValueError("Submit cannot be done; proposal is incomplete,"
                          " or call is closed.")
     self.doc["submitted"] = utils.get_time()
Exemple #8
0
 def set_last_login(self):
     self.doc["last_login"] = utils.get_time()