Python flask 模块,get_template_attribute() 实例源码

我们从Python开源项目中,提取了以下41个代码示例,用于说明如何使用flask.get_template_attribute()

项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def submit_post(obj_response, files, form_values):
    form = forms.PostForm(**form_values)
    if form.validate():
        parent_id = None
        if form.parent_id.data:
            parent_id = form.parent_id.data
        post = Post.submit(form.content.data, current_user, parent_id)

        if parent_id:
            render_comment = get_template_attribute('macros.html', 'render_comment')
            obj_response.html_prepend(''.join(['#post-', parent_id, '-comments']),
                                      render_comment(post, current_user).unescape())
            # update parent comments counter
            obj_response.script(''.join(['$("#load_comment_button_', parent_id, '").children(".badge").html(',
                                         str(Post.query.filter_by(parent_id=parent_id).count()), ')']))
        else:
            render_post = get_template_attribute('macros.html', 'render_post')
            obj_response.html_prepend('#post-container', render_post(post, current_user).unescape())
        obj_response.script("$('#collapsable_post_form').collapse('hide');")
        form.reset()
    render_post_form = get_template_attribute('macros.html', 'render_post_form')
    obj_response.html('#collapsable_post_form', render_post_form(form, current_user).unescape())
    # register again the sijax upload plugin
    obj_response.script('sjxUpload.registerForm({"callback": "post_form_upload", "formId": "post_form"});')
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def load_more_laws(obj_response, group_name, status_name, order, last):
    laws = Law.get_more(group_name=group_name, status_name=status_name, order=order, last=last)
    render_law = get_template_attribute('macros.html', 'render_law')
    more_laws_panel = get_template_attribute('macros.html', 'more_laws_panel')
    if laws:
        for law in laws:
            obj_response.html_append('#laws-container', render_law(law, current_user, actions_footer=True).unescape())
        if order == 'id':
            panel = more_laws_panel(group_name, status_name, order, laws[-1].id).unescape()
        elif order == 'date':
            panel = more_laws_panel(group_name, status_name, order, laws[-1].date).unescape()
        else:
            return
        obj_response.html('#load_more_container', panel)
        # refresh masonry to load the new laws correctly
        obj_response.script('$(".masonry-grid").masonry( "reloadItems" )')
        obj_response.script('$(".masonry-grid").masonry()')
        # refresh and re-enable waypoint to achieve continuous loading
        obj_response.script('Waypoint.refreshAll()')
        obj_response.script('Waypoint.enableAll()')
    else:
        obj_response.html('#load_more_container', more_laws_panel().unescape())
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:tesismometro    作者:joapaspe    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:isni-reconcile    作者:cmh2166    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def load_more_posts(obj_response, group, name, older_than):
    posts = Post.get_more(group=group, name=name, older_than=older_than)
    render_post = get_template_attribute('macros.html', 'render_post')
    more_posts_panel = get_template_attribute('macros.html', 'more_posts_panel')
    if posts:
        for post in posts:
            obj_response.html_append('#post-container', render_post(post, current_user).unescape())
        obj_response.html('#load_more_container', more_posts_panel(group, name, posts[-1].date).unescape())
        # refresh and re-enable waypoint to achieve continuous loading
        obj_response.script('Waypoint.refreshAll()')
        obj_response.script('Waypoint.enableAll()')
    else:
        obj_response.html('#load_more_container', more_posts_panel(group, name, None).unescape())
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def load_comments(obj_response, post_id, depth):
    comments = Post.query.filter_by(parent_id=post_id).order_by(Post.date)
    if comments:
        render_comment = get_template_attribute('macros.html', 'render_comment')
        # clear the comments displayed (to avoid double loading of inserted comments)
        obj_response.html(''.join(['#post-', str(post_id), '-comments']), '')
        for comment in comments:
            obj_response.html_append(''.join(['#post-', str(post_id), '-comments']),
                                     render_comment(comment, current_user, depth).unescape())
        # change the button to hide the comments if pressed again
        obj_response.script(''.join(['$("#load_comment_button_', str(post_id), '").attr("onclick", "hide_comments(',
                                     str(post_id), ',', str(depth), ')")']))
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def load_more_proposals(obj_response, open, pending, older_than):
    proposals = Proposal.get_more(open=open, pending=pending, older_than=older_than)
    render_proposal = get_template_attribute('macros.html', 'render_proposal')
    more_proposals_panel = get_template_attribute('macros.html', 'more_proposals_panel')
    if proposals:
        for proposal in proposals:
            obj_response.html_append('#proposals-container', render_proposal(proposal, current_user).unescape())
        obj_response.html('#load_more_container',
                          more_proposals_panel(proposals[-1].date, open=open, pending=pending).unescape())
        # refresh and re-enable waypoint to achieve continuous loading
        obj_response.script('Waypoint.refreshAll()')
        obj_response.script('Waypoint.enableAll()')
    else:
        obj_response.html('#load_more_container', more_proposals_panel(None).unescape())
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def update_notifications(obj_response, newer_than):
    if current_user.has_new_notifications(newer_than):
        # make the notifications bell green
        obj_response.script('$("#notifications_bell").attr("class", "glyphicon glyphicon-bell notif-unseen")')
        # play an unpleasant sound
        obj_response.script('document.getElementById("bleep_sound").play()')
        # update the notifications dropdown
        render_dropdown = get_template_attribute('macros.html', 'render_notifications_dropdown')
        obj_response.html('#notifications_dropdown', render_dropdown(current_user).unescape())
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def set_all_notifications_seen(obj_response):
    # set all as seen in the database:
    current_user.set_all_notifications_seen()
    # make the notifications bell white
    obj_response.script('$("#notifications_bell").attr("class", "glyphicon glyphicon-bell")')
    # update the notifications dropdown
    render_dropdown = get_template_attribute('macros.html', 'render_notifications_dropdown')
    obj_response.html('#notifications_dropdown', render_dropdown(current_user).unescape())
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def toggle_subscription(obj_response, item_type, item_id):
    render_subscription = get_template_attribute('macros.html', 'render_subscription')
    if item_type == 'proposal':
        query = Proposal.query
    elif item_type == 'law':
        query = Law.query
    elif item_type == 'post':
        query = Post.query
    else:
        return
    item = query.filter_by(id=item_id).first()
    if item:
        item.toggle_subscription(current_user)
        obj_response.html('#' + item_type + '-' + str(item_id) + '-subscription',
                          render_subscription(current_user, item, item_type).unescape())
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def autolink(self, link, is_email):
        if is_email:
            return '<a href="mailto:{0}">{0}</a>'.format(link)
        # analyze url
        parsed = urlparse(link)
        if 'youtube.com' in parsed.netloc:
            vid_id = dict(item.split('=') for item in parsed.query.split('&'))['v']
            return youtube_embed(vid_id)
        if 'youtu.be' in parsed.netloc:
            vid_id = parsed.path
            return youtube_embed(vid_id)
        if parsed.path.lower().endswith(('.jpg', '.jpeg', '.jpe', '.jif', '.jfif', '.jfi', '.gif', '.png')):
            return '<a href="{0}"><img src="{0}" class="img-responsive img-thumbnail" /></a>'.format(link)
        # standard case autolink
        res = requests.get(link)
        soup = BeautifulSoup(res.text, 'html.parser')
        title = soup.title.string
        if len(title) > 50:
            title = title[:47] + '...'
        icon = soup.find("link", rel="shortcut icon")
        if icon:
            icon = icon['href']
            # might be not absolute
            if not icon.startswith('http'):
                # url might have changed
                parsed = urlparse(res.url)
                if not icon.startswith('/'):
                    icon = '/' + icon
                icon = parsed.scheme + '://' + parsed.netloc + icon
        render_autolink = get_template_attribute('macros.html', 'render_autolink')
        return render_autolink(link, title, icon).unescape()
项目:tellmeabout.coffee    作者:billyfung    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Flask-NvRay-Blog    作者:rui7157    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:python_ddd_flask    作者:igorvinnicius    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:QA4LOV    作者:gatemezing    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Sudoku-Solver    作者:ayush1997    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Flask-SocketIO    作者:cutedogspark    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:compatify    作者:hatooku    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:compatify    作者:hatooku    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:ropi    作者:ThumbGen    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:skojjt    作者:martin-green    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Data-visualization    作者:insta-code1    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:zoom-autocomplete-demo    作者:kenju254    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:micro-blog    作者:nickChenyx    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:noobotkit    作者:nazroll    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:subroofer    作者:Sypherio    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:subroofer    作者:Sypherio    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:facebook-face-recognition    作者:mathur    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')
项目:Hawkeye    作者:tozhengxq    | 项目源码 | 文件源码
def test_macros(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            macro = flask.get_template_attribute('_macro.html', 'hello')
            self.assert_equal(macro('World'), 'Hello World!')