当前位置: 首页>>代码示例>>Python>>正文


Python SQLFORM.elements方法代码示例

本文整理汇总了Python中gluon.SQLFORM.elements方法的典型用法代码示例。如果您正苦于以下问题:Python SQLFORM.elements方法的具体用法?Python SQLFORM.elements怎么用?Python SQLFORM.elements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gluon.SQLFORM的用法示例。


在下文中一共展示了SQLFORM.elements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: comment_internal

# 需要导入模块: from gluon import SQLFORM [as 别名]
# 或者: from gluon.SQLFORM import elements [as 别名]
    def comment_internal(self):
        is_author = False
        if self.session.auth and self.session.auth.user:
            is_author = True if self.session.auth.user.id == self.context.article.author else False
            self.db.Comments.article_id.default = self.context.article.id
            self.db.Comments.user_id.default = self.session.auth.user.id
            self.db.Comments.commenttime.default = self.request.now
            self.db.Comments.comment_text.label = self.T("Post your comment")
            from plugin_ckeditor import CKEditor
            ckeditor = CKEditor()
            self.db.Comments.comment_text.widget = ckeditor.basicwidget
            form = SQLFORM(self.db.Comments, formstyle='divs')
            submit_button = form.elements(_type='submit')[0]
            submit_button['_class'] = "btn btn-info"
            submit_button['_value'] = self.T("Post comment")
            if form.process(message_onsuccess=self.T('Comment included')).accepted:
                self.new_article_event('new_article_comment',
                                        self.session.auth.user,
                                        data={'event_text': form.vars.comment_text,
                                              'event_link': form.vars.nickname or form.vars.user_id,
                                              'event_image': self.get_image(None, 'user', themename=self.context.theme_name, user=self.session.auth.user),
                                              'event_link_to': "%s/%s#comment_%s" % (self.context.article.id, self.context.article.slug, form.vars.id)})

        else:
            form = CAT(A(self.T("Login to post comments"),
                     _class="button btn",
                     _href=self.CURL('default', 'user',
                                  args='login',
                                  vars=dict(_next=self.CURL('article', 'show',
                                       args=[self.context.article.id,
                                             self.context.article.slug])))),
                       BR(),
                       BR())

        if 'commentlimitby' in self.request.vars:
            limitby = [int(item) for item in self.request.vars.commentlimitby.split(',')]
        else:
            limitby = (0, 5)
        comment_set = self.db(self.db.Comments.article_id == self.context.article.id)
        comments = comment_set.select(orderby=~self.db.Comments.created_on, limitby=limitby)

        if comments and is_author:
            edit_in_place = ckeditor.bulk_edit_in_place(["comment_%(id)s" % comment for comment in comments], URL('editcomment'))
        elif comments and self.session.auth and self.session.auth.user:
            usercomments = comments.find(lambda row: row.user_id == self.session.auth.user.id)
            if usercomments:
                edit_in_place = ckeditor.bulk_edit_in_place(["comment_%(id)s" % comment for comment in usercomments], URL('editcomment'))
            else:
                edit_in_place = ('', '')
        else:
            edit_in_place = ('', '')

        self.context.lencomments = comment_set.count()

        def showmore(anchor, limitby=limitby, lencomments=self.context.lencomments):
            if lencomments > limitby[1]:
                return A(self.T('show more comments'), _class="button btn", _style="width:97%;", _href=self.CURL(args=self.request.args, vars={"commentlimitby": "0,%s" % (limitby[1] + 10)}, anchor=anchor))
            else:
                return ''

        return DIV(
                  H4(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='board.24.png')), self.T("Comments"), " (%s)" % self.context.lencomments),
                  UL(form,
                      *[LI(
                           H5(
                              A(
                                 self.T("%s %s", (comment.nickname or comment.user_id,
                                                   self.db.pdate(comment.commenttime))),
                               _href=self.CURL('person', 'show', args=comment.nickname or comment.user_id))
                             ),
                            DIV(
                               XML(comment.comment_text),
                               **{'_class': 'editable commentitem',
                                  '_data-object': 'comment',
                                  '_data-id': comment.id,
                                  '_id': "comment_%s" % comment.id}
                             ),
                            _class="comment_li"
                          ) for comment in comments],
                  **dict(_class="comment_ul")),
                  edit_in_place[1],
                  showmore("comment_%s" % comment.id) if comments else '',
                  _class="internal-comments article-box"
                  )
开发者ID:kaiquewdev,项目名称:Movuca,代码行数:86,代码来源:article.py


注:本文中的gluon.SQLFORM.elements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。