def recover_password(request): FORM_TITLE = _('Password Recovery') main = get_renderer(BASE_TEMPLATE).implementation() localizer = get_localizer(request) recovery_form = RecoverPasswordForm.get_form(localizer) recovery_key = request.params.get('key', None) if recovery_key is None: raise exceptions.NotFound() if request.method == 'POST': controls = request.POST.items() try: appstruct = recovery_form.validate(controls) except deform.ValidationFailure, e: return {'content':e.render(), 'main':main, 'general_stuff':{'form_title':FORM_TITLE}, 'user':get_logged_user(request), } del(appstruct['__LOCALE__']) try: user = AccountRecoveryManager.redefine_password(appstruct['recovery_key'], appstruct['new_password'], request) request.session.flash(_('Password successfully redefined.')) except InvalidActivationKey: raise exceptions.NotFound() except ActivationError: request.session.flash(_('Problems occured when trying to redefine the user password. Please try again.')) return HTTPFound(location=request.route_path('users.login'))
def swf_file(request): sbid = request.matchdict['sbid'] req_part = request.matchdict['part'] monograph = Monograph.get(request.db, sbid) parts = get_book_parts(monograph._id, request) try: selected_part = parts[int(req_part)] except (IndexError, ValueError): raise exceptions.NotFound() part = Part.get(request.db, selected_part['part_sbid']) try: pdf_file = request.db.fetch_attachment(part._id, part.pdf_file['filename']) except (couchdbkit.ResourceNotFound, AttributeError): raise exceptions.NotFound() swf_file = functions.convert_pdf2swf(pdf_file) response = Response(content_type='application/x-shockwave-flash', expires=datetime_rfc822(365)) response.app_iter = swf_file try: response.etag = str(hash(swf_file)) except TypeError: #cannot generate a hash for the object, return it without the ETag pass return response
def delete_book(request): monograph_sbid = request.matchdict.get('sbid', None) if monograph_sbid is None: return Response(status=204) #TODO! catch exception evaluation = request.rel_db_session.query( rel_models.Evaluation).filter_by(monograph_sbid=monograph_sbid).one() try: parts = [ part['doc'] for part in request.db.view( 'scielobooks/monographs_and_parts', include_docs=True, startkey=[evaluation.monograph_sbid, 0], endkey=[evaluation.monograph_sbid, 1]) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() request.rel_db_session.delete(evaluation) try: request.rel_db_session.commit() request.db.delete_docs(parts, all_or_nothing=True) request.session.flash(_('Successfully deleted.')) except: request.rel_db_session.rollback() return Response(status=200)
def book_details(request): main = get_renderer(BASE_TEMPLATE).implementation() sbid = request.matchdict['sbid'] try: monograph = Monograph.get(request.db, sbid) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() book_attachments = [] for attach in [('toc', _('Table of Contents')), ('editorial_decision', _('Editorial Decision')), ('pdf_file', _('Book in PDF')), ('epub_file', _('Book in EPUB'))]: if getattr(monograph, attach[0], None): file_url = request.route_path('staff.evaluation_attachments', sbid=monograph._id, filename=getattr( monograph, attach[0])['filename']) book_attachments.append({ 'url': file_url, 'text': attach[1], 'css_class': attach[0] }) evaluation = request.rel_db_session.query( rel_models.Evaluation).filter_by(monograph_sbid=monograph._id).one() parts = catalog_views.get_book_parts(monograph._id, request) return { 'document': monograph, 'publication_mode': _('Commercial') if getattr(monograph, 'is_comercial', None) else _('Open Access'), 'document_parts': parts, 'evaluation': evaluation, 'book_attachments': book_attachments, 'main': main, 'user': get_logged_user(request), 'cover_full_url': request.route_path('catalog.cover', sbid=monograph._id), 'cover_thumb_url': request.route_path('catalog.cover_thumbnail', sbid=monograph._id), 'add_part_url': request.route_path('staff.new_part', sbid=monograph._id), 'general_stuff': { 'breadcrumb': [ (_('Dashboard'), request.route_path('staff.panel')), (monograph.title, None), ] } }
def favicon(request): try: icon = open(os.path.join(HERE, 'static', 'images', 'favicon.ico')) except IOError: return exceptions.NotFound() return Response(content_type='image/x-icon', app_iter=icon)
def activation(request): main = get_renderer(BASE_TEMPLATE).implementation() activation_key = request.params.get('key', None) if activation_key is None: raise exceptions.NotFound() try: user = RegistrationProfileManager.activate_user(activation_key, request) except InvalidActivationKey: raise exceptions.NotFound() except ActivationError: request.session.flash(_('Problems occured when trying to activate the user. Please try again.')) return {'main':main, 'active':False} request.session.flash(_('User %s has been activated successfuly.' % user.username)) return {'main':main, 'active':True}
def edit_user(request): FORM_TITLE = _('Edit User') main = get_renderer(BASE_TEMPLATE).implementation() localizer = get_localizer(request) publishers = request.rel_db_session.query(models.Publisher.name_slug, models.Publisher.name).all() edit_user_form = EditUserForm.get_form(localizer,publishers) if request.method == 'POST': if 'btn_cancel' in request.POST: return HTTPFound(location=request.route_path('users.list')) controls = request.POST.items() try: appstruct = edit_user_form.validate(controls) except deform.ValidationFailure, e: return {'content':e.render(), 'main':main, 'general_stuff':{'form_title':FORM_TITLE, 'breadcrumb': [ (_('Dashboard'), request.route_path('staff.panel')), (_('Manage Users'), request.route_path('users.list')), (FORM_TITLE, None), ] }, 'user':get_logged_user(request), } try: user = request.rel_db_session.query(users.User).filter_by(id=appstruct['_id']).one() except NoResultFound: raise exceptions.NotFound() if appstruct['password'] is not None: user.password = SHA256.new(appstruct['password']).hexdigest() user.password_encryption = 'SHA256' if len(appstruct['email']): user.email = appstruct['email'] if appstruct['group'] != user.group.name: group = request.rel_db_session.query(users.Group).filter_by(name=appstruct['group']).one() user.group = group request.rel_db_session.add(user) try: request.rel_db_session.commit() except: request.rel_db_session.rollback() request.session.flash(_('Problems occured when trying to update user data. Please try again.')) else: request.session.flash(_('Successfully updated.')) return HTTPFound(location=request.route_path('users.edit_user', id=user.id))
def chapter_details(request): sbid = request.matchdict['sbid'] try: chapter = int(request.matchdict['chapter']) except ValueError: raise exceptions.NotFound(_('Not a valid chapter')) try: monograph = Monograph.get(request.db, sbid) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() if not monograph.visible: raise exceptions.NotFound() parts = get_book_parts(monograph._id, request) try: part = parts[chapter] except IndexError: raise exceptions.NotFound(_('Not a valid chapter')) main = get_renderer(BASE_TEMPLATE).implementation() return { 'document': monograph, 'parts': parts, 'part': part, 'cover_thumb_url': request.route_path('catalog.cover_thumbnail', sbid=monograph._id), 'breadcrumb': { 'home': '/', 'search': request.registry.settings['solr_url'], 'book': request.route_path('catalog.book_details', sbid=sbid), }, 'main': main, }
def get_book_parts(monograph_sbid, request): try: parts = request.db.view('scielobooks/monographs_and_parts', include_docs=True, key=[monograph_sbid, 1]) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() monograph = Monograph.get(request.db, monograph_sbid) monograph_parts = [] for i, part in enumerate(parts): partnumber = part['doc']['order'].zfill(2) part_meta = { 'part_sbid': part['id'], 'partnumber': partnumber, 'title': part['doc']['title'], 'preview_url': request.route_path('catalog.chapter_details', sbid=monograph_sbid, chapter=partnumber), 'swf_url': request.route_path('catalog.swf_file', sbid=monograph_sbid, part=partnumber), 'edit_url': request.route_path('staff.edit_part', sbid=monograph_sbid, part_id=part['id']), } try: part_meta.update({ 'pdf_url': request.route_path('catalog.pdf_file', sbid=monograph_sbid, part=monograph.shortname + '-' + partnumber) }) except AttributeError: # some mandatory data is missing. do not make the link public pass monograph_parts.append(part_meta) monograph_parts = sorted(monograph_parts, key=itemgetter('partnumber')) return monograph_parts
def evaluation_attachments(request): sbid = request.matchdict['sbid'] filename = request.matchdict['filename'] monograph = Monograph.get(request.db, sbid) try: attachment = request.db.fetch_attachment(monograph._id, filename, stream=True) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() response = Response(content_type='application/octet-stream') response.app_iter = attachment return response
def list_publishers(request): def _prepare_response(data): resp = { 'total_items': data['value'], 'title': data['key'], '_id': urllib.quote(data['key']), } return resp try: publishers = [ _prepare_response(pub) for pub in request.db.view('scielobooks/publishers', group=True) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() return publishers
def list_alphasum(request): def _prepare_response(data): resp = { 'total_items': data['value'], 'title': data['key'], '_id': data['key'], } return resp try: letters = [ _prepare_response(letter) for letter in request.db.view('scielobooks/alphabetical', group=True) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() return letters
def epub_file(request): sbid = request.matchdict['sbid'] monograph = Monograph.get(request.db, sbid) try: epub_file = request.db.fetch_attachment( monograph._id, monograph.epub_file['filename'], stream=True) except (couchdbkit.ResourceNotFound, AttributeError, KeyError): raise exceptions.NotFound() response = Response(content_type='application/epub', expires=datetime_rfc822(365)) response.app_iter = epub_file try: response.etag = str(hash(epub_file)) except TypeError: #cannot generate a hash for the object, return it without the ETag pass return response
def ajax_action_unpublish(request): if request.method == 'POST': evaluation_sbid = request.POST.get('sbid', None) if evaluation_sbid is None: return Response('insufficient params') #TODO! catch exception evaluation = request.rel_db_session.query( rel_models.Evaluation).filter_by( monograph_sbid=evaluation_sbid).one() if not evaluation.is_published: return Response('nothing to do') try: parts = [ update_part(part['doc'], {'visible': False}) for part in request.db.view('scielobooks/monographs_and_parts', include_docs=True, startkey=[evaluation.monograph_sbid, 0], endkey=[evaluation.monograph_sbid, 1]) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() evaluation.is_published = False request.rel_db_session.add(evaluation) #TODO! catch exception try: request.rel_db_session.commit() request.db.save_docs(parts, all_or_nothing=True) except: request.rel_db_session.rollback() return Response('done') return Response('nothing to do')
def parts_list(request): monograph_id = request.matchdict['sbid'] try: parts = request.db.view('scielobooks/monographs_and_parts', include_docs=True, key=[monograph_id, 1]) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() documents = [] for part in parts: part_meta = { 'id': part['id'], 'title': part['doc']['title'], 'order': part['doc']['order'], 'creators': part['doc']['creators'], 'pdf_url': request.route_path('catalog.pdf_file', sbid=monograph_id, part=part['doc']['order']), 'edit_url': request.route_path('staff.edit_part', sbid=monograph_id, part_id=part['id']), } documents.append(part_meta) main = get_renderer(BASE_TEMPLATE).implementation() return { 'documents': documents, 'main': main, 'user': get_logged_user(request), }
def list_books(request): _couch_viewname = 'scielobooks/books_by_alpha' kwargs = {} filter_initial = request.params.get('filter_initial', None) filter_publisher = request.params.get('filter_publisher', None) if filter_initial: kwargs['key'] = filter_initial.upper() if filter_publisher: kwargs['key'] = filter_publisher.upper() _couch_viewname = 'scielobooks/books_by_publisher' try: books = [ _prepare_response(book['doc'], request) for book in request.db.view(_couch_viewname, include_docs=True, **kwargs) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() return books
def pdf_file(request): sbid = request.matchdict['sbid'] req_part = request.matchdict['part'].split('-') monograph = Monograph.get(request.db, sbid) if len(req_part) == 2: if req_part[1] != getattr(monograph, 'isbn', None) and req_part[1] != getattr( monograph, 'eisbn', None): raise exceptions.NotFound() try: url = static_url( 'scielobooks:fileserver/{0}/pdf/{1}.pdf'.format( sbid, request.matchdict['part']), request) u = urllib2.urlopen(url) return HTTPFound(location=url) except (urllib2.HTTPError, urllib2.URLError): #cannot find in static file server, fetch from db try: pdf_file = request.db.fetch_attachment( monograph._id, monograph.pdf_file['filename'], stream=True) except (couchdbkit.ResourceNotFound, AttributeError): raise exceptions.NotFound() else: if asbool( request.registry.settings.get('fileserver_sync_enable', False)): if req_part[1] == getattr(monograph, 'eisbn', None) and getattr( monograph, 'isbn', None): #when the eisbn is registered at an already published book. The eisbn takes #precedence when generating the shortname. source_filename = '-'.join([ monograph.shortname.split('-')[0], monograph.isbn ]) try: url = static_url( 'scielobooks:fileserver/{0}/pdf/{1}.pdf'. format(sbid, source_filename), request) u = urllib2.urlopen(url) except (urllib2.HTTPError, urllib2.URLError): # there are no static files available for this book. fresh_pdf_file = request.db.fetch_attachment( monograph._id, monograph.pdf_file['filename'], stream=True) functions.transfer_static_file( request, fresh_pdf_file, monograph._id, monograph.shortname, 'pdf', request.registry. settings['fileserver_remotebase']) else: dest_filename = monograph.shortname functions.symlink_static_file( request, monograph._id, source_filename, dest_filename, 'pdf', request.registry. settings['fileserver_remotebase']) else: fresh_pdf_file = request.db.fetch_attachment( monograph._id, monograph.pdf_file['filename'], stream=True) functions.transfer_static_file( request, fresh_pdf_file, monograph._id, monograph.shortname, 'pdf', request.registry.settings['fileserver_remotebase']) else: parts = get_book_parts(monograph._id, request) try: selected_part = parts[int(req_part[2])] except (IndexError, ValueError): raise exceptions.NotFound() part = Part.get(request.db, selected_part['part_sbid']) try: pdf_file = request.db.fetch_attachment(part._id, part.pdf_file['filename'], stream=True) except (couchdbkit.ResourceNotFound, AttributeError): raise exceptions.NotFound() response = Response(content_type='application/pdf', expires=datetime_rfc822(365)) response.app_iter = pdf_file try: response.etag = str(hash(pdf_file)) except TypeError: #cannot generate a hash for the object, return it without the ETag pass return response
def new_part(request): FORM_TITLE_NEW = _('New Book Part') FORM_TITLE_EDIT = '%s' monograph_id = request.matchdict['sbid'] try: monograph = Monograph.get(request.db, monograph_id) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() localizer = get_localizer(request) part_form = PartForm.get_form(localizer) main = get_renderer(BASE_TEMPLATE).implementation() if request.method == 'POST': if 'btn_cancel' in request.POST: return HTTPFound(location=request.route_path( 'staff.book_details', sbid=request.matchdict['sbid'])) controls = request.POST.items() try: appstruct = part_form.validate(controls) except deform.ValidationFailure, e: return { 'content': e.render(), 'main': main, 'user': get_logged_user(request), 'general_stuff': { 'form_title': FORM_TITLE_NEW, 'breadcrumb': [ (_('Dashboard'), request.route_path('staff.panel')), (monograph.title, request.route_path('staff.book_details', sbid=monograph_id)), (_('New Book Part'), None), ] }, } try: monograph = Monograph.get(request.db, monograph_id) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() monograph_as_python = monograph.to_python() appstruct.update({ 'monograph': monograph_as_python['_id'], 'visible': monograph_as_python['visible'], 'monograph_title': monograph_as_python['title'], 'monograph_isbn': monograph_as_python.get('isbn'), 'monograph_creators': monograph_as_python['creators'], 'monograph_publisher': monograph_as_python['publisher'], }) part = Part.from_python(appstruct) if hasattr(monograph, 'language') and monograph.language: part.monograph_language = monograph.language if hasattr(monograph, 'year') and monograph.year: part.monograph_year = monograph.year is_new = True if getattr(part, '_rev', None) is None else False part.save(request.db) if is_new: request.session.flash(_('Successfully added.')) else: request.session.flash(_('Successfully updated.')) return HTTPFound(location=request.route_path( 'staff.book_details', sbid=request.matchdict['sbid']))
def book_details(request): sbid = request.matchdict['sbid'] try: monograph = Monograph.get(request.db, sbid) except couchdbkit.ResourceNotFound: raise exceptions.NotFound() if not monograph.visible: raise exceptions.NotFound() parts = get_book_parts(monograph._id, request) book_attachments = [] if getattr(monograph, 'pdf_file', None): try: pdf_file_url = request.route_path('catalog.pdf_file', sbid=monograph._id, part=monograph.shortname) except AttributeError: # some mandatory data is missing. do not make the link public pass else: book_attachments.append({ 'url': pdf_file_url, 'text': _('Book in PDF'), 'css_class': 'pdf_file', 'citation_file': 'citation_pdf_url' }) if getattr(monograph, 'epub_file', None): try: epub_file_url = request.route_path('catalog.epub_file', sbid=monograph._id, part=monograph.shortname) except AttributeError: # some mandatory data is missing. do not make the link public pass else: book_attachments.append({ 'url': epub_file_url, 'text': _('Book in EPUB'), 'css_class': 'epub_file', 'citation_file': 'citation_epub_url' }) main = get_renderer(BASE_TEMPLATE).implementation() return { 'document': monograph, 'book_attachments': book_attachments, 'parts': parts, 'cover_thumb_url': request.route_path('catalog.cover_thumbnail', sbid=monograph._id), 'cover_full_url': request.route_path('catalog.cover', sbid=monograph._id), 'breadcrumb': { 'home': '/', 'search': request.registry.settings['solr_url'], }, 'main': main, }
def list_books(request): _couch_viewname = 'scielobooks/books_by_alpha' def _prepare_response(data): book = models.Monograph(**data) if getattr(book, 'pdf_file', None): pdf_file_url = APP_DOMAIN + request.route_path( 'catalog.pdf_file', sbid=book._id, part=book.shortname) else: pdf_file_url = '' if getattr(book, 'epub_file', None): epub_file_url = APP_DOMAIN + request.route_path( 'catalog.epub_file', sbid=book._id, part=book.shortname) else: epub_file_url = '' if getattr(book, 'cover', None): cover_url = APP_DOMAIN + request.route_path('catalog.cover', sbid=book._id) else: cover_url = '' if getattr(book, 'cover_thumbnail', None): cover_thumb_url = APP_DOMAIN + request.route_path( 'catalog.cover_thumbnail', sbid=book._id) else: cover_thumb_url = '' resp = { 'publisher': data.get('publisher', ''), '_id': data.get('_id', ''), 'pisbn': data.get('isbn', ''), 'eisbn': data.get('eisbn', ''), 'language': data.get('language', ''), 'updated': data.get('creation_date', ''), 'cover_thumbnail': { 'type': 'image/jpeg', 'uri': cover_thumb_url, }, 'cover': { 'type': 'image/jpeg', 'uri': cover_url, }, 'synopsis': data.get('synopsis', ''), 'year': data.get('year', ''), 'title': data.get('title', ''), 'creators': book._creators_by_roles(), } if pdf_file_url: resp.update({ 'pdf_file': { 'type': 'application/pdf', 'uri': pdf_file_url, } }) if epub_file_url: resp.update({ 'epub_file': { 'type': 'application/epub+zip', 'uri': epub_file_url, } }) return resp kwargs = {} filter_initial = request.params.get('filter_initial', None) filter_publisher = request.params.get('filter_publisher', None) if filter_initial: kwargs['key'] = filter_initial.upper() if filter_publisher: kwargs['key'] = filter_publisher.upper() _couch_viewname = 'scielobooks/books_by_publisher' try: books = [ _prepare_response(book['doc']) for book in request.db.view( _couch_viewname, include_docs=True, **kwargs) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() return books
def edit_book(request): FORM_TITLE = '%s' localizer = get_localizer(request) publishers = request.rel_db_session.query(rel_models.Publisher.name_slug, rel_models.Publisher.name).all() monograph_form = MonographForm.get_form(localizer, publisher_values=publishers) main = get_renderer(BASE_TEMPLATE).implementation() if request.method == 'POST': if 'btn_cancel' in request.POST: return HTTPFound(location=request.route_path( 'staff.book_details', sbid=request.matchdict['sbid'])) controls = request.POST.items() try: appstruct = monograph_form.validate(controls) except deform.ValidationFailure, e: monograph = Monograph.get(request.db, request.matchdict['sbid']) return { 'content': e.render(), 'main': main, 'user': get_logged_user(request), 'general_stuff': { 'form_title': FORM_TITLE % monograph.title, 'breadcrumb': [ (_('Dashboard'), request.route_path('staff.panel')), (monograph.title, request.route_path('staff.book_details', sbid=monograph._id)), (_('Edit'), None), ] }, } if appstruct['cover'] and appstruct['cover']['fp'] is not None: cover_thumbnail = { 'fp': create_thumbnail(appstruct['cover']['fp']), 'filename': appstruct['cover']['filename'] + '.thumb.jpeg', 'uid': '', } appstruct['cover_thumbnail'] = cover_thumbnail publisher_slug = appstruct.pop('publisher') publisher = request.rel_db_session.query( rel_models.Publisher).filter_by(name_slug=publisher_slug).one() appstruct['publisher'] = publisher.name existing_doc_appstruct = Monograph.get(request.db, appstruct['_id']).to_python() existing_doc_appstruct.update(appstruct) monograph = Monograph.from_python(existing_doc_appstruct) monograph.save(request.db) #update monographic data that lives on each part monograph_as_python = monograph.to_python() monographic_data = { 'monograph_title': monograph_as_python['title'], 'monograph_creators': monograph_as_python['creators'], 'monograph_publisher': monograph_as_python['publisher'], } if monograph_as_python.get('isbn'): monographic_data.update( {'monograph_isbn': monograph_as_python['isbn']}) try: parts = [ update_part(part['doc'], monographic_data) for part in request.db.view('scielobooks/monographs_and_parts', include_docs=True, key=[monograph._id, 1]) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() request.db.save_docs(parts, all_or_nothing=True) #update evaluation data evaluation = request.rel_db_session.query( rel_models.Evaluation).filter_by( monograph_sbid=monograph_as_python['_id']).one() for attr in [ 'title', 'isbn', ]: try: setattr(evaluation, attr, monograph_as_python[attr]) except KeyError: setattr(evaluation, attr, None) request.rel_db_session.add(evaluation) try: request.rel_db_session.commit() except IntegrityError: request.rel_db_session.rollback() request.session.flash(_('Successfully updated.')) return HTTPFound(location=request.route_path('staff.book_details', sbid=monograph._id))
def ajax_action_publish(request): if request.method == 'POST': evaluation_sbid = request.POST.get('sbid', None) if evaluation_sbid is None: return Response('insufficient params') #TODO! catch exception try: evaluation = request.rel_db_session.query( rel_models.Evaluation).filter_by( monograph_sbid=evaluation_sbid).one() except NoResultFound: return Response('invalid action') if evaluation.status != 'accepted' and evaluation.status != 'accepted-with-condition': return Response('invalid action') if evaluation.is_published: return Response('nothing to do') try: parts = [ update_part(part['doc'], { 'visible': True, 'publication_date': str(date.today()) }) for part in request.db.view( 'scielobooks/monographs_and_parts', include_docs=True, startkey=[evaluation.monograph_sbid, 0], endkey=[evaluation.monograph_sbid, 1]) ] except couchdbkit.ResourceNotFound: raise exceptions.NotFound() evaluation.is_published = True request.rel_db_session.add(evaluation) monograph = Monograph.get(request.db, evaluation.monograph_sbid) if not getattr(monograph, 'eisbn', None): # eISBN is required to publish a book return Response('invalid action') #TODO! catch exception try: request.rel_db_session.commit() request.db.save_docs(parts, all_or_nothing=True) except: request.rel_db_session.rollback() if hasattr(monograph, 'pdf_file'): # Transfer pdf file to static.scielo.org pdf_file = request.db.fetch_attachment( monograph._id, monograph.pdf_file['filename'], stream=True) if request.registry.settings.get('fileserver_sync_enable', 'false').lower() == 'true': #weird. need to find a better way to get boolean values from #settings. transfer_static_file( request, pdf_file, monograph._id, monograph.shortname, 'pdf', request.registry.settings['fileserver_remotebase']) return Response('done') return Response('nothing to do')
del(appstruct['__LOCALE__']) try: user = AccountRecoveryManager.redefine_password(appstruct['recovery_key'], appstruct['new_password'], request) request.session.flash(_('Password successfully redefined.')) except InvalidActivationKey: raise exceptions.NotFound() except ActivationError: request.session.flash(_('Problems occured when trying to redefine the user password. Please try again.')) return HTTPFound(location=request.route_path('users.login')) else: try: account = request.rel_db_session.query(users.AccountRecovery).filter_by(recovery_key=recovery_key).one() except NoResultFound: raise exceptions.NotFound() return {'content':recovery_form.render({'recovery_key':recovery_key}), 'main':main, 'general_stuff':{'form_title':FORM_TITLE}, 'user':get_logged_user(request), } def users_list(request): main = get_renderer(BASE_TEMPLATE).implementation() user_list = request.rel_db_session.query(users.User).all() return {'users':user_list, 'main':main, 'general_stuff':{'breadcrumb': [ (_('Dashboard'), request.route_path('staff.panel')),