Пример #1
0
    def POST(self, key):
        i = web.input(v=None, _method="GET")

        if spamcheck.is_spam():
            return render_template(
                "message.html", "Oops",
                'Something went wrong. Please try again later.')

        recap = get_recaptcha()

        if recap and not recap.validate():
            return render_template(
                "message.html",
                'Recaptcha solution was incorrect',
                'Please <a href="javascript:history.back()">go back</a> and try again.',
            )

        v = i.v and safeint(i.v, None)
        work = web.ctx.site.get(key, v)
        if work is None:
            raise web.notfound()

        try:
            helper = SaveBookHelper(work, None)
            helper.save(web.input())
            add_flash_message("info", utils.get_message("flash_work_updated"))
            raise safe_seeother(work.url())
        except (ClientException, ValidationException) as e:
            add_flash_message('error', str(e))
            return self.GET(key)
Пример #2
0
    def GET(self, key):
        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")

        author = web.ctx.site.get(key)
        if author is None:
            raise web.notfound()
        return render_template("type/author/edit", author)
Пример #3
0
    def GET(self, key):
        i = web.input(v=None, _method="GET")
        v = i.v and safeint(i.v, None)

        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")

        work = web.ctx.site.get(key, v)
        if work is None:
            raise web.notfound()

        return render_template('books/edit', work, recaptcha=get_recaptcha())
Пример #4
0
    def POST(self):
        i = web.input(
            title="",
            publisher="",
            publish_date="",
            id_name="",
            id_value="",
            _test="false",
        )

        if spamcheck.is_spam(i):
            return render_template(
                "message.html", "Oops", 'Something went wrong. Please try again later.'
            )

        if not web.ctx.site.get_user():
            recap = get_recaptcha()
            if recap and not recap.validate():
                return render_template(
                    'message.html',
                    'Recaptcha solution was incorrect',
                    'Please <a href="javascript:history.back()">go back</a> and try again.',
                )

        i = utils.unflatten(i)
        saveutil = DocSaveHelper()
        created_author = saveutil.create_authors_from_form_data(
            i.authors, i.author_names, _test=i._test == 'true'
        )
        match = None if created_author else self.find_matches(i)

        if i._test == 'true' and not isinstance(match, list):
            if match:
                return f'Matched <a href="{match.key}">{match.key}</a>'
            else:
                return 'No match found'

        if isinstance(match, list):
            # multiple matches
            return render_template('books/check', i, match)

        elif match and match.key.startswith('/books'):
            # work match and edition match, match is an Edition
            return self.work_edition_match(match)

        elif match and match.key.startswith('/works'):
            # work match but not edition
            work = match
            return self.work_match(saveutil, work, i)
        else:
            # no match
            return self.no_match(saveutil, i)
Пример #5
0
    def GET(self, key):
        i = web.input(v=None)
        v = i.v and safeint(i.v, None)

        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")

        edition = web.ctx.site.get(key, v)
        if edition is None:
            raise web.notfound()

        work = (edition.works and edition.works[0] or
                edition.make_work_from_orphaned_edition())

        return render_template('books/edit', work, edition, recaptcha=get_recaptcha())
Пример #6
0
    def POST(self, key):
        i = web.input(v=None, _method="GET")

        if spamcheck.is_spam():
            return render_template(
                "message.html", "Oops", 'Something went wrong. Please try again later.'
            )

        recap = get_recaptcha()
        if recap and not recap.validate():
            return render_template(
                "message.html",
                'Recaptcha solution was incorrect',
                'Please <a href="javascript:history.back()">go back</a> and try again.',
            )
        v = i.v and safeint(i.v, None)
        edition = web.ctx.site.get(key, v)

        if edition is None:
            raise web.notfound()
        if edition.works:
            work = edition.works[0]
        else:
            work = None

        add = (
            edition.revision == 1
            and work
            and work.revision == 1
            and work.edition_count == 1
        )

        try:
            helper = SaveBookHelper(work, edition)
            helper.save(web.input())

            if add:
                add_flash_message("info", utils.get_message("flash_book_added"))
            else:
                add_flash_message("info", utils.get_message("flash_book_updated"))

            raise safe_seeother(edition.url())
        except ClientException as e:
            add_flash_message('error', e.args[-1] or e.json)
            return self.GET(key)
        except ValidationException as e:
            add_flash_message('error', str(e))
            return self.GET(key)
Пример #7
0
    def GET(self, key):
        page = web.ctx.site.get(key)

        if not page:
            raise web.notfound()

        return render_template("books/daisy", page)
Пример #8
0
    def POST(self, key):
        author = web.ctx.site.get(key)
        if author is None:
            raise web.notfound()

        i = web.input(_comment=None)
        formdata = self.process_input(i)
        try:
            if not formdata:
                raise web.badrequest()
            elif "_save" in i:
                author.update(formdata)
                author._save(comment=i._comment)
                raise safe_seeother(key)
            elif "_delete" in i:
                author = web.ctx.site.new(key, {
                    "key": key,
                    "type": {
                        "key": "/type/delete"
                    }
                })
                author._save(comment=i._comment)
                raise safe_seeother(key)
        except (ClientException, ValidationException) as e:
            add_flash_message('error', str(e))
            author.update(formdata)
            author['comment_'] = i._comment
            return render_template("type/author/edit", author)
Пример #9
0
    def GET(self):
        """Main user interface for adding a book to Open Library."""

        if not self.has_permission():
            return render_template(
                "permission_denied", "/books/add",
                "Permission denied to add a book to Open Library.")

        i = web.input(work=None, author=None)
        work = i.work and web.ctx.site.get(i.work)
        author = i.author and web.ctx.site.get(i.author)

        return render_template('books/add',
                               work=work,
                               author=author,
                               recaptcha=get_recaptcha())
Пример #10
0
    def POST(self, key):
        book = web.ctx.site.get(key)
        if not book:
            raise web.notfound("")

        i = web.input(file={}, url="")

        # remove references to field storage objects
        web.ctx.pop("_fieldstorage", None)

        data = self.upload(key, i)
        coverid = data.get('id')

        if coverid:
            self.save(book, coverid, url=i.url)
            cover = Image(web.ctx.site, "b", coverid)
            return render_template("covers/saved", cover)
        else:
            return render_template("covers/add", book, {'url': i.url}, data)
Пример #11
0
 def GET(self, key):
     if key.lower() != key:
         raise web.redirect(key.lower())
         
     # temporary code to handle url change from /people/ to /person:
     if key.count("/") == 3:
         key2 = key
         key2 = key2.replace("/people/", "/person:")
         key2 = key2.replace("/places/", "/place:")
         key2 = key2.replace("/times/", "/time:")
         if key2 != key:
             raise web.seeother(key2)
         
     page = get_subject(key, details=True)
     
     if page.work_count == 0:
         return render_template('subjects/notfound.tmpl', key)
     
     return render_template("subjects", page)
Пример #12
0
    def GET(self):
        """Main user interface for adding a book to Open Library."""

        if not self.has_permission():
            return web.seeother("/account/login?redirect={}".format(self.path))

        i = web.input(work=None, author=None)
        work = i.work and web.ctx.site.get(i.work)
        author = i.author and web.ctx.site.get(i.author)

        return render_template('books/add', work=work, author=author, recaptcha=get_recaptcha())
Пример #13
0
    def GET(self, key):
        i = web.input(v=None)
        v = i.v and safeint(i.v, None)

        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath,
                                   "Permission denied to edit " + key + ".")

        edition = web.ctx.site.get(key, v)
        if edition is None:
            raise web.notfound()

        work = edition.works and edition.works[0]

        if not work:
            # HACK: create dummy work when work is not available
            work = web.ctx.site.new(
                '', {
                    'key':
                    '',
                    'type': {
                        'key': '/type/work'
                    },
                    'title':
                    edition.title,
                    'authors': [{
                        'type': {
                            'key': '/type/author_role'
                        },
                        'author': {
                            'key': a['key']
                        }
                    } for a in edition.get('authors', [])],
                    'subjects':
                    edition.get('subjects', []),
                })

        return render_template('books/edit',
                               work,
                               edition,
                               recaptcha=get_recaptcha())
Пример #14
0
    def POST(self, key):
        book = web.ctx.site.get(key)
        if not book:
            raise web.notfound()

        images = web.input(image=[]).image
        if '-' in images:
            images = [int(id) for id in images[:images.index('-')]]
            self.save_images(book, images)
            return render_template("covers/saved", self.get_image(book), showinfo=False)
        else:
            # ERROR
            pass
Пример #15
0
 def GET(self):
     def get_results(q, offset=0, limit=100):
         solr_select = solr_edition_select_url + "?q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (web.urlquote(q), offset, limit)
         return json.loads(urllib.urlopen(solr_select).read())
     return render_template('search/editions.tmpl', get_results)
Пример #16
0
 def GET(self):
     def get_results(q, offset=0, limit=100):
         solr_select = solr_subject_select_url + "?q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=name,type,count&qt=standard&wt=json" % (web.urlquote(q), offset, limit)
         solr_select += '&sort=count+desc'
         return json.loads(urllib.urlopen(solr_select).read())
     return render_template('search/subjects.tmpl', get_results)
Пример #17
0
 def GET(self, key):
     book = web.ctx.site.get(key)
     if not book:
         raise web.notfound()
     return render_template("covers/manage", key, self.get_images(book))
Пример #18
0
 def GET(self, key):
     book = web.ctx.site.get(key)
     return render_template('covers/add', book)