2016-06-02 7 views
0

enter code here dir (sttachments) wird den folgenden Wert geben.Anhänge in Redmine Python Rest API

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

Aber ich kann nicht in der Lage, die container_id von Anlagen zu lesen, aufgrund dieses ich nicht in der Lage kann meine Anhänge mit Ausgabe abzubilden.

Wie die container_id von Anlagen zu lesen und wie die Anlagen zur Karte mit Ausgabe

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 

Der obige Code gibt folgendes Ergebnis

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)})] 

Die zweite Liste mit gleichen Daten wiederholt wird.

EDIT ONE

ich hier durch den Screenshot von Attachments Tabelle anhängen, hier container_id mit Fragen Nummer zugeordnet, so dass ich möchte eine Liste vorbereitet, basierend auf Ausgabe mit Anhängen,

Zum Beispiel Problem Nr. 1 dh container_id 1 hat zwei Anhänge, dh ID 1 und 4, also muss ich eine Liste vorbereiten [(0,0, {Dateiname: 'vignesh.png'}), (0,0, {Dateiname: 'Seite. png '})], so dass Nummer 1 zwei Probleme hat, die als Liste erstellt werden sollten.

+0

Was meinst du mit „die Anlagen mit der Ausgabe der Karte“? Woher kommt "id.attachments"? Bitte posten Sie den gesamten Code. –

+0

Ich poste den ganzen Code: - Mr Tepkeev –

+0

Danke, aber ich sehe immer noch nicht das Problem, können Sie bitte erklären, was Sie versuchen zu erreichen? Was meinst du mit "Wie lese ich die container_id von Anhängen und wie man die Anhänge mit dem Problem abbildet". –

Antwort

1

So weit ich verstanden habe, ist das Problem die wiederholten Daten, aber es hat nichts mit Python-Redmine oder Redmines REST API zu tun. Das Problem tritt auf, weil Ihre att_list = [] auf Modulebene definiert ist, wenn Sie es innerhalb der ersten for() Schleife definieren dann sollte alles wie erwartet, z.B .:

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 
+0

Danke, ich vermasselt mit Code –