Exemple #1
0
 def control_panel(self, id):
     """ update from the control panel """
     doc = cls.find_or_404(id)
     form = ControlPanelForm()
     if form.validate_on_submit():
         doc._from_form(form)
         doc.save()
     return model.redirect(doc.url_for())
Exemple #2
0
 def GET(self, hash):
     try:
         url = model.redirect(hash)
         raise web.seeother(url)
     except KeyError:
         raise web.notfound()
     except ValueError:
         raise web.notfound()
Exemple #3
0
 def update(self, id):
     """ update user info """
     doc = cls.find_or_404(id)
     form = ExtendedControlPanelForm(obj=doc)
     if form.validate_on_submit():
         doc._from_form(form)
         doc.save()
         return model.redirect(doc.url_for())
     else:
         url = doc.url_for("update")
         return model.render_template(name + "/update.html", doc=doc, form=form, url=url)
Exemple #4
0
 def set_info(self, id):
     """ Set the author, title, etc to values from worldcat. """
     doc = cls.find_or_404(id)
     try:
         idx = int(model.request.form["idx"])
     except ValueError:
         return self.get_info(id)
     if "google_volumes" not in doc or not doc["google_volumes"] or len(doc["google_volumes"]) <= idx:
         return self.get_info(id)
     entry = doc["google_volumes"][idx]
     mine = ["authors", "title", "identifiers", "genre", "imageLinks", "year"]
     theirs = ["authors", "title", "industryIdentifiers", "categories", "imageLinks", "publishedDate"]
     for m, t in zip(mine, theirs):
         if t in entry:
             doc[m] = entry[t]
     doc["google_volumes_idx"] = idx
     try:
         doc["year"] = int(doc["year"][:4])
     except ValueError:
         del doc["year"]
     doc.save()
     return model.redirect(doc.url_for())