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


Python Template.data方法代码示例

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


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

示例1: application

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import data [as 别名]
def application(environ, start_response):

	connector = MySQLdb.connect(host="192.168.30.10",
                                    db="personal",
                                    user="vagrant",
                                    passwd="vagrant",
                                    charset="utf8")
	cursor = connector.cursor()
	cursor.execute("SELECT * FROM info")
	result = cursor.fetchall()

	start_response('200 OK', [('Content-Type', 'text/html')])

	tpl = Template(file="/var/www/wsgi/test/tpl/result.tpl")
	tpl.data = []

	for row in result:
		if str(row[3]) == "M":
			tpl.data.append((str(row[0]), str(row[2]), "Man", str(row[4]), str(row[5])))
		else:
			tpl.data.append((str(row[0]), str(row[2]), "Woman", str(row[4]), str(row[5])))
			
	cursor.close()
	connector.close()

	return tpl.respond().encode('utf-8')
开发者ID:kakky0312,项目名称:test-scripts,代码行数:28,代码来源:load_db.py

示例2: write

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import data [as 别名]
  def write(self):
    t = Template(file='templates/new.tmpl')

    t.message = []
    t.goodmessage = ''
    t.showform = True

    if self._dic and self._dic.has_key('submit'):
      t.data = { 'day':self._dic['day'], 'month':self._dic['month'], 'year':self._dic['year'], 'start':self._dic['start'], 'end':self._dic['end'], 'description':self._dic['description'] }

      day = int(self._dic['day'])
      month = int(self._dic['month'])
      year = int(self._dic['year'])

      (sh, sm) = extractTuple(self._dic['start'])
      (eh, em) = extractTuple(self._dic['end'])

      desc = self._dic['description']

      ok = True
      if sh == None:
        t.message.append('Ungültige Startzeit')
        ok = False

      if eh == None:
        t.message.append('Ungültige Endzeit')
        ok = False

      if ok:
        if sh > eh  or  sh == eh and sm >= em:
          t.message.append('Startzeit liegt nach Endzeit')
          ok = False

      if not (1 <= day <= 31 ):
        t.message.append('Ung&uuml;ltiger Tag')
        ok = False

      if not ( 1 <= month <= 12 ):
        t.message.append('Ung&uuml;ltiger Monat')
        ok = False

      if not ( 2005 <= year <= 2100 ):
        t.message.append('Ung&uuml;ltiges Jahr')
        ok = False

      if ok:
        when = datetime(year, month, day, eh, em, 0)
        if when < datetime.now():
          t.message.append('Termin liegt in der Vergangenheit')
          ok = False

      if ok:
        start = datetime(year, month, day, sh, sm, 0)
        end = datetime(year, month, day, eh, em, 0)
        self._page._db.newReservation(self._page._login.getOid(),
          start,
          end,
          desc)
        t.goodmessage = "Der Termin wurde reserviert"
        t.showform = False

    else:
      t.data = { 'day':datetime.now().day, 'month':datetime.now().month, 'year':datetime.now().year, 'start':'16:00', 'end':'22:00', 'description':'' }

    return t
开发者ID:pmoor,项目名称:pizza,代码行数:67,代码来源:EditModule.py

示例3: Template

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import data [as 别名]
            FirstAnchor = ''

        subcname = query['Container'][0]
        cname = subcname.split('/')[0]
        handler.send_response(200)
        handler.send_header('Content-Type', 'text/html; charset=UTF-8')
        handler.end_headers()
        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'npl.tmpl'))
        t.folder = folder
        t.status = status
        t.tivo_mak = tivo_mak
        t.togo_path = togo_path
        t.tivos = handler.tivos
        t.tivoIP = tivoIP
        t.container = cname
        t.data = data
        t.unquote = unquote
        t.len = len
        t.TotalItems = int(TotalItems)
        t.ItemStart = int(ItemStart)
        t.ItemCount = int(ItemCount)
        t.FirstAnchor = quote(FirstAnchor)
        t.shows_per_page = shows_per_page
        t.redirect = quote(unquote_plus(handler.path).split('/')[1])
        handler.wfile.write(unicode(t).encode('utf-8'))

    def get_tivo_file(self, url, mak, tivoIP, outfile):
        #global status
        cj = cookielib.LWPCookieJar()

        r=urllib2.Request(url)
开发者ID:armooo,项目名称:pytivo,代码行数:33,代码来源:admin.py

