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)
def POST(self, key): if web.re_compile('/(people/[^/]+)').match( key) and spamcheck.is_spam(): return render_template( 'message.html', 'Oops', 'Something went wrong. Please try again later.') return core.edit.POST(self, key)
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)
def POST(self, user_key): # POST is allowed only for /people/foo/lists if not user_key.startswith("/people/"): raise web.nomethod() site = web.ctx.site user = site.get(user_key) if not user: raise web.notfound() if not site.can_write(user_key): raise self.forbidden() data = self.loads(web.data()) # TODO: validate data seeds = self.process_seeds(data.get('seeds', [])) lst = user.new_list( name=data.get('name', ''), description=data.get('description', ''), tags=data.get('tags', []), seeds=seeds, ) if spamcheck.is_spam(lst): raise self.forbidden() try: result = site.save( lst.dict(), comment="Created new list.", action="lists", data={ "list": { "key": lst.key }, "seeds": seeds }, ) except client.ClientException as e: headers = {"Content-Type": self.get_content_type()} data = {"message": e.message} raise web.HTTPError(e.status, data=self.dumps(data), headers=headers) web.header("Content-Type", self.get_content_type()) return delegate.RawText(self.dumps(result))
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)