def inject(): now = datetime.datetime.now() return dict( channels=Channel.objects(published=True, available_at__lte=now, parent=None), Config=Config, Content=Content, Channel=Channel, homepage=Channel.get_homepage(), Link=Link )
def reset(self): Post.objects( slug__in=[item['slug'] for item in self.json_data.get('posts')] ).delete() SubContentPurpose.objects( identifier__in=[ item['identifier'] for item in self.json_data.get('purposes') ] ).delete() for channel in Channel.objects( slug__in=[ item['slug'] for item in self.json_data.get('channels')]): for subchannel in channel.get_children(): for subsubchannel in subchannel.get_children(): subsubchannel.delete() subchannel.delete() channel.delete() User.objects( email__in=[item['email'] for item in self.json_data.get('users')] ).delete() if self.kwargs.get('first_install'): Quokka.objects.delete()
def get_default_channel(cls): default_channel = cls.DEFAULT_CHANNEL try: return Channel.objects.get(long_slug=default_channel) except Exception as e: logger.warning(str(e)) return Channel.get_homepage()
def get_channels(self): now = datetime.now() filters = { 'published': True, 'available_at__lte': now, } channels = Channel.objects().filter(**filters) return channels
def inject(): now = datetime.datetime.now() return dict( channels=Channel.objects(published=True, available_at__lte=now, parent=None), Config=Config, Content=Content, Channel=Channel, homepage=Channel.get_homepage(), Link=Link, dir=dir, get_url=get_url, request_path=load_req_path, request_endpoint=load_req_endpoint, bp=map(str, app.blueprints), theme_path=load_theme_path, get_unmoderated_comments=get_unmoderated_comments, )
def configure(app): app.add_quokka_url_rule('/sitemap.xml', view_func=SiteMap.as_view('sitemap')) app.add_quokka_url_rule('/mediafiles/<path:filename>', view_func=media) app.add_quokka_url_rule('/template_files/<path:filename>', view_func=template_files) app.add_quokka_url_rule( '/theme_template_files/<identifier>/<path:filename>', view_func=theme_template_files ) for filepath in app.config.get('MAP_STATIC_ROOT', []): app.add_quokka_url_rule(filepath, view_func=static_from_root) # Match content detail, .html added to distinguish from channels # better way? how? content_extension = app.config.get("CONTENT_EXTENSION", "html") app.add_quokka_url_rule('/<path:long_slug>.{0}'.format(content_extension), view_func=ContentDetail.as_view('detail')) # Draft preview app.add_quokka_url_rule('/<path:long_slug>.preview', view_func=ContentDetailPreview.as_view('preview')) # Atom Feed app.add_quokka_url_rule( '/<path:long_slug>.atom', view_func=FeedAtom.as_view('atom_list') ) app.add_quokka_url_rule( '/tag/<tag>.atom', view_func=TagAtom.as_view('atom_tag') ) # RSS Feed app.add_quokka_url_rule( '/<path:long_slug>.xml', view_func=FeedRss.as_view('rss_list') ) app.add_quokka_url_rule('/tag/<tag>.xml', view_func=TagRss.as_view('rss_tag')) # Tag list app.add_quokka_url_rule('/tag/<tag>/', view_func=TagList.as_view('tag')) # Match channels by its long_slug mpath app.add_quokka_url_rule('/<path:long_slug>/', view_func=ContentList.as_view('list')) # Home page app.add_quokka_url_rule( '/', view_func=ContentList.as_view('home'), defaults={"long_slug": Channel.get_homepage('long_slug') or "home"} )
def configure(app): app.add_quokka_url_rule('/sitemap.xml', view_func=SiteMap.as_view('sitemap')) app.add_quokka_url_rule('/mediafiles/<path:filename>', view_func=media) app.add_quokka_url_rule('/template_files/<path:filename>', view_func=template_files) app.add_quokka_url_rule( '/theme_template_files/<identifier>/<path:filename>', view_func=theme_template_files) for filepath in app.config.get('MAP_STATIC_ROOT', []): app.add_quokka_url_rule(filepath, view_func=static_from_root) # Match content detail, .html added to distinguish from channels # better way? how? content_extension = app.config.get("CONTENT_EXTENSION", "html") app.add_quokka_url_rule('/<path:long_slug>.{0}'.format(content_extension), view_func=ContentDetail.as_view('detail')) # Draft preview app.add_quokka_url_rule('/<path:long_slug>.preview', view_func=ContentDetailPreview.as_view('preview')) # Atom Feed app.add_quokka_url_rule('/<path:long_slug>.atom', view_func=FeedAtom.as_view('atom_list')) app.add_quokka_url_rule('/tag/<tag>.atom', view_func=TagAtom.as_view('atom_tag')) # RSS Feed app.add_quokka_url_rule('/<path:long_slug>.xml', view_func=FeedRss.as_view('rss_list')) app.add_quokka_url_rule('/tag/<tag>.xml', view_func=TagRss.as_view('rss_tag')) # Tag list app.add_quokka_url_rule('/tag/<tag>/', view_func=TagList.as_view('tag')) # Match channels by its long_slug mpath app.add_quokka_url_rule('/<path:long_slug>/', view_func=ContentList.as_view('list')) # Home page app.add_quokka_url_rule( '/', view_func=ContentList.as_view('home'), defaults={"long_slug": Channel.get_homepage('long_slug') or "home"})
def set_project_campaign(self, donation_to_project, cart=None): cart = cart or self.cart default_campaign = current_app.config.get( 'FUNDRAISING_PROJECT_CAMPAIGN', {'slug': 'project-campaign', 'title': 'Donation to project', 'description': 'Donation to project', 'published': True, 'channel': Channel.get_homepage()} ) try: campaign = Campaign.objects.get(slug=default_campaign.get('slug')) except Campaign.DoesNotExist: campaign = Campaign(**default_campaign) campaign.save() self.values.append( Values(campaign=campaign, value=float(donation_to_project)) ) cart.items.append( Item( uid=campaign.get_uid(), product=campaign, reference=self, title=campaign.get_title(), description=campaign.get_description(), unity_value=float(donation_to_project) ) ) cart.addlog( "Item added %s" % campaign.get_title(), save=False ) self.save()
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}}, # 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)
#!/usr/bin/python """ THIS SCRIPT CLEANS ALL DATA IN YOUR QUOKKA DB RUN ONLY IN OPENSHIFT DEMO DEPLOY OR AT YOUR OWN RISK!!!! """ from quokka import create_app from quokka.core.models.content import Content from quokka.core.models.config import Config from quokka.core.models.channel import Channel from quokka.modules.accounts.models import User app = create_app() Content.drop_collection() User.drop_collection() Config.drop_collection() Channel.drop_collection()
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 } }, # 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)