def post(self): form = self.form(request.form) if form.validate(): user = get_current_user() avatar_file_path = user.avatar_file_path avatar = request.files.get('avatar') if avatar: filename = secure_filename(avatar.filename) avatar_file_path = os.path.join('avatars', str(user.id), filename) path = os.path.join(lazy_media_path(), avatar_file_path) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path), 0o777) avatar.save(path) form.populate_obj(user) user.avatar_file_path = avatar_file_path if avatar: user.use_avatar_from = 'upload' user.username = User.generate_username(user.username or user.name, user=user) self.update_user_links(request.form, user) user.save() flash('Profile saved!', 'alert') return redirect( request.args.get('next') or url_for('flaskpress.modules.accounts.profile_edit')) else: flash('Error ocurred!', 'alert error') # form errors return render_template('accounts/profile_edit.html', form=form)
def dispatch_aliases(): app = current_app aliases_map = app.config.get('ALIASES_MAP') if aliases_map and request.path in aliases_map: alias = aliases_map[request.path] status = alias.get('status', 200) if alias['alias_type'] == 'endpoint': endpoint = alias['to'] if alias.get('action') == 'redirect': return redirect(url_for(endpoint, **request.args)) else: # render return app.process_response( app.make_response(app.view_functions[endpoint]())) elif alias['alias_type'] == 'long_slug': long_slug = alias['to'] if alias.get('action') == 'redirect': return redirect(long_slug) # pass request.args ? else: # render endpoint = route_from(long_slug)[0] return app.process_response( app.make_response(app.view_functions[endpoint]())) elif alias['alias_type'] == 'url': return redirect(alias['to']) elif alias['alias_type'] == 'string': return render_template_string(alias['to']), status elif alias['alias_type'] == 'template': return render_template(alias['to']), status
def get(self): user = get_current_user() context = {} for link in user.links: context[link.icon] = link.link return self.needs_login() or render_template( 'accounts/profile_edit.html', form=self.form(instance=user), **context)
def render(self, template, **kwargs): # Store self as admin_view kwargs['admin_view'] = self kwargs['admin_base_template'] = self.admin.base_template # Provide i18n support even if flask-babel is not installed or enabled. kwargs['_gettext'] = gettext kwargs['_ngettext'] = ngettext kwargs['h'] = h # Contribute extra arguments kwargs.update(self._template_args) theme = current_app.config.get('ADMIN_THEME') return render_template(template, theme=theme, **kwargs)
def get(self): return render_template('sitemap.xml', contents=self.get_contents(), channels=self.get_channels())
def get(self, tag): contents = self.get_contents(tag) return render_template(self.get_template_names(), contents=contents)
def render_context(path, form): comments = Comment.objects(path=path, published=True) return render_template('content/comments.html', comments=comments, form=form, path=path)
def get(self, slug): context = self.get_context(slug) return render_template('medias/detail.html', **context)
def get(self, author_id): author = get_author(author_id) contents = get_author_contents(author) return render_template('authors/detail.html', author=author, contents=contents)
def get(self, user_id): return render_template('accounts/profile.html')
def forbidden_page(*args, **kwargs): return render_template("errors/access_forbidden.html"), 403
def server_error_page(*args, **kwargs): return render_template("errors/server_error.html"), 500
def method_not_allowed_page(*args, **kwargs): return render_template("errors/method_not_allowed.html"), 405
def page_not_found(*args, **kwargs): return render_template("errors/page_not_found.html"), 404
def get(self, long_slug): # !!! filter available_until now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath, published=True) if not is_accessible(roles_accepted=channel.roles): raise abort(403, "User has no role to view this channel content") if channel.is_homepage and request.path != channel.get_absolute_url(): return redirect(channel.get_absolute_url()) published_channels = Channel.objects(published=True).values_list('id') if channel.redirect_url: url_protos = ('http://', 'mailto:', '/', 'ftp://') if channel.redirect_url.startswith(url_protos): return redirect(channel.redirect_url) else: return redirect(url_for(channel.redirect_url)) if channel.render_content: return ContentDetail().get( channel.render_content.content.long_slug, True) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, 'show_on_channel': True, 'channel__in': published_channels } if not channel.is_homepage: base_filters['__raw__'] = { '$or': [{ 'mpath': { '$regex': "^{0}".format(mpath) } }, { 'related_mpath': { '$regex': "^{0}".format(mpath) } }] } else: # list only allowed items in homepage user_roles = [role.name for role in get_current_user().roles] if 'admin' not in user_roles: base_filters['__raw__'] = { "$or": [{ "channel_roles": { "$in": user_roles } }, { "channel_roles": { "$size": 0 } }, { "channel_roles": None }, { "channel_roles": { "$exists": False } }] } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) sort = request.args.get('sort') if sort: contents = contents.order_by(sort) elif channel.sort_by: contents = contents.order_by(*channel.sort_by) disabled_pagination = False if not current_app.config.get("PAGINATION_ENABLED", True): disabled_pagination = contents.count() pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = (disabled_pagination or request.args.get('per_page') or channel.per_page or current_app.config.get("PAGINATION_PER_PAGE", 10)) contents = contents.paginate(page=int(page), per_page=int(per_page)) themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get(self): return render_template('authors/list.html', authors=get_authors())
def render_template(self, *args, **kwargs): return render_template(*args, **kwargs)
def get(self, slug): context = self.get_context(slug) return render_template('{{cookiecutter.module_name}}s/detail.html', **context)
def get(self): logger.info('getting list of media') medias = Media.objects.all() return render_template('media/list.html', medias=medias)