Пример #1
0
 def login(self, username, password):
     status = self.account_manager.login(username, password)
     if status == "ok":
         self.account_manager.set_auth_token("/people/" + username)
     else:
         d = {"code": status}
         raise client.ClientException("bad_data", msg="Login failed", json=simplejson.dumps(d))
Пример #2
0
    def get(self, sitename, data):
        key = data.get('key')

        itemid = self._get_itemid(key)
        if itemid:
            edition_key = self._find_edition(sitename, itemid)
            if edition_key:
                # Delete the store entry, indicating that this is no more is an item to be imported.
                self._ensure_no_store_entry(sitename, itemid)
                return self._make_redirect(itemid, edition_key)
            else:
                metadata = ia.get_metadata(itemid)
                doc = ia.edition_from_item_metadata(itemid, metadata)

                if doc is None:
                    # Delete store entry, if it exists.
                    # When an item is darked on archive.org, it should be
                    # automatically removed from OL. Removing entry from store
                    # will trigger the solr-updater to delete it from solr as well.
                    self._ensure_no_store_entry(sitename, itemid)

                    raise client.ClientException(
                        "404 Not Found", "notfound", 
                        simplejson.dumps({"key": "/books/ia:" + itemid, "error": "notfound"}))

                storedoc = self._ensure_store_entry(sitename, itemid)

                # Hack to add additional subjects /books/ia: pages
                # Adding subjects to store docs, will add thise subjects to the books.
                # These subjects are used when indexing the books in solr.
                if storedoc.get("subjects"):
                    doc.setdefault("subjects", []).extend(storedoc['subjects'])
                return simplejson.dumps(doc)
        else:
            return ConnectionMiddleware.get(self, sitename, data)
Пример #3
0
 def register(self, username, displayname, email, password):
     try:
         self.account_manager.register(username=username,
                                       email=email,
                                       password=password,
                                       data={"displayname": displayname})
     except common.InfobaseException, e:
         raise client.ClientException("bad_data", str(e))
Пример #4
0
 def update_account(self, username, **kw):
     status = self.account_manager.update(username, **kw)
     if status != "ok":
         raise client.ClientException("bad_data", "Account activation failed.")
Пример #5
0
 def activate_account(self, username):
     try:
         self.account_manager.activate(username=username)
     except common.InfobaseException, e:
         raise client.ClientException(str(e))