Ejemplo n.º 1
0
 def write_log(self):
     "Write a log entry for the change."
     log = dict(
         _id=utils.get_iuid(),
         doc=self.doc["_id"],
         doctype=self.doc[constants.DOCTYPE],
         changed=self.changed,
         modified=utils.timestamp(),
     )
     log[constants.DOCTYPE] = constants.LOG
     if self.rqh:
         # xheaders argument to HTTPServer takes care of X-Real-Ip
         # and X-Forwarded-For
         log["remote_ip"] = self.rqh.request.remote_ip
         try:
             log["user_agent"] = self.rqh.request.headers["User-Agent"]
         except KeyError:
             pass
     if self.account:
         try:
             log["account"] = self.account["email"]
         except (TypeError, AttributeError, KeyError):
             pass
         try:
             log["user_agent"] = self.account["user_agent"]
         except (TypeError, AttributeError, KeyError):
             pass
     self.db.put(log)
Ejemplo n.º 2
0
 def post(self, identifier):
     try:
         publication = self.get_publication(identifier)
         self.check_deletable(publication)
     except (KeyError, ValueError) as error:
         self.see_other("home", error=str(error))
         return
     blacklist = {
         constants.DOCTYPE: constants.BLACKLIST,
         "_id": utils.get_iuid(),
         "title": publication["title"],
         "pmid": publication.get("pmid"),
         "doi": publication.get("doi"),
         "created": utils.timestamp(),
         "owner": self.current_user["email"],
     }
     self.db.put(blacklist)
     self.delete_entity(publication)
     self.see_other("home")
Ejemplo n.º 3
0
 def __init__(self, doc=None, rqh=None, db=None, account=None):
     assert self.doctype in constants.ENTITIES
     if rqh is not None:
         self.rqh = rqh
         self.db = rqh.db
         self.account = account or rqh.current_user
     elif db is not None:
         self.rqh = None
         self.db = db
         self.account = account
     else:
         raise AttributeError('neither db nor rqh given')
     self.doc = doc or dict()
     self.changed = dict()
     if '_id' in self.doc:
         assert self.doctype == self.doc[constants.DOCTYPE]
     else:
         self.doc['_id'] = utils.get_iuid()
         self.doc[constants.DOCTYPE] = self.doctype
         self.initialize()
     self.setup()
Ejemplo n.º 4
0
 def __init__(self, doc=None, rqh=None, db=None, account=None):
     assert self.doctype in constants.ENTITIES
     self.rqh = rqh
     self.db = db
     if self.db is None and self.rqh is None:
         raise AttributeError("neither db nor rqh given")
     if self.db is None:
         self.db = rqh.db
     if self.rqh:
         self.account = account or rqh.current_user
     else:
         self.account = account
     self.doc = doc or dict()
     self.changed = dict()
     if "_id" in self.doc:
         assert self.doctype == self.doc[constants.DOCTYPE]
     else:
         self.doc["_id"] = utils.get_iuid()
         self.doc[constants.DOCTYPE] = self.doctype
         self.initialize()
     self.setup()
Ejemplo n.º 5
0
 def write_log(self):
     "Write a log entry for the change."
     # utils.write_log(self.db, self.rqh, self.doc, changed=self.changed)
     log = dict(_id=utils.get_iuid(),
                doc=self.doc['_id'],
                doctype=self.doc[constants.DOCTYPE],
                changed=self.changed,
                modified=utils.timestamp())
     log[constants.DOCTYPE] = constants.LOG
     if self.rqh:
         # xheaders argument to HTTPServer takes care of X-Real-Ip
         # and X-Forwarded-For
         log['remote_ip'] = self.rqh.request.remote_ip
         try:
             log['user_agent'] = self.rqh.request.headers['User-Agent']
         except KeyError:
             pass
     if self.account:
         try:
             log['account'] = self.account['email']
         except (TypeError, AttributeError, KeyError):
             pass
     self.db.save(log)
Ejemplo n.º 6
0
 def renew_api_key(self):
     "Set a new API key."
     self["api_key"] = utils.get_iuid()
Ejemplo n.º 7
0
 def reset_password(self):
     "Invalidate any previous password and set activation code."
     self.erase_password()
     self["code"] = utils.get_iuid()