def POST(self, path): if not self.is_scan_user(): return permission_denied('Permission denied.') book = web.ctx.site.get(path) i = web.input("scan_status", _comment=None) q = { 'key': '/scan_record' + path, 'scan_status': { 'connect': 'update', 'value': i.scan_status } } web.ctx.site.write(q, i._comment) def get_email(user): try: delegate.admin_login() return web.utf8(web.ctx.site.get_user_email(user.key).email) finally: web.ctx.headers = [] scan_record = get_scan_record(path) to = scan_record.sponsor and get_email(scan_record.sponsor) cc = getattr(config, 'scan_email_recipients', []) if to: if i.scan_status == 'SCAN_IN_PROGRESS': message = render.scan_inprogress_email(book, scan_record, i._comment) else: message = render.scan_book_notfound_email(book, scan_record, i._comment) web.sendmail(config.from_address, to, message.subject.strip(), str(message), cc=cc) raise web.seeother(web.changequery(query={}))
def POST(self, path): if not self.is_scan_user(): return permission_denied('Permission denied.') book = get_book(path, check_scanned=False, check_ocaid=False) i = web.input("ocaid", volumes=None, multivolume_work=None, _comment=None) q = [ { 'key': path, 'ocaid': { 'connect': 'update', 'value': i.ocaid } }, { 'key': '/scan_record' + path, 'scan_status': { 'connect': 'update', 'value': 'SCAN_COMPLETE' }, 'completion_date': { 'connect': 'update', 'value': datetime.datetime.utcnow().isoformat() } } ] if i.multivolume_work: def volume(index, ia_id): return { 'type': {'key': '/type/volume'}, 'volume_number': index, 'ia_id': ia_id } volumes = i.volumes and i.volumes.split() or [] q[0]['volumes'] = { 'connect': 'update_list', 'value': [volume(index+1, v) for index, v in enumerate(volumes)] } q[0]['ocaid'] = { 'connect': 'update', 'value': '' } web.ctx.site.write(q, i._comment) scan_record = get_scan_record(path) to = scan_record.sponsor and get_email(scan_record.sponsor) cc = getattr(config, 'scan_email_recipients', []) if to: message = render.scan_complete_email(book, scan_record, i._comment) web.sendmail(config.from_address, to, message.subject.strip(), str(message), cc=cc) raise web.seeother(web.changequery(query={}))
def GET(self, path): if not self.is_scan_user(): return permission_denied('Permission denied.') book = get_book(path, check_scanned=False, check_ocaid=False) return render.scan_complete(book)