Open Farkal opened 8 years ago
I have made a function to delete the files:
def delete_file(self, filename):
page = self.browser.open(str(self.url + 'projects/' + self.project_id + '/files'))
tree = lxml.html.fromstring(page.get_data())
meta_csrftoken = tree.xpath("//meta[@name='csrf-token']/@content")[0]
for link in self.browser.links(text_regex=filename):
file_id = link.url.split("/")[-2]
url = self.url + 'attachments/' + file_id
print "Deleting", url
data = urllib.urlencode({u'_method': 'delete', u'authenticity_token': meta_csrftoken})
self.browser.open(url, data)
print "File deleted"
But you need to add this imports
import urllib
import lxml.html
I need to delete files in redmine Files module.
I find this code but it's in ruby: