from openlibrary.plugins import ol_infobase ol_infobase.init_plugin() from openlibrary.core import models models.register_models() models.register_types() # this adds /show-marc/xxx page to infogami import showmarc # Remove movefiles install hook. openlibrary manages its own files. infogami._install_hooks = [h for h in infogami._install_hooks if h.__name__ != "movefiles"] import lists lists.setup() class hooks(client.hook): def before_new_version(self, page): if page.key.startswith('/a/') or page.key.startswith('/authors/'): if page.type.key == '/type/author': return books = web.ctx.site.things({"type": "/type/edition", "authors": page.key}) books = books or web.ctx.site.things({"type": "/type/work", "authors": {"author": {"key": page.key}}}) if page.type.key == '/type/delete' and books: raise ValidationException("Deleting author pages is not allowed.") elif page.type.key != '/type/author' and books: raise ValidationException("Changing type of author pages is not allowed.") @infogami.action
# set up infobase schema. required when running in standalone mode. from openlibrary.core import schema schema.register_schema() from openlibrary.core import models models.register_models() models.register_types() # this adds /show-marc/xxx page to infogami import showmarc # Remove movefiles install hook. openlibrary manages its own files. infogami._install_hooks = [h for h in infogami._install_hooks if h.__name__ != "movefiles"] import lists lists.setup() class hooks(client.hook): def before_new_version(self, page): user = web.ctx.site.get_user() account = user and user.get_account() if account and account.is_blocked(): raise ValidationException("Your account has been suspended. You are not allowed to make any edits.") if page.type.key == '/type/library': bad = list(page.find_bad_ip_ranges(page.ip_ranges or "")) if bad: raise ValidationException('Bad IPs: ' + '; '.join(bad)) if page.key.startswith('/a/') or page.key.startswith('/authors/'): if page.type.key == '/type/author':