def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath) 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 } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': {'$regex': "^{0}".format(mpath)}} filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get_contents(self, long_slug): 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 channel.include_in_rss: abort(404) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': {'$regex': "^{0}".format(mpath)}} filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = channel.per_page or current_app.config.get( "PAGINATION_PER_PAGE", 10 ) contents = contents.paginate(page=int(page), per_page=per_page) return contents
def get_contents(self, tag): now = datetime.now() filters = { 'published': True, 'available_at__lte': now } contents = Content.objects(**filters).filter(tags=tag) # instantiate tag like channel for a list feed self.tag = tag 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 current_app.config.get("TAGS_PAGINATION_PER_PAGE") or current_app.config.get("PAGINATION_PER_PAGE", 10) ) contents = contents.paginate(page=int(page), per_page=per_page) return contents
def get(self, long_slug): 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 channel.is_homepage and request.path != "/": # return redirect("/") if channel.redirect_url: return redirect(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 } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': {'$regex': "^{0}".format(mpath)}} filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = ( 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)) # this can be overkill! try another solution # to filter out content in unpublished channels # when homepage and also in blocks # contents = [content for content in contents # if content.channel.published] themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get_contents(self, tag): now = datetime.now() filters = {'published': True, 'available_at__lte': now} contents = Content.objects(**filters).filter(tags=tag) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = current_app.config.get("PAGINATION_PER_PAGE", 10) contents = contents.paginate(page=int(page), per_page=per_page) return contents
def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath) if not channel.is_homepage: contents = Content.objects(__raw__={'mpath': { '$regex': mpath }}, published=True, available_at__lte=now, show_on_channel=True) else: contents = Content.objects(published=True, available_at__lte=now, show_on_channel=True) return render_template('content/list.html', contents=contents)
def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath) if not channel.is_homepage: contents = Content.objects( __raw__={'mpath': {'$regex': mpath}}, published=True, available_at__lte=now, show_on_channel=True ) else: contents = Content.objects( published=True, available_at__lte=now, show_on_channel=True ) return render_template('content/list.html', contents=contents)
def get_contents(self, tag): now = datetime.now() filters = { 'published': True, 'available_at__lte': now } contents = Content.objects(**filters).filter(tags=tag) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = current_app.config.get( "PAGINATION_PER_PAGE", 10 ) contents = contents.paginate(page=int(page), per_page=per_page) return contents
def get_contents(self, tag): now = datetime.now() filters = {'published': True, 'available_at__lte': now} contents = Content.objects(**filters).filter(tags=tag) # instantiate tag like channel for a list feed self.tag = tag 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 current_app.config.get("TAGS_PAGINATION_PER_PAGE") or current_app.config.get("PAGINATION_PER_PAGE", 10)) contents = contents.paginate(page=int(page), per_page=per_page) return contents
def get_contents(self, long_slug): 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 channel.include_in_rss: abort(404) self.channel = channel base_filters = {} filters = { 'published': True, 'available_at__lte': now, } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': { '$regex': "^{0}".format(mpath) } } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = channel.per_page or current_app.config.get( "PAGINATION_PER_PAGE", 10) contents = contents.paginate(page=int(page), per_page=per_page) return contents
def get(self, long_slug): now = datetime.now() path = long_slug.split('/') mpath = ",".join(path) mpath = ",{0},".format(mpath) channel = Channel.objects.get_or_404(mpath=mpath) 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 } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': { '$regex': "^{0}".format(mpath) } } filters.update(channel.get_content_filters()) contents = Content.objects(**base_filters).filter(**filters) themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get(self, long_slug): 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 channel.is_homepage and request.path != "/": # return redirect("/") if channel.redirect_url: return redirect(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 } if not channel.is_homepage: base_filters['__raw__'] = { 'mpath': { '$regex': "^{0}".format(mpath) } } 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) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = (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)) # this can be overkill! try another solution # to filter out content in unpublished channels # when homepage and also in blocks # contents = [content for content in contents # if content.channel.published] themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get(self, long_slug): 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 != "/": # return redirect("/") if channel.redirect_url: return redirect(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 } 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 } }, # the following filters are for backwards compatibility { "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) if current_app.config.get("PAGINATION_ENABLED", True): pagination_arg = current_app.config.get("PAGINATION_ARG", "page") page = request.args.get(pagination_arg, 1) per_page = (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)) # this can be overkill! try another solution # to filter out content in unpublished channels # when homepage and also in blocks # contents = [content for content in contents # if content.channel.published] themes = channel.get_themes() return render_template(self.get_template_names(), theme=themes, contents=contents, channel=channel)
def get(self, long_slug): 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: return redirect(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}}, # the following filters are for backwards compatibility {"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)