How to use the template.Template.__init__ function in template

To help you get started, we’ve selected a few template examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dequis / wakarimasen / staff_interface.py View on Github external
def __init__(self, admin, board=None, dest=None, page=None,
                 perpage=50, **kwargs):
        try:
            self.user = staff.check_password(admin)
        except staff.LoginError:
            Template.__init__(self, 'admin_login_template', login_task=dest)
            return
        if not dest:
            dest = HOME_PANEL

        self.admin = admin

        # 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
github dequis / wakarimasen / staff_interface.py View on Github external
def make_enable_staff_window(self, username):
        Template.__init__(self, 'staff_enable_template',
                                user_to_enable=username)
github dequis / wakarimasen / staff_interface.py View on Github external
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)
github dequis / wakarimasen / staff_interface.py View on Github external
if self.board:
            inputs.append({'name' : 'board', 'value' : self.board.name})

        # Apply sorting.
        if sortby_name and hasattr(table.c, sortby_name):
            order_col = getattr(table.c, sortby_name)
            if sortby_dir.lower() == 'asc':
                sort_spec = order_col.asc()
            else:
                sort_spec = order_col.desc()
            sql = sql.order_by(sort_spec)

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

        Template.__init__(self, template_view,
                          user_to_view=user_to_view,
                          entries=res.rows,
                          staff=staff,
                          rowcount=res.total_entries,
                          numberofpages=res.total_pages,
                          view=view,
                          order=sortby_dir,
                          action_name=action_name,
                          content_name=action_content,
                          sortby=sortby_name,
                          number_of_pages=res.total_pages,
                          rooturl=rooturl,
                          inputs=inputs)
github dequis / wakarimasen / staff_interface.py View on Github external
def make_delete_all_window(self, **kwargs):
        Template.__init__(self, 'delete_crap_confirm', **kwargs)
github dequis / wakarimasen / staff_interface.py View on Github external
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))
github dequis / wakarimasen / staff_interface.py View on Github external
# 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)
github dequis / wakarimasen / staff_interface.py View on Github external
def make_del_staff_window(self, username):
        Template.__init__(self, 'staff_delete_template',
                                user_to_delete=username)
github dequis / wakarimasen / staff_interface.py View on Github external
if total &lt;= self.page and total &gt; 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)
github dequis / wakarimasen / staff_interface.py View on Github external
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)