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


Python Template.__init__方法代码示例

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


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

示例1: make_admin_staff_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_staff_panel(self):
        session = model.Session()
        table = model.account
        sql = table.select().order_by(table.c.account.asc(), table.c.username.asc())

        query = session.execute(sql)
        users = [dict(row.items()) for row in query]

        rowtype = 1
        for row in users:
            # Alternate between values 1 and 2.
            rowtype ^= 0x3
            row["rowtype"] = rowtype

            # Get latest action from DB.
            action_table = model.activity
            action_grab_sql = (
                action_table.select()
                .where(action_table.c.username == row["username"])
                .order_by(action_table.c.date.desc())
            )
            last_action = session.execute(action_grab_sql).fetchone()

            # Copy to row.
            if last_action:
                row["action"] = last_action["action"]
                row["actiondate"] = last_action["date"]
            else:
                row["action"] = None
                row["actiondate"] = None

        Template.__init__(self, "staff_management", users=users)
开发者ID:dequis,项目名称:wakarimasen,代码行数:34,代码来源:staff_interface.py

示例2: make_admin_post_search_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_post_search_panel(self, search, text, caller='internal'):
        board = self.board
        session = model.Session()
        table = board.table

        board.check_access(self.user)

        popup = caller != 'board'

        if search.find('IP Address') != -1:
            try:
                sql = table.select()\
                           .where(table.c.ip == misc.dot_to_dec(text))
            except ValueError:
                raise WakaError('Please enter a valid IP.')
            search_type = 'IP'
        elif search.find('Text String') != -1:
            sql = table.select().where(table.c.comment.like('%'+text+'%'))
            search_type = 'text string'
        elif search.find('Author') != -1:
            sql = table.select().where(or_(table.c.name.like('%'+text+'%'),
                table.c.trip.like('%'+text+'%')))
            search_type = 'author'
        else:
            sql = table.select().where(table.c.num == text)
            search_type = 'ID'

        if search_type != 'ID':
            page = model.Page(sql, self.page, self.perpage)
            rowcount = page.total_entries
            total_pages = page.total_pages
            posts = page.rows
            if not posts:
                raise WakaError("No posts found for %s %s" % (search_type, text))
        else:
            rowcount = total_pages = 1
            row = session.execute(sql).fetchone()
            if not row:
                raise WakaError("Post not found. (It may have just been"
                                " deleted.)")
            posts = [row]


        inputs = [
            {'name': 'board', 'value': board.name},
            {'name' : 'task', 'value' : 'searchposts'},
            {'name' : 'text', 'value' : text},
            {'name': 'caller', 'value': caller},
            {'name' : 'search', 'value': search}
        ]

        rooturl = misc.make_script_url(task='searchposts', board=board.name,
            caller=caller, search=search, text=text, _amp=True)

        Template.__init__(self, 'post_search', num=id,
                          posts=posts, search=search, text=text,
                          inputs=inputs, number_of_pages=total_pages,
                          rooturl=rooturl, rowcount=rowcount, popup=popup)
开发者ID:mouhtasi,项目名称:wakarimasen,代码行数:60,代码来源:staff_interface.py

示例3: make_edit_staff_window

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_edit_staff_window(self, username):
        boards = interboard.get_all_boards()
        edited_user = staff.StaffMember.get(username)

        for board in boards:
            if board in edited_user.reign:
                board["underpower"] = True

        Template.__init__(self, "staff_edit_template", user_to_edit=username, boards=boards)
开发者ID:dequis,项目名称:wakarimasen,代码行数:11,代码来源:staff_interface.py

示例4: __init__

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def __init__(self, cookie, board=None, dest=None, page=None, perpage=50, **kwargs):
        try:
            self.user = staff.StaffMember.get_from_cookie(cookie)
        except staff.LoginError:
            Template.__init__(self, "admin_login_template", login_task=dest)
            return
        if not dest:
            dest = HOME_PANEL

        self.admin = cookie

        # TODO: Check if mod is banned.
        if not page:
            if dest in (HOME_PANEL, TRASH_PANEL):
                # Adjust for different pagination scheme. (Blame Wakaba.)
                page = 0
            else:
                page = 1
        if not str(perpage).isdigit():
            perpage = 50

        # The page attribute is not always a pure integer (thread pages).
        if str(page).isdigit():
            page = int(page)
        self.page = page
        self.perpage = int(perpage)
        self.board = local.environ["waka.board"]

        if dest not in INTERFACE_MAPPING:
            dest = HOME_PANEL

        INTERFACE_MAPPING[dest](self, **kwargs)

        # Convert user reign list into a list of dictionaries, for
        # templating.
        reign = []
        if self.user.account == staff.MODERATOR:
            reign = [{"board_entry": entry} for entry in self.user.reign]
        else:
            if self.board:
                reign = interboard.get_all_boards(check_board_name=self.board.name)
            else:
                reign = interboard.get_all_boards()

        # Set global form variables.
        Template.update_parameters(
            self,
            username=self.user.username,
            type=self.user.account,
            admin=cookie,
            boards_select=reign,
            boards=reign,
            page=self.page,
            perpage=self.perpage,
        )
开发者ID:dequis,项目名称:wakarimasen,代码行数:57,代码来源:staff_interface.py

示例5: make_admin_spam_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_spam_panel(self):
        # TODO: Paginate this, too.
        spam_list = []
        for filename in config.SPAM_FILES:
            with open(filename, "r") as f:
                spam_list.extend([str_format.clean_string(l) for l in f])

        spamlines = len(spam_list)
        spam = "".join(spam_list)

        Template.__init__(self, "spam_panel_template", spam=spam, spamlines=spamlines)
开发者ID:dequis,项目名称:wakarimasen,代码行数:13,代码来源:staff_interface.py

示例6: __init__

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def __init__(self):
	Template.__init__(self,
			  [{"class" : Getstatic, "match" : "getstatic CRunTime/memory [I"},
			   {"class" : Iload},
			   {"class" : Iconst},
			   {"class" : Iushr},
			   {"optional-class" : Iconst},
			   {"optional-class" : Iadd},
			   {"class" : Iaload},
			   {"class" : Istore},
			   ]
			  )
开发者ID:NoamSheffer,项目名称:WazeWP7,代码行数:14,代码来源:memory-getstatic.py

示例7: make_admin_ban_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_ban_panel(self, ip=""):
        session = model.Session()
        table = model.admin

        sql = select(
            [
                model.activity.c.username,
                table.c.num,
                table.c.type,
                table.c.comment,
                table.c.ival1,
                table.c.ival2,
                table.c.sval1,
                table.c.total,
                table.c.expiration,
            ],
            from_obj=[
                table.outerjoin(
                    model.activity,
                    and_(table.c.num == model.activity.c.admin_id, table.c.type == model.activity.c.action),
                )
            ],
        ).order_by(table.c.type.asc(), table.c.num.asc())

        # TODO: We should be paginating, but the page needs to be
        # adjusted first.
        # res = model.Page(sql, self.page, self.perpage)

        query = session.execute(sql)
        bans = [dict(row.items()) for row in query]

        rowtype = 1
        prevtype = ""
        for row in bans:
            prevtype = row
            if prevtype != row["type"]:
                row["divider"] = 1

            # Alternate between values 1 and 2.
            rowtype ^= 0x3
            row["rowtype"] = rowtype

            if row["expiration"]:
                row["expirehuman"] = misc.make_date(row["expiration"])
            else:
                row["expirehuman"] = "Never"

            if row["total"] == "yes":
                row["browsingban"] = "No"
            else:
                row["browsingban"] = "Yes"

        Template.__init__(self, "ban_panel_template", bans=bans, ip=ip)
开发者ID:dequis,项目名称:wakarimasen,代码行数:55,代码来源:staff_interface.py

示例8: make_admin_home_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_home_panel(self):
        # Update perpage attribute: it is determined here by board options.
        board = self.board
        self.perpage = board.options['IMAGES_PER_PAGE']

        # Get reports.
        reports = board.get_local_reports()

        # Send to Template initializer.
        kwargs = {}
        threads = []

        if str(self.page).startswith('t'):
            self.page = self.page[1:]
            posts = board.get_thread_posts(self.page)
            threads.append({'posts' : posts})
            kwargs = {'lockedthread' : posts[0].locked,
                      'parent' : self.page,
                      'thread' : self.page}
        else:
            # Grab count of all threads.
            table = board.table
            session = model.Session()
            sql = select([func.count()], table.c.parent == 0)
            thread_count = session.execute(sql).fetchone()[0]
            total = (thread_count + self.perpage - 1) / self.perpage

            if total <= self.page and total > 0:
                # Set page number to last page if exceeding total.
                # Pages are 0-indexed.
                self.page = total - 1
            # Get partial board posts.
            pagethreads = board.get_some_threads(self.page)
            (pages, prevpage, nextpage)\
                = board.get_board_page_data(self.page, total,
                                            admin_page='mpanel')
            threads = board.parse_page_threads(pagethreads)
            kwargs = {'pages' : pages,
                      'prevpage' : prevpage,
                      'nextpage' : nextpage}

        Template.__init__(self, 'post_panel_template', 
                          postform=board.options['ALLOW_TEXTONLY'] or
                                   board.options['ALLOW_IMAGES'],
                          image_inp=board.options['ALLOW_IMAGES'],
                          threads=threads,
                          reportedposts=reports,
                          **kwargs)
