本文整理汇总了Python中trac.env.Environment.create_attachment方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.create_attachment方法的具体用法?Python Environment.create_attachment怎么用?Python Environment.create_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.env.Environment
的用法示例。
在下文中一共展示了Environment.create_attachment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TracDatabase
# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import create_attachment [as 别名]
#.........这里部分代码省略.........
if field == 'milestone':
field = 'product_version'
print " * adding ticket change \"%s\": \"%s\" -> \"%s\" (%s)" % (field, oldvalue[0:20], newvalue[0:20], time)
c = self.db().cursor()
#workaround 'unique' ticket_change warnings POTENTIALLY BAD IDEA ALERT
sql = "SELECT * FROM ticket_change WHERE field='%s' AND ticket=%s AND time=%s" % (field, ticket, self.convertTime(time))
c.execute(sql)
fixtime = c.fetchall()
if fixtime:
time = time + 1
c.execute("""INSERT OR IGNORE INTO ticket_change (ticket, time, author, field, oldvalue, newvalue)
VALUES (%s, %s, %s, %s, %s, %s)""",
(ticket, self.convertTime(time), author, field, oldvalue.encode('utf-8'), newvalue.encode('utf-8')))
self.db().commit()
#workaround 'unique' ticket warnings POTENTIALLY BAD IDEA ALERT
sql = "SELECT * FROM ticket WHERE %s='%s' AND id=%s AND time=%s" % (field, newvalue, ticket, self.convertTime(time))
c.execute(sql)
fixtime = c.fetchall()
if fixtime:
time = time + 1
# Now actually change the ticket because the ticket wont update itself!
sql = "UPDATE ticket SET %s='%s' WHERE id=%s" % (field, newvalue, ticket)
c.execute(sql)
self.db().commit()
# unused in 1.2
def addAttachment(self, id, attachment, description, author):
print 'inserting attachment for ticket %s -- %s' % (id, description)
attachment.filename = attachment.filename.encode('utf-8')
self.env.create_attachment(self.db(), 'ticket', str(id), attachment, description.encode('utf-8'),
author, 'unknown')
def getLoginName(self, cursor, userid):
if userid not in self.loginNameCache and userid is not None and userid != '':
cursor.execute("SELECT username,email,realname,last_visit FROM mantis_user_table WHERE id = %i" % int(userid))
result = cursor.fetchall()
if result:
loginName = result[0]['username']
print 'Adding user %s to sessions table' % loginName
c = self.db().cursor()
# check if user is already in the sessions table
c.execute("SELECT sid FROM session WHERE sid = '%s'" % result[0]['username'].encode('utf-8'))
r = c.fetchall()
# if there was no user sid in the database already
if not r:
sessionSql = """INSERT INTO session
(sid, authenticated, last_visit)
VALUES (%s, %s, %s)""", (result[0]['username'].encode('utf-8'), '1', self.convertTime(result[0]['last_visit']))
# pre-populate the session table and the realname/email table with user data
try:
c.execute(sessionSql)
except:
print 'failed executing sql: '
print sessionSql
print 'could not insert %s into sessions table: sql error ' % (loginName)
self.db().commit()
# insert the user's real name into session attribute table
try: