示例#1
0
def setup():
    models.register_models()

    client.register_thing_class('/type/edition', Edition)
    client.register_thing_class('/type/author', Author)
    client.register_thing_class('/type/work', Work)

    client.register_thing_class('/type/subject', Subject)
    client.register_thing_class('/type/place', SubjectPlace)
    client.register_thing_class('/type/person', SubjectPerson)
    client.register_thing_class('/type/user', User)

    client.register_changeset_class(None, Changeset)  # set the default class
    client.register_changeset_class('merge-authors', MergeAuthors)
    client.register_changeset_class('undo', Undo)

    client.register_changeset_class('add-book', AddBookChangeset)
    client.register_changeset_class('lists', ListChangeset)
    client.register_changeset_class('new-account', NewAccountChangeset)
示例#2
0
def setup():
    client.register_thing_class('/type/edition', Edition)
    client.register_thing_class('/type/author', Author)
    client.register_thing_class('/type/work', Work)

    client.register_thing_class('/type/subject', Subject)
    client.register_thing_class('/type/place', SubjectPlace)
    client.register_thing_class('/type/person', SubjectPerson)
    client.register_thing_class('/type/user', User)
示例#3
0
def register_models():
    client.register_thing_class(None, Thing) # default
    client.register_thing_class('/type/edition', Edition)
    client.register_thing_class('/type/work', Work)
    client.register_thing_class('/type/author', Author)
    client.register_thing_class('/type/user', User)
    client.register_thing_class('/type/list', List)
    client.register_thing_class('/type/library', Library)
示例#4
0
def register_models():
    client.register_thing_class(None, Thing) # default
    client.register_thing_class('/type/edition', Edition)
    client.register_thing_class('/type/work', Work)
    client.register_thing_class('/type/author', Author)
    client.register_thing_class('/type/user', User)
    client.register_thing_class('/type/list', List)
    client.register_thing_class('/type/usergroup', UserGroup)
示例#5
0
def setup():
    models.register_models()

    client.register_thing_class('/type/edition', Edition)
    client.register_thing_class('/type/author', Author)
    client.register_thing_class('/type/work', Work)

    client.register_thing_class('/type/subject', Subject)
    client.register_thing_class('/type/place', SubjectPlace)
    client.register_thing_class('/type/person', SubjectPerson)
    client.register_thing_class('/type/user', User)

    client.register_changeset_class(None, Changeset) # set the default class
    client.register_changeset_class('merge-authors', MergeAuthors)
    client.register_changeset_class('undo', Undo)

    client.register_changeset_class('add-book', AddBookChangeset)
    client.register_changeset_class('lists', ListChangeset)
    client.register_changeset_class('new-account', NewAccountChangeset)
示例#6
0
文件: code.py 项目: ziwar/openlibrary
    def url(self, suffix="", **params):
        u = self.key + "/" + processors._safepath(self.title or "untitled") + suffix
        if params:
            u += '?' + urllib.urlencode(params)
        return u

class User(client.Thing):
    def get_usergroups(self):
        keys = web.ctx.site.things({'type': '/type/usergroup', 'members': self.key})
        return web.ctx.site.get_many(keys)
    usergroups = property(get_usergroups)

    def is_admin(self):
        return '/usergroup/admin' in [g.key for g in self.usergroups]
    
client.register_thing_class('/type/author', Author)
client.register_thing_class('/type/edition', Edition)
client.register_thing_class('/type/work', Work)
client.register_thing_class('/type/user', User)

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:
示例#7
0
def register_models():
    client.register_thing_class(None, Thing)  # default
    client.register_thing_class("/type/edition", Edition)
    client.register_thing_class("/type/work", Work)
    client.register_thing_class("/type/author", Author)
    client.register_thing_class("/type/user", User)
    client.register_thing_class("/type/list", List)
    client.register_thing_class("/type/library", Library)
示例#8
0
def setup():
    models.register_models()

    client.register_thing_class("/type/edition", Edition)
    client.register_thing_class("/type/author", Author)
    client.register_thing_class("/type/work", Work)

    client.register_thing_class("/type/subject", Subject)
    client.register_thing_class("/type/place", SubjectPlace)
    client.register_thing_class("/type/person", SubjectPerson)
    client.register_thing_class("/type/user", User)

    client.register_changeset_class(None, Changeset)  # set the default class
    client.register_changeset_class("merge-authors", MergeAuthors)
    client.register_changeset_class("undo", Undo)

    client.register_changeset_class("add-book", AddBookChangeset)
    client.register_changeset_class("lists", ListChangeset)
    client.register_changeset_class("new-account", NewAccountChangeset)
示例#9
0
def setup():
    client.register_thing_class('/type/edition', Edition)
    client.register_thing_class('/type/author', Author)
    client.register_thing_class('/type/work', Work)

    client.register_thing_class('/type/subject', Subject)
    client.register_thing_class('/type/place', SubjectPlace)
    client.register_thing_class('/type/person', SubjectPerson)
    client.register_thing_class('/type/user', User)

    client.register_changeset_class(None, Changeset) # set the default class
    client.register_changeset_class('merge-authors', MergeAuthors)
    client.register_changeset_class('undo', Undo)
示例#10
0
        parent = self.key.rsplit('/', 1)[0]
        return web.ctx.site.get(parent)
    
class Issue(client.Thing):
    @property
    def banner_url(self):
        _, yyyy, mm = self.key.split("/")
        prefix = os.path.join("static", "images", yyyy, mm, "banner")
        extensions = [".jpg", ".JPG", ".gif", ".GIF", ".png", ".PNG"]
        for ext in extensions:
            if os.path.exists(prefix + ext):
                return get_image_url(self.key, "banner" + ext, 900, 900)

        return get_image_url(self.key, "banner" + ".gif", 900, 900)

client.register_thing_class('/type/article', Article)
client.register_thing_class('/type/issue', Issue)

@public
def get_metatags():
    return web.ctx.setdefault("metatags", web.storage())

@public
def add_metatag(name, value):
    meta = get_metatags()
    meta[name] = value

@public
def getPlainText(text, collapse_whitespace=False):
    """It takes a text(Body of page, it might have macros) and remove macros and html tags, returns new text.
    """
示例#11
0
def setup():
    client.register_thing_class('/type/edition', Edition)
    client.register_thing_class('/type/author', Author)
    client.register_thing_class('/type/work', Work)

    client.register_thing_class('/type/subject', Subject)
    client.register_thing_class('/type/place', SubjectPlace)
    client.register_thing_class('/type/person', SubjectPerson)
    client.register_thing_class('/type/user', User)

    client.register_changeset_class(None, Changeset) # set the default class
    client.register_changeset_class('merge-authors', MergeAuthors)
    client.register_changeset_class('undo', Undo)

    client.register_changeset_class('add-book', AddBookChangeset)
    
    client.Thing.get_history_preview = get_history_preview
    client.Thing.get_most_recent_change = get_most_recent_change
    client.Thing.prefetch = prefetch