开发者ID:mouhtasi,项目名称:wakarimasen,代码行数:50,代码来源:staff_interface.py

示例9: make_admin_report_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_report_panel(self, sortby="date", order="desc"):
        sortby_type = sortby
        sortby_dir = order

        table = model.report
        sql = table.select()

        # Enforce limited moderation reign.
        if self.user.account == staff.MODERATOR:
            sql = sql.where(table.c.board.in_(self.user.reign))

        # Determine order.
        if sortby_type in ("board", "postnum", "date"):
            try:
                column = getattr(table.c, sortby_type)
            except AttributeError:
                raise WakaError("Sort-by column is absent from table.")
            sort = column.desc
            if sortby_dir == "asc":
                sort = column.asc
            sql = sql.order_by(sort(), table.c.date.desc())
        else:
            sql = sql.order_by(table.c.date.desc())

        # Paginate.
        res = model.Page(sql, self.page, self.perpage)

        # Hidden input fields.
        inputs = [
            {"name": "task", "value": "reports"},
            {"name": "order", "value": sortby_dir},
            {"name": "sortby", "value": sortby_type},
        ]

        rooturl = misc.make_script_url(task="reports", sortby=sortby_type, order=sortby_dir, _amp=True)

        Template.__init__(
            self,
            "report_panel_template",
            reports=res.rows,
            sortby=sortby_type,
            order=sortby_dir,
            number_of_pages=res.total_pages,
            rowcount=res.total_entries,
            inputs=inputs,
            rooturl=rooturl,
        )
开发者ID:dequis,项目名称:wakarimasen,代码行数:49,代码来源:staff_interface.py

示例10: make_admin_ban_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_ban_panel(self, ip=''):
        session = model.Session()
        table = model.admin

        sql = select([model.activity.c.username,
                      table.c.num,
                      table.c.type,
                      table.c.comment,
                      table.c.ival1,
                      table.c.ival2,
                      table.c.sval1,
                      table.c.total,
                      table.c.expiration],
            from_obj=[table.outerjoin(model.activity,
            and_(table.c.num == model.activity.c.admin_id,
            table.c.type == model.activity.c.action))])\
            .order_by(table.c.type.asc(), table.c.num.asc())

        # TODO: We should be paginating, but the page needs to be
        # adjusted first.
        # res = model.Page(sql, self.page, self.perpage)

        query = session.execute(sql)
        bans = [dict(row.items()) for row in query]

        rowtype = 1
        prevtype = ''
        for row in bans:
            prevtype = row
            if prevtype != row['type']:
                row['divider'] = 1

            # Alternate between values 1 and 2.
            rowtype ^= 0x3
            row['rowtype'] = rowtype

            if row['expiration']:
                row['expirehuman'] = misc.make_date(row['expiration'])
            else:
                row['expirehuman'] = 'Never'

            if row['total'] == 'yes':
                row['browsingban'] = 'No'
            else:
                row['browsingban'] = 'Yes'

        Template.__init__(self, 'ban_panel_template', bans=bans, ip=ip)
开发者ID:mouhtasi,项目名称:wakarimasen,代码行数:49,代码来源:staff_interface.py

示例11: make_admin_script_security_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_script_security_panel(self):
        session = model.Session()
        table = model.passprompt
        rows = session.execute(table.select())

        now = time.time()

        entries = []
        for row in rows:
            row = dict(row)
            if row["passfail"]:
                row["expiration"] = config.PASSFAIL_ROLLBACK - now + row["timestamp"]
            else:
                row["expiration"] = config.PASSPROMPT_EXPIRE_TO_FAILURE - now + row["timestamp"]
            entries.append(row)

        Template.__init__(self, "script_security_panel", entries=entries)
开发者ID:dequis,项目名称:wakarimasen,代码行数:19,代码来源:staff_interface.py

示例12: make_ban_edit_popup

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_ban_edit_popup(self, num):
        session = model.Session()
        table = model.admin
        sql = table.select().where(table.c.num == num)
        row = session.execute(sql).fetchone()

        if row.expiration:
            expiration = datetime.utcfromtimestamp(row.expiration)
        else:
            expiration = datetime.utcnow()

        Template.__init__(self, 'edit_window', hash=[row],
                          year=expiration.year,
                          month=expiration.month,
                          day=expiration.day,
                          hour=expiration.hour,
                          min=expiration.minute,
                          sec=expiration.second)
开发者ID:mouhtasi,项目名称:wakarimasen,代码行数:20,代码来源:staff_interface.py

示例13: make_admin_report_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_admin_report_panel(self, sortby='date', order='desc'):
        sortby_type = sortby
        sortby_dir = order

        session = model.Session()
        table = model.report
        sql = table.select()

        # Enforce limited moderation reign.
        if self.user.account == staff.MODERATOR:
            sql = sql.where(table.c.board.in_(self.user.reign))

        # Determine order.
        if sortby_type in ('board', 'postnum', 'date'):
            try:
                column = getattr(table.c, sortby_type)
            except AttributeError:
                raise WakaError('Sort-by column is absent from table.')
            sort = column.desc
            if sortby_dir == 'asc':
                sort = column.asc
            sql = sql.order_by(sort(), table.c.date.desc())
        else:
            sql = sql.order_by(table.c.date.desc())

        # Paginate.
        res = model.Page(sql, self.page, self.perpage)

        # Hidden input fields.
        inputs = [{'name' : 'task', 'value' : 'reports'},
                  {'name' : 'order', 'value' : sortby_dir},
                  {'name' : 'sortby', 'value' : sortby_type}]

        rooturl = misc.make_script_url(task='reports', sortby=sortby_type,
            order=sortby_dir, _amp=True)

        Template.__init__(self, 'report_panel_template',
                          reports=res.rows,
                          sortby=sortby_type,
                          order=sortby_dir,
                          number_of_pages=res.total_pages,
                          rowcount=res.total_entries,
                          inputs=inputs,
                          rooturl=rooturl)
开发者ID:mouhtasi,项目名称:wakarimasen,代码行数:46,代码来源:staff_interface.py

示例14: make_sql_interface_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_sql_interface_panel(self, sql='', nuke=''):
        if self.user.account != staff.ADMIN:
            raise WakaError(strings.INUSUFFICENTPRIVLEDGES)

        results = []

        if sql or nuke:
            if nuke != local.environ['waka.board'].options['NUKE_PASS']:
                raise WakaError(strings.WRONGPASS)

            session = model.Session()
            if sql:
                for sql in sql.split('\r\n'):
                    # Execute teh string.
                    try:
                        results.append('>>> ' + sql)
                        row = session.execute(sql)
                    except Exception as errstr:
                        results.append('ERROR: %s' % (errstr))
                    else:
                        try:
                            results.append(str(row.fetchall()))
                        except:
                            results.append('OK')
            else:
                # Remove board table contents and board list entry.
                try:
                    board = local.environ['waka.board']
                    board.table.drop(bind=model.engine, checkfirst=True)
                    del model._boards[board.name]
                    model.common.delete().where(model.common.c.board \
                                                == board.name)
                except Exception as errstr:
                    results.append('ERROR %s' % (errstr))
                else:
                    results.append('Comment table dropped. You should '
                                   'delete/move the board folder now.')
        else:
            results.append('Leave textarea blank to delete the board.\n\n'
                           '(It is recommended that you disable site access '
                           'while entering SQL or deleting boards.)')

        Template.__init__(self, 'sql_interface_template',
                          results='<br />'.join(results))
开发者ID:mouhtasi,项目名称:wakarimasen,代码行数:46,代码来源:staff_interface.py

示例15: make_sql_interface_panel

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import __init__ [as 别名]
    def make_sql_interface_panel(self, sql="", nuke=""):
        if self.user.account != staff.ADMIN:
            raise WakaError(strings.INSUFFICIENTPRIVILEGES)

        results = []

        if sql or nuke:
            if nuke != local.environ["waka.board"].options["NUKE_PASS"]:
                raise WakaError(strings.WRONGPASS)

            session = model.Session()
            if sql:
                for sql in sql.split("\r\n"):
                    # Execute teh string.
                    try:
                        results.append(">>> " + sql)
                        row = session.execute(sql)
                    except Exception as errstr:
                        results.append("ERROR: %s" % (errstr))
                    else:
                        try:
                            results.append(str(row.fetchall()))
                        except:
                            results.append("OK")
            else:
                # Remove board table contents and board list entry.
                try:
                    board = local.environ["waka.board"]
                    board.table.drop(bind=model.engine, checkfirst=True)
                    del model._boards[board.name]
                    model.common.delete().where(model.common.c.board == board.name)
                except Exception as errstr:
                    results.append("ERROR %s" % (errstr))
                else:
                    results.append("Comment table dropped. You should " "delete/move the board folder now.")
        else:
            results.append(
                "Leave textarea blank to delete the board.\n\n"
                "(It is recommended that you disable site access "
                "while entering SQL or deleting boards.)"
            )

        Template.__init__(self, "sql_interface_template", results="<br />".join(results))
开发者ID:dequis,项目名称:wakarimasen,代码行数:45,代码来源:staff_interface.py


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