def _check_version(self, distribution, current_version=None): try: response = requests.get('https://pypi.org/pypi/{}/json'.format(distribution)) except requests.RequestException as exc: Logger.get('versioncheck').warning('Version check for %s failed: %s', distribution, exc) raise NoReportError.wrap_exc(ServiceUnavailable()) try: data = response.json() except ValueError: return None if current_version is None: try: current_version = get_distribution(distribution).version except DistributionNotFound: return None current_version = Version(current_version) if current_version.is_prerelease: # if we are on a prerelease, get the latest one even if it's also a prerelease latest_version = Version(data['info']['version']) else: # if we are stable, get the latest stable version versions = [v for v in map(Version, data['releases']) if not v.is_prerelease] latest_version = max(versions) if versions else None return {'current_version': unicode(current_version), 'latest_version': unicode(latest_version) if latest_version else None, 'outdated': (current_version < latest_version) if latest_version else False}
def _check_version(self, distribution, current_version=None): try: response = requests.get('https://pypi.org/pypi/{}/json'.format(distribution)) except requests.RequestException as exc: Logger.get('versioncheck').warning('Version check for %s failed: %s', distribution, exc) raise NoReportError.wrap_exc(ServiceUnavailable()) try: data = response.json() except ValueError: return None if current_version is None: try: current_version = get_distribution(distribution).version except DistributionNotFound: return None current_version = Version(current_version) if current_version.is_prerelease: # if we are on a prerelease, get the latest one even if it's also a prerelease latest_version = Version(data['info']['version']) else: # if we are stable, get the latest stable version versions = [v for v in map(Version, data['releases']) if not v.is_prerelease] latest_version = max(versions) if versions else None return {'current_version': unicode(current_version), 'latest_version': unicode(latest_version) if latest_version else None, 'outdated': (current_version < latest_version) if latest_version else False}
def _entries(self): if self.session_block: # if we have a session block we reschedule the entries inside that block for entry in self.session_block.timetable_entry.children: # the block should only have entries on the same day if entry.start_dt.astimezone( self.event.tzinfo).date() != self.day: raise NoReportError.wrap_exc( BadRequest( _('This action cannot be completed because the event dates' ' have changed. Please reload the page and try again.' ))) yield entry elif self.session: # if we have a session we reschedule the blocks of that session on the day for block in self.session.blocks: if not block.timetable_entry: continue if block.timetable_entry.start_dt.astimezone( self.event.tzinfo).date() == self.day: yield block.timetable_entry else: # if we are on the top level we reschedule all top-level entries on the day query = (self.event.timetable_entries.filter( TimetableEntry.parent_id.is_(None), db.cast(TimetableEntry.start_dt.astimezone(self.event.tzinfo), db.Date) == self.day)) for entry in query: yield entry
def _process(self): from_preview = request.args.get('from_preview') == '1' force_download = request.args.get('download') == '1' signals.attachments.attachment_accessed.send(self.attachment, user=session.user, from_preview=from_preview) if request.values.get('preview') == '1': if self.attachment.type != AttachmentType.file: raise BadRequest previewer = get_file_previewer(self.attachment.file) if not previewer: raise NoReportError.wrap_exc( BadRequest( _('There is no preview available for this file type. ' 'Please refresh the page.'))) preview_content = previewer.generate_content(self.attachment) return jsonify_template('attachments/preview.html', attachment=self.attachment, preview_content=preview_content) else: if self.attachment.type == AttachmentType.link: return redirect(self.attachment.link_url) else: return self.attachment.file.send(inline=not force_download)
def check_event_locked(rh, event, force=False): if (not getattr(rh, 'ALLOW_LOCKED', False) or force) and event.is_locked and request.method not in ('GET', 'HEAD'): raise NoReportError.wrap_exc( Forbidden( _('This event has been locked so no modifications are possible.' )))
def _check_access(self): cfa = self.event.cfa if session.user and not cfa.is_open and not cfa.can_submit_abstracts(session.user): raise NoReportError.wrap_exc(Forbidden(_('The Call for Abstracts is closed. ' 'Please contact the event organizer for further assistance.'))) elif not session.user or not cfa.can_submit_abstracts(session.user): raise Forbidden RHAbstractsBase._check_access(self)
def _check_access(self): cfa = self.event.cfa if session.user and not cfa.is_open and not cfa.can_submit_abstracts(session.user): raise NoReportError.wrap_exc(Forbidden(_('The Call for Abstracts is closed. ' 'Please contact the event organizer for further assistance.'))) elif not session.user or not cfa.can_submit_abstracts(session.user): raise Forbidden RHAbstractsBase._check_access(self)
def _process(self): if not self.registrations: raise NoReportError.wrap_exc(BadRequest(_("The selected registrants have been removed."))) registration = self.registrations[0] email_body = replace_placeholders('registration-email', request.form['body'], regform=self.regform, registration=registration) tpl = get_template_module('events/registration/emails/custom_email.html', email_subject=request.form['subject'], email_body=email_body) html = render_template('events/registration/management/email_preview.html', subject=tpl.get_subject(), body=tpl.get_body()) return jsonify(html=html)
def _process(self): if not self.registrations: raise NoReportError.wrap_exc(BadRequest(_("The selected registrants have been removed."))) registration = self.registrations[0] email_body = replace_placeholders('registration-email', request.form['body'], regform=self.regform, registration=registration) email_subject = replace_placeholders('registration-email', request.form['subject'], regform=self.regform, registration=registration) tpl = get_template_module('events/registration/emails/custom_email.html', email_subject=email_subject, email_body=email_body) html = render_template('events/registration/management/email_preview.html', subject=tpl.get_subject(), body=tpl.get_body()) return jsonify(html=html)
def _process(self): from_preview = request.args.get('from_preview') == '1' force_download = request.args.get('download') == '1' signals.attachments.attachment_accessed.send(self.attachment, user=session.user, from_preview=from_preview) if request.values.get('preview') == '1': if self.attachment.type != AttachmentType.file: raise BadRequest previewer = get_file_previewer(self.attachment.file) if not previewer: raise NoReportError.wrap_exc(BadRequest(_('There is no preview available for this file type. ' 'Please refresh the page.'))) preview_content = previewer.generate_content(self.attachment) return jsonify_template('attachments/preview.html', attachment=self.attachment, preview_content=preview_content) else: if self.attachment.type == AttachmentType.link: return redirect(self.attachment.link_url) else: return self.attachment.file.send(inline=not force_download)
def _redirect_if_insecure(): if not request.endpoint: return if ( request.blueprint == 'assets' or request.endpoint.endswith('.static') or request.endpoint in ('auth.logout', 'auth.accounts', 'core.contact', 'core.change_lang') ): return if 'insecure_password_error' not in session: return if request.method != 'GET': raise NoReportError.wrap_exc(Forbidden(_('You need to change your password'))) if request.is_xhr or request.is_json: return return redirect(url_for('auth.accounts'))
def _entries(self): if self.session_block: # if we have a session block we reschedule the entries inside that block for entry in self.session_block.timetable_entry.children: # the block should only have entries on the same day if entry.start_dt.astimezone(self.event.tzinfo).date() != self.day: raise NoReportError.wrap_exc(BadRequest(_('This action cannot be completed because the event dates' ' have changed. Please reload the page and try again.'))) yield entry elif self.session: # if we have a session we reschedule the blocks of that session on the day for block in self.session.blocks: if not block.timetable_entry: continue if block.timetable_entry.start_dt.astimezone(self.event.tzinfo).date() == self.day: yield block.timetable_entry else: # if we are on the top level we reschedule all top-level entries on the day query = (self.event.timetable_entries .filter(TimetableEntry.parent_id.is_(None), db.cast(TimetableEntry.start_dt.astimezone(self.event.tzinfo), db.Date) == self.day)) for entry in query: yield entry
def check_event_locked(rh, event, force=False): if (not getattr(rh, 'ALLOW_LOCKED', False) or force) and event.is_locked and request.method not in ('GET', 'HEAD'): raise NoReportError.wrap_exc(Forbidden(_('This event has been locked so no modifications are possible.')))