Esempio n. 1
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from .views import CartView, SetItemView, RemoveItemView, SetProcessorView, \
    CheckoutView, HistoryView, ConfirmationView, NotificationView
from .functions import get_current_cart

module = QuokkaModule("cart", __name__,
                      template_folder="templates", static_folder="static")

# template globals
module.add_app_template_global(get_current_cart)


# urls
module.add_url_rule('/cart/', view_func=CartView.as_view('cart'))
module.add_url_rule('/cart/setitem/', view_func=SetItemView.as_view('setitem'))
module.add_url_rule('/cart/removeitem/',
                    view_func=RemoveItemView.as_view('removeitem'))
module.add_url_rule('/cart/setprocessor/',
                    view_func=SetProcessorView.as_view('setprocessor'))
module.add_url_rule('/cart/checkout/',
                    view_func=CheckoutView.as_view('checkout'))
module.add_url_rule('/cart/history/', view_func=HistoryView.as_view('history'))
module.add_url_rule('/cart/confirmation/<identifier>/',
                    view_func=ConfirmationView.as_view('confirmation'))
module.add_url_rule('/cart/notification/<identifier>/',
                    view_func=NotificationView.as_view('notification'))

"""
Every url accepts ajax requests, and so do not redirect anything.
Esempio n. 2
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from views import AddTopicVideoLikeView, AddNewsArticleLikeView, SendMessageView, \
    JoinMessageView, BrotherInfoView, BrotherLikeView, TopicsView, NewsView, \
    WechatCheckView, WechatJsView

module = QuokkaModule("brothers", __name__, template_folder="templates")

module.add_url_rule('/brothers/like', view_func=BrotherLikeView.as_view('brotherlike'))
module.add_url_rule('/topic/like', view_func=AddTopicVideoLikeView.as_view('topiclike'))
module.add_url_rule('/news/like', view_func=AddNewsArticleLikeView.as_view('newslike'))
module.add_url_rule('/brotherask/sendmessage', view_func=SendMessageView.as_view('sendmessage'))
module.add_url_rule('/joinmessages/sendmessage', view_func=JoinMessageView.as_view('joinmessage'))
module.add_url_rule('/brotherinfo', view_func=BrotherInfoView.as_view('brotherinfo'))
module.add_url_rule('/topicsinfo', view_func=TopicsView.as_view('topicsinfo'))
module.add_url_rule('/newsinfo', view_func=NewsView.as_view('newsinfo'))
module.add_url_rule('/wechat/check', view_func=WechatCheckView.as_view('wechatcheck'))
module.add_url_rule('/wechat/js', view_func=WechatJsView.as_view('wechatjs'))
Esempio n. 3
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from .views import CommentView
from .models import Comment


module = QuokkaModule("comments", __name__, template_folder="templates")
module.add_url_rule('/comment/<path:path>/',
                    view_func=CommentView.as_view('comment'))


def get_comment(**kwargs):
    try:
        return Comment.objects.get(**kwargs)
    except:
        return None


def get_comments(limit=None, order_by="-created_at", **kwargs):
    contents = Comment.objects.filter(**kwargs).order_by(order_by)
    if limit:
        contents = contents[:limit]
    return contents


module.add_app_template_global(get_comment)
module.add_app_template_global(get_comments)
Esempio n. 4
0
# coding: utf8
from quokka.core.app import QuokkaModule
from .views import SwatchView, ProfileEditView, ProfileView


module = QuokkaModule('accounts', __name__, template_folder='templates')
module.add_url_rule('/accounts/set_swatch/',
                    view_func=SwatchView.as_view('set_swatch'))
module.add_url_rule('/accounts/profile/<user_id>/',
                    view_func=ProfileView.as_view('profile'))
module.add_url_rule('/accounts/profile/edit/',
                    view_func=ProfileEditView.as_view('profile_edit'))
Esempio n. 5
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from .views import SubscribeView

module = QuokkaModule('classes', __name__,
                      template_folder="templates", static_folder="static")

module.add_url_rule('/classes/subscribe/',
                    view_func=SubscribeView.as_view('subscribe'))
Esempio n. 6
0
def configure(app):
    # Register admin views
    app.admin.register(
        app.db.index,
        AdminArticlesView,
        name='Articles',
        endpoint='articleview'
    )

    app.admin.register(
        app.db.index,
        AdminPagesView,
        name='Pages',
        endpoint='pageview'
    )

    app.admin.register(
        app.db.index,
        AdminBlocksView,
        name='Blocks',
        endpoint='blockview',
        category='Administration'
    )

    # Admin admin index panel icons
    app.admin.add_icon(
        endpoint='quokka.core.content.admin.articleview.create_view',
        icon='glyphicon-edit',
        text='New<br>Article'
    )

    app.admin.add_icon(
        endpoint='quokka.core.content.admin.pageview.create_view',
        icon='glyphicon-file',
        text='New<br>Page'
    )

    app.admin.add_icon(
        endpoint='quokka.core.content.admin.blockview.create_view',
        icon='glyphicon-th-list',
        text='New<br>Block'
    )

    # app.admin.add_icon(
    #     endpoint='quokka.core.content.admin.articleview.index_view',
    #     icon='glyphicon-list',
    #     text='All<br>Articles'
    # )

    # Register new commands

    # Register content types

    # Register content formats

    # create new Quokka Module with its views
    module = QuokkaModule(__name__)
    ext = app.config.get("CONTENT_EXTENSION", "html")

    extensions = list(app.config.get('CONTENT_EXTENSION_MAP', {}).keys())
    ext_list = ','.join(extensions or ['html', 'htm', 'rss', 'atom'])
    ext = f'<any({ext_list}):ext>'

    # INDEX|HOME
    # handle /
    module.add_url_rule('/', view_func=ArticleListView.as_view('index'))
    # handle /index.html
    module.add_url_rule(f'/index.{ext}',
                        view_func=ArticleListView.as_view('indexnamed'))
    # handle /2/
    module.add_url_rule(f'/<int:page_number>/',
                        view_func=ArticleListView.as_view('indexpag'))
    # handle /2.html
    module.add_url_rule(f'/<int:page_number>.{ext}',
                        view_func=ArticleListView.as_view('indexpagext'))
    # handle /2/index.html
    module.add_url_rule(f'/<int:page_number>/index.{ext}',
                        view_func=ArticleListView.as_view('indexpagnamed'))

    # USER
    # handle /@authorname/
    # handle /@authorname/2/
    # handle /@authorname/index.html
    # handle /@authorname/2.html
    # handle /@authorname/2/index.html

    # AUTHORS
    # handle /authors/
    module.add_url_rule(f'/authors/',
                        view_func=AuthorListView.as_view('authors'))
    # handle /authors/index.html
    module.add_url_rule(f'/authors/index.{ext}',
                        view_func=AuthorListView.as_view('authorsnamed'))
    # AUTHOR
    # handle /author/name/
    module.add_url_rule('/author/<path:author>/',
                        view_func=ArticleListView.as_view('author'))

    # handle /author/name/index.html
    module.add_url_rule(f'/author/<path:author>/index.{ext}',
                        view_func=ArticleListView.as_view('authornamed'))

    # handle /author/name/2
    module.add_url_rule('/author/<path:author>/<int:page_number>/',
                        view_func=ArticleListView.as_view('authorpag'))

    # handle /author/name/2.html
    module.add_url_rule(f'/author/<path:author>/<int:page_number>.{ext}',
                        view_func=ArticleListView.as_view('authorpagext'))

    # handle /author/name/2/index.html
    module.add_url_rule(f'/author/<path:author>/<int:page_number>/index.{ext}',
                        view_func=ArticleListView.as_view('authorpagnamed'))

    # TAGS
    # handle /tags/
    module.add_url_rule(f'/tags/',
                        view_func=TagListView.as_view('tags'))
    # handle /tags/index.html
    module.add_url_rule(f'/tags/index.{ext}',
                        view_func=TagListView.as_view('tagsnamed'))
    # TAG
    # handle /tag/tagname/
    module.add_url_rule('/tag/<string:tag>/',
                        view_func=ArticleListView.as_view('tag'))
    # handle /tag/tagname/index.html
    module.add_url_rule(f'/tag/<string:tag>/index.{ext}',
                        view_func=ArticleListView.as_view('tagnamed'))
    # handle /tag/tagname/2/
    module.add_url_rule('/tag/<string:tag>/<int:page_number>/',
                        view_func=ArticleListView.as_view('tagpag'))
    # handle /tag/tagname/2.html
    module.add_url_rule(f'/tag/<string:tag>/<int:page_number>.{ext}',
                        view_func=ArticleListView.as_view('tagpagext'))
    # handle /tag/tagname/2/index.html
    module.add_url_rule(f'/tag/<string:tag>/<int:page_number>/index.{ext}',
                        view_func=ArticleListView.as_view('tagpagnamed'))

    # BLOCKS
    # handle /block/slug.html
    module.add_url_rule('/block/<string:block>/',
                        view_func=ArticleListView.as_view('block'))
    # handle /block/blockname/index.html
    module.add_url_rule(f'/block/<string:block>/index.{ext}',
                        view_func=ArticleListView.as_view('blocknamed'))
    # handle /block/blockname/2/
    module.add_url_rule('/block/<string:block>/<int:page_number>/',
                        view_func=ArticleListView.as_view('blockpag'))
    # handle /block/blockname/2.html
    module.add_url_rule(f'/block/<string:block>/<int:page_number>.{ext}',
                        view_func=ArticleListView.as_view('blockpagext'))
    # handle /block/blockname/2/index.html
    module.add_url_rule(f'/block/<string:block>/<int:page_number>/index.{ext}',
                        view_func=ArticleListView.as_view('blockpagnamed'))

    # CATEGORIES
    # handle /categories/
    module.add_url_rule(f'/categories/',
                        view_func=CategoryListView.as_view('categories'))
    # handle /categories/index.html
    module.add_url_rule(f'/categories/index.{ext}',
                        view_func=CategoryListView.as_view('categoriesnamed'))
    # CATEGORY
    # handle /blog/subcategory/
    module.add_url_rule('/<path:category>/',
                        view_func=ArticleListView.as_view('cat'))
    # handle /blog/subcategory/index.html
    module.add_url_rule(f'/<path:category>/index.{ext}',
                        view_func=ArticleListView.as_view('catnamed'))
    # handle /blog/subcategory/2/
    module.add_url_rule(f'/<path:category>/<int:page_number>/',
                        view_func=ArticleListView.as_view('catpag'))
    # handle /blog/subcategory/2.html
    module.add_url_rule(f'/<path:category>/<int:page_number>.{ext}',
                        view_func=ArticleListView.as_view('catpagext'))
    # handle /blog/subcategory/2/index.html
    module.add_url_rule(f'/<path:category>/<int:page_number>/index.{ext}',
                        view_func=ArticleListView.as_view('catpagnamed'))

    # ARTICLE|PAGE
    # handle /article-name.html and /foo/bar/article-name.html
    module.add_url_rule(f'/<path:slug>.{ext}',
                        view_func=DetailView.as_view('detail'))

    # handle the .preview of drafts
    module.add_url_rule('/<path:slug>.preview',
                        view_func=PreviewView.as_view('preview'))

    # add template globals to app
    app.add_template_global(url_for_content)
    app.add_template_filter(strftime)

    # add context processors
    @module.context_processor
    def theme_context():
        return {
            'FOO': 'BAR'
        }

    # register the module
    app.register_module(module)
Esempio n. 7
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from .views import CommentView

module = QuokkaModule("comments", __name__, template_folder="templates")
module.add_url_rule('/comment/<path:path>/',
                    view_func=CommentView.as_view('comment'))
Esempio n. 8
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from .views import AggregatedTopicsListView

# Blueprint endpoints
module = QuokkaModule("rssaggregator", __name__, template_folder="templates")
module.add_url_rule(
    '/aggregated-topics/',
    view_func=AggregatedTopicsListView.as_view('aggregated topic'))
Esempio n. 9
0
# coding: utf-8

from flask import session
from quokka.core.app import QuokkaModule
from .admin import PostAddProductTypeView, admin, BaseView
from .models import ProductType
from .views import CartView, SetItemView, RemoveItemView, SetProcessorView, \
    CheckoutView, HistoryView, ConfirmationView, NotificationView
from .functions import get_current_cart
from quokka.utils.translation import _, _l

module = QuokkaModule("cart",
                      __name__,
                      template_folder="templates",
                      static_folder="static")  #, url_prefix="/cart")

# template globals
module.add_app_template_global(get_current_cart)


@module.before_app_first_request
def load_models():
    if not session.get('cart_loaded_models'):
        session['cart_loaded_models'] = True
        classes = [x.get_class_from_db() for x in ProductType.objects.all()]
        print "loaded models"
        for c in classes:
            admin_class = type('{}Admin'.format(c.__name__), (BaseView, ), {})
            admin.register(c, name=_l(c.__name__), category=_("Cart"))

Esempio n. 10
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from .views import DonationView, TransactionListView
from .functions import get_random_campaign, get_latest_donations

module = QuokkaModule("fundraising", __name__, template_folder="templates")

module.add_app_template_global(get_random_campaign)
module.add_app_template_global(get_latest_donations)

module.add_url_rule('/fundraising/donate/',
                    view_func=DonationView.as_view('donate'))

module.add_url_rule('/fundraising/transactions/',
                    view_func=TransactionListView.as_view('transactions'))
Esempio n. 11
0
# coding: utf-8

from quokka.core.app import QuokkaModule
from .views import AuthorListView, AuthorView
from .utils import get_author, get_authors, get_author_contents


module = QuokkaModule("authors", __name__, template_folder="templates")
module.add_url_rule('/author/<author_id>/',
                    view_func=AuthorView.as_view('author'))
module.add_url_rule('/authors/',
                    view_func=AuthorListView.as_view('authors'))
module.add_app_template_global(get_author)
module.add_app_template_global(get_authors)
module.add_app_template_global(get_author_contents)