【问题标题】:Attachments in Redmine Python Rest APIRedmine Python Rest API 中的附件
【发布时间】:2016-06-02 08:57:17
【问题描述】:

dir(sttachments) 将给出以下值。

[u'author', u'content_type', u'content_url', u'created_on', u'description', u'filename', u'filesize', u'id', u'thumbnail_url']

但我无法读取附件的 container_id,因此我无法映射有问题的附件。

如何读取附件的container_id以及如何映射有问题的附件

    from redmine import Redmine
    conn_red = Redmine('http://localhost:3000', username='admin',   password='admin')
    issue = conn_red.issue.all()
    attachment = {}
    att_list = []
    for id in issue:
       for att in id.attachments:
           attachment['file_name'] = att.content_url
           attachment['created_date'] = att.created_on
           att_list.append((0, 0, attachment))
           print "issue",id.id,"attachments",att.id,"att_list",att_list

上面的代码给出以下结果

issue 7 attachments 5 att_list [(0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)})]
issue 6 attachments 5 att_list [(0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)})]
issue 5 attachments 5 att_list [(0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)})]
issue 4 attachments 5 att_list [(0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)})]
issue 3 attachments 5 att_list [(0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/5/3BasicSkills_Eng.pdf', 'created_date': datetime.datetime(2016, 6, 2, 8, 43, 51)})]
issue 2 attachments 3 att_list [(0, 0, {'file_name': u'http://localhost:3000/attachments/download/3/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 15, 42)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/3/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 15, 42)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/3/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 15, 42)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/3/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 15, 42)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/3/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 15, 42)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/3/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 15, 42)})]
issue 1 attachments 4 att_list [(0, 0, {'file_name': u'http://localhost:3000/attachments/download/4/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 16, 40)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/4/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 16, 40)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/4/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 16, 40)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/4/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 16, 40)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/4/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 16, 40)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/4/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 16, 40)}), (0, 0, {'file_name': u'http://localhost:3000/attachments/download/4/page.png', 'created_date': datetime.datetime(2016, 5, 30, 8, 16, 40)})]

第二个列表使用相同的数据重复。

编辑一个

我这里附上附件表的截图,这里的container_id是和issues编号相关联的,所以我想根据附件的issue准备一个列表,

例如第 1 期即 container_id 1 有两个附件,即 ID 1 和 4,所以我必须准备一个列表 [(0,0,{filename:'vignesh.png'}),(0,0,{ filename:'page.png'})],所以问题 1 有两个问题应该创建为一个列表。

【问题讨论】:

  • “映射有问题的附件”是什么意思? id.attachments 来自哪里?请发布整个代码。
  • 我发布了整个代码:- Tepkeev 先生
  • 谢谢,但我仍然没有看到问题,你能解释一下你想要达到什么目的吗? “如何读取附件的 container_id 以及如何映射有问题的附件”是什么意思。
  • Tepkeev 先生附上表格供您参考

标签: openerp redmine-api python-redmine


【解决方案1】:

据我了解,问题在于重复数据,但这与 Python-Redmine 或 Redmine 的 REST API 无关。出现问题是因为您的 att_list = [] 是在模块级别定义的,如果您在第一个 for() 循环中定义它,那么一切都应该按预期工作,例如:

from redmine import Redmine
conn_red = Redmine('http://localhost:3000', username='admin', password='admin')
issues = conn_red.issue.all()
for issue in issues:
   att_list = []
   for att in issue.attachments:
       attachment = {
           'file_name': att.content_url,
           'created_date': att.created_on
       }
       att_list.append((0, 0, attachment))

   print "issue",issue.id, "att_list", att_list

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多