コード例 #1
0
ファイル: code.py プロジェクト: purhan/infogami
def movetemplates(prefix_pattern=None):
    """Move templates to wiki."""
    def get_title(name):
        if name.startswith('/type/'):
            type, name = name.rsplit('/', 1)
            title = '%s template for %s' % (name, type)
        else:
            title = '%s template' % (name)
        return title

    templates = []

    for name, t in template.disktemplates.items():
        if isinstance(t, LazyTemplate):
            try:
                t.func()
            except:
                print('unable to load template', t.name, file=web.debug)
                raise

    for name, t in template.disktemplates.items():
        prefix = '/templates/'
        wikipath = _wikiname(name, prefix, '.tmpl')
        if prefix_pattern is None or wikipath.startswith(prefix_pattern):
            title = get_title(name)
            body = open(t.filepath).read()
            d = web.storage(create='unless_exists', key=wikipath, type={"key": '/type/template'}, title=title, body=dict(connect='update', value=body))
            templates.append(d)

    delegate.admin_login()
    result = web.ctx.site.write(templates)
    for p in result.created:
        print("created", p)
    for p in result.updated:
        print("updated", p)
コード例 #2
0
ファイル: code.py プロジェクト: hornc/infogami
def movemacros():
    """Move macros to wiki."""
    macros = []

    for name, t in macro.diskmacros.items():
        if isinstance(t, LazyTemplate):
            t.func()

    for name, m in macro.diskmacros.items():
        key = _wikiname(name, '/macros/', '')
        body = open(m.filepath).read()
        d = web.storage(
            create='unless_exists',
            key=key,
            type={'key': '/type/macro'},
            description='',
            macro=body,
        )
        macros.append(d)
    delegate.admin_login()
    result = web.ctx.site.write(macros)
    for p in result.created:
        print("created", p)
    for p in result.updated:
        print("updated", p)
コード例 #3
0
ファイル: code.py プロジェクト: anandology/infogami
def movetemplates(prefix_pattern=None):
    """Move templates to wiki."""
    def get_title(name):
        if name.startswith('/type/'):
            type, name = name.rsplit('/', 1)
            title = '%s template for %s' % (name, type)
        else:
            title = '%s template' % (name)
        return title
    
    templates = []

    for name, t in template.disktemplates.items():
        if isinstance(t, LazyTemplate):
            try:
                t.func()
            except:
                print >> web.debug, 'unable to load template', t.name
                raise
    
    for name, t in template.disktemplates.items():
        prefix = '/templates/'
        wikipath = _wikiname(name, prefix, '.tmpl')
        if prefix_pattern is None or wikipath.startswith(prefix_pattern):
            title = get_title(name)
            body = open(t.filepath).read()
            d = web.storage(create='unless_exists', key=wikipath, type={"key": '/type/template'}, title=title, body=dict(connect='update', value=body))
            templates.append(d)
            
    delegate.admin_login()
    result = web.ctx.site.write(templates)
    for p in result.created:
        print "created", p
    for p in result.updated:
        print "updated", p
コード例 #4
0
ファイル: __init__.py プロジェクト: EdwardBetts/infogami
def install():
    """Setup everything."""
    from infogami.utils import delegate
    delegate.fakeload()
    if not web.ctx.site.exists():
        web.ctx.site.create()

    delegate.admin_login()
    for a in _install_hooks:
        print >> web.debug, a.__name__
        a()
コード例 #5
0
ファイル: code.py プロジェクト: EdwardBetts/infogami
 def POST(self):
     i = web.input()
     f = forms.forgot_password()
     if not f.validates(i):
         return render.forgot_password(f)
     else:
         from infogami.infobase.client import ClientException
         try:
             delegate.admin_login()
             d = web.ctx.site.get_reset_code(i.email)
         except ClientException, e:
             f.note = str(e)
             web.ctx.headers = []
             return render.forgot_password(f)
         else:
コード例 #6
0
def install():
    """Setup everything."""
    
    # set debug=False to avoid reload magic.
    web.config.debug = False
    
    from infogami.utils import delegate
    delegate.fakeload()
    if not web.ctx.site.exists():
        web.ctx.site.create()

    delegate.admin_login()
    for a in _install_hooks:
        print >> web.debug, a.__name__
        a()
コード例 #7
0
 def POST(self):
     i = web.input()
     f = forms.forgot_password()
     if not f.validates(i):
         return render.forgot_password(f)
     else:
         from infogami.infobase.client import ClientException
         try:
             delegate.admin_login()
             d = web.ctx.site.get_reset_code(i.email)
         except ClientException, e:
             f.note = str(e)
             web.ctx.headers = []
             return render.forgot_password(f)
         else:
コード例 #8
0
ファイル: code.py プロジェクト: anandology/infogami
def movemacros():
    """Move macros to wiki."""
    macros = []

    for name, t in macro.diskmacros.items():
        if isinstance(t, LazyTemplate):
            t.func()
    
    for name, m in macro.diskmacros.items():
        key = _wikiname(name, '/macros/', '')
        body = open(m.filepath).read()
        d = web.storage(create='unless_exists', key=key, type={'key': '/type/macro'}, description='', macro=body)
        macros.append(d)
    delegate.admin_login()
    result = web.ctx.site.write(macros)
    for p in result.created:
        print "created", p
    for p in result.updated:
        print "updated", p
コード例 #9
0
def move(dir, extension, recursive=False, readfunc=None):
    readfunc = readfunc or eval
    pages = []
    from infogami.utils import delegate
    for p in delegate.plugins:
        path = os.path.join(p.path, dir)
        if os.path.exists(path) and os.path.isdir(path):
            files = [os.path.join(path, f) for f in os.listdir(path) if f.endswith(extension)]
            for f in files:
                page = readfunc(open(f).read())
                if isinstance(page, list):
                    pages.extend(page)
                else:
                    pages.append(page)

    delegate.admin_login()
    result = web.ctx.site.save_many(pages, "install")
    for r in result:
        print(r)
コード例 #10
0
ファイル: code.py プロジェクト: z84213966/openlibrary
    def POST(self, path):
        book = get_book(path)
        record = get_scan_record(path)
        user = accounts.get_current_user()
        delegate.admin_login()
        q = {
            'key': '/scan_record' + path,
            'scan_status': {
                'connect': 'update',
                'value': 'WAITING_FOR_BOOK'
            },
            'sponsor': {
                'connect': 'update',
                'key': user.key
            },
            'request_date': {
                'connect': 'update',
                'value': datetime.datetime.utcnow().isoformat()
            }
        }
        try:
            web.ctx.site.write(q)
        finally:
            web.ctx.headers = []

        def get_to():
            if config.get('plugin_scod') is not None:
                return config.plugin_scod.get('email_recipients', [])
            else:
                return config.get('scan_email_recipients', [])

        to = get_to()
        if to:
            scan_record = get_scan_record(path)
            message = render.scan_request_email(book, scan_record)
            web.sendmail(config.from_address, to, message.subject.strip(),
                         message)

        to = get_email(user)
        message = render.scan_waiting_email(book, scan_record)
        web.sendmail(config.from_address, to, message.subject.strip(), message)
        return render.scan_inprogress(book)
コード例 #11
0
ファイル: code.py プロジェクト: amoghravish/openlibrary
    def POST(self, path):
        book = get_book(path)
        record = get_scan_record(path)
        user = web.ctx.site.get_user()
        delegate.admin_login()
        q = {
            'key': '/scan_record' + path,
            'scan_status': {
                'connect': 'update',
                'value': 'WAITING_FOR_BOOK'
            },
            'sponsor': {
                'connect': 'update',
                'key': user.key
            },
            'request_date': {
                'connect': 'update',
                'value': datetime.datetime.utcnow().isoformat()
            }
        }
        try:
            web.ctx.site.write(q)
        finally:
            web.ctx.headers = []

        def get_to():
            if config.get('plugin_scod') is not None:
                return config.plugin_scod.get('email_recipients', [])
            else:
                return config.get('scan_email_recipients', [])
        
        to = get_to()
        if to:
            scan_record = get_scan_record(path)
            message = render.scan_request_email(book, scan_record)
            web.sendmail(config.from_address, to, message.subject.strip(), message)

        to = get_email(user)
        message = render.scan_waiting_email(book, scan_record)
        web.sendmail(config.from_address, to, message.subject.strip(), message)
        return render.scan_inprogress(book)
コード例 #12
0
ファイル: code.py プロジェクト: paulproteus/infogami
    def POST(self):
        i = web.input()
        f = forms.forgot_password()
        if not f.validates(i):
            return render.forgot_password(f)
        else:
            from infogami.infobase.client import ClientException
            try:
                delegate.admin_login()
                d = web.ctx.site.get_reset_code(i.email)
            except ClientException as e:
                f.note = str(e)
                web.ctx.headers = []
                return render.forgot_password(f)
            else:
                # clear the cookie set by delegate.admin_login
                # Otherwise user will be able to work as admin user.
                web.ctx.headers = []

            msg = render.password_mailer(web.ctx.home, d.username, d.code)
            web.sendmail(config.from_address, i.email, msg.subject.strip(), str(msg))
            return render.passwordsent(i.email)
コード例 #13
0
 def g(*a, **kw):
     try:
         delegate.admin_login()
         return f(*a, **kw)
     finally:
         web.ctx.headers = []
コード例 #14
0
ファイル: code.py プロジェクト: kamdjouduplex/openlibrary
 def get_email(user):
     try:
         delegate.admin_login()
         return web.utf8(web.ctx.site.get_user_email(user.key).email)
     finally:
         web.ctx.headers = []
コード例 #15
0
ファイル: account.py プロジェクト: RaceList/openlibrary
 def g(*a, **kw):
     try:
         delegate.admin_login()
         return f(*a, **kw)
     finally:
         web.ctx.headers = []