示例4: NPL

# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import data [as 别名]
    def NPL(handler, query):
        """
        ToGo.NPL returns an html page displaying the now playing list (NPL)
        from a particular TiVo device.
        The query may specify:
        - TiVo: the IPv4 address of the TiVo whose NPL is to be retrieved
        - ItemCount: the number of shows/folders to put on the page (default: 50, max: 50)
        - AnchorItem: the url identifying the 1st item in the retrieved list (default 1st item in folder)
        - AnchorOffset: the offset from the AnchorItem to start the retrieval from (default 0)
        - SortOrder:
        - Recurse:
        """

        def getint(thing):
            try:
                result = int(thing)
            except:                             # pylint: disable=bare-except
                result = 0
            return result


        shows_per_page = 50 # Change this to alter the number of shows returned (max is 50)
        if 'ItemCount' in query:
            shows_per_page = int(query['ItemCount'][0])

        if shows_per_page > 50:
            shows_per_page = 50

        folder = ''
        FirstAnchor = ''
        has_tivodecode = bool(config.get_bin('tivodecode'))
        has_tivolibre = bool(config.get_bin('tivolibre'))

        if 'TiVo' in query:
            tivoIP = query['TiVo'][0]
            try:
                tsn = config.tivos_by_ip(tivoIP)
                attrs = config.tivos[tsn]
                tivo_name = attrs.get('name', tivoIP)
                tivo_mak = config.get_tsn('tivo_mak', tsn)
            except config.Error as e:
                logger.error('NPL: %s', e)
                t = Template(ERROR_TEMPLATE)
                t.e = e
                t.additional_info = 'Your browser may have cached an old page'
                handler.send_html(str(t))
                return

            protocol = attrs.get('protocol', 'https')
            ip_port = '%s:%d' % (tivoIP, attrs.get('port', 443))
            path = attrs.get('path', DEFPATH)
            baseurl = '%s://%s%s' % (protocol, ip_port, path)
            theurl = baseurl
            if 'Folder' in query:
                folder = query['Folder'][0]
                theurl = urljoin(theurl, folder)
            theurl += '&ItemCount=%d' % shows_per_page
            if 'AnchorItem' in query:
                theurl += '&AnchorItem=' + quote(query['AnchorItem'][0])
            if 'AnchorOffset' in query:
                theurl += '&AnchorOffset=' + query['AnchorOffset'][0]
            if 'SortOrder' in query:
                theurl += '&SortOrder=' + query['SortOrder'][0]
            if 'Recurse' in query:
                theurl += '&Recurse=' + query['Recurse'][0]

            if (theurl not in tivo_cache or
                    (time.time() - tivo_cache[theurl]['thepage_time']) >= 60):
                # if page is not cached or old then retrieve it
                auth_handler.add_password('TiVo DVR', ip_port, 'tivo', tivo_mak)
                logger.debug('NPL: (1) add password for TiVo DVR netloc: %s', ip_port)
                try:
                    logger.debug("NPL.theurl: %s", theurl)
                    with tivo_open(theurl) as page:
                        tivo_cache[theurl] = {'thepage': minidom.parse(page),
                                              'thepage_time': time.time()}
                except IOError as e:
                    handler.redir(UNABLE % (tivoIP, html.escape(str(e))), 10)
                    return

            xmldoc = tivo_cache[theurl]['thepage']
            items = xmldoc.getElementsByTagName('Item')

            TotalItems = tag_data(xmldoc, 'TiVoContainer/Details/TotalItems')
            ItemStart = tag_data(xmldoc, 'TiVoContainer/ItemStart')
            ItemCount = tag_data(xmldoc, 'TiVoContainer/ItemCount')
            title = tag_data(xmldoc, 'TiVoContainer/Details/Title')
            if items:
                FirstAnchor = tag_data(items[0], 'Links/Content/Url')

            data = []
            for item in items:
                entry = {}
                for tag in ('CopyProtected', 'ContentType'):
                    value = tag_data(item, 'Details/' + tag)
                    if value:
                        entry[tag] = value
                if entry['ContentType'].startswith('x-tivo-container'):
                    entry['Url'] = tag_data(item, 'Links/Content/Url')
                    entry['Title'] = tag_data(item, 'Details/Title')
#.........这里部分代码省略.........
开发者ID:mlippert,项目名称:pytivo,代码行数:103,代码来源:togo.py


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