def get(self, request, *args, **kwargs): # files = os.listdir(settings.EPUB_ROOT) # downloads = [] # for f in sorted(files): # ext = os.path.splitext(f)[1] # if ext == '.epub' or ext == '.zip': # # the download link is going to be EPUB_URL + filename # filename = os.path.basename(f) # link = "{0}{1}".format(settings.EPUB_URL, filename) # label = "" # if ext == '.epub': # # assuming the filenames are all like: # # epub30-test-0220-20131016.epub # # chop off the first 12 and the last 14 to get the number, e.g. 0220. # # this matches what is usually in the publication title and what is shown to the user in the test form # label = "Document {0}".format(f[12:len(f)-14]) # else: # label = "All Testsuite Documents (zip)" # dl = {"label": label, "link": link} # downloads.append(dl) downloads = [] epubs = helper_functions.get_epubs_from_latest_testsuites() for epub in epubs: dl = {"label": epub.name, "link": "{0}{1}".format(settings.EPUB_URL, os.path.basename(epub.source))} downloads.append(dl) dl = {"label": "All Testsuite Documents (zip)", "link": "{0}TestSuiteDocuments.zip".format(settings.EPUB_URL)} downloads.append(dl) return render(request, self.template_name, {'downloads': downloads})
def gen_testsuite_xml(request, *args, **kwargs): doc = etree.Element("testsuite") doc.attrib["date"] = datetime.utcnow().strftime("%Y-%m-%d") epubs = helper_functions.get_epubs_from_latest_testsuites() for epub in epubs: item = etree.SubElement(doc, "epub") item.attrib["src"] = epub.source item.attrib["name"] = epub.name if epub.desc != None: item.attrib["desc"] = "epub.desc" xmlstr = etree.tostring(doc, pretty_print=True, encoding="utf-8") return HttpResponse(xmlstr, mimetype="text")
def get_unanswered_flagged_items_sorted_by_epub(result_set): "get unanswered flagged item ids, organized by the EPUB file they appear in" tests = result_set.get_unanswered_flagged_tests() unique_epubs = helper_functions.get_epubs_from_latest_testsuites() tests_by_epub = [] for epub in unique_epubs: print "epub: {0}".format(epub.id) for epub in unique_epubs: testdata = [] for t in tests: if t.get_parent_epub_category() == epub: print "match!" testdata.append({"id": t.testid, "parentid": t.get_top_level_parent_category().id}) else: print t.get_parent_epub_category().id if len(testdata) > 0: tests_by_epub.append({"epub_name": epub.name, "epub_url": "{0}{1}".format(settings.EPUB_URL, os.path.basename(epub.source)), "tests": testdata}) return tests_by_epub