From 294fe654a8f3708204230aa892d1c903c8641096 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 15 Feb 2012 15:05:06 +0530 Subject: [PATCH] migration to next.pad.ma --- padmaTexts/migrations/__init__.py | 0 padmaTexts/migrations/migrate.py | 44 +++++++++++++++++++++++++++ padmaTexts/static/js/views/sidebar.js | 12 ++++++-- padmaTexts/templates/text_embed.html | 2 +- 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 padmaTexts/migrations/__init__.py create mode 100644 padmaTexts/migrations/migrate.py diff --git a/padmaTexts/migrations/__init__.py b/padmaTexts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/padmaTexts/migrations/migrate.py b/padmaTexts/migrations/migrate.py new file mode 100644 index 0000000..74efab5 --- /dev/null +++ b/padmaTexts/migrations/migrate.py @@ -0,0 +1,44 @@ +import urllib2 +import re +from texts.models import * + +NEXT = "http://next.pad.ma/" +OLD = "http://pad.ma/" +IdMapping = {} + + +def getNewUrl(oldUrl): + new = oldUrl.replace(OLD, NEXT) + try: + return urllib2.urlopen(new).url + except: + print "ERROR: " + oldUrl + +def getNewId(oldId): + oldId = oldId.group().replace(OLD, "")[:-1] + print oldId + if oldId in IdMapping: + return IdMapping[oldId] + url = NEXT + oldId + u = urllib2.urlopen(url) + newId = u.url.replace(NEXT, "") + IdMapping[oldId] = newId + return newId + +def replaceUrls(text): + regex = re.compile(r'(http:\/\/pad.ma\/V.*?)[\s\"\<]') + for f in re.findall(regex, text): + newUrl = getNewUrl(f) + print newUrl + text = text.replace(f, newUrl) + return text +# for m in re.findall(regex, text): +# print getNewId(m) + +def doAll(): + for p in PadmaText.objects.all(): + print p.title + newText = replaceUrls(p.html) + p.html = newText + p.save() + diff --git a/padmaTexts/static/js/views/sidebar.js b/padmaTexts/static/js/views/sidebar.js index fbc53ab..d3b440a 100644 --- a/padmaTexts/static/js/views/sidebar.js +++ b/padmaTexts/static/js/views/sidebar.js @@ -13,21 +13,29 @@ $(function() { $(window).resize(resize); }); + function setupPadmaLink(videoObj, data) { var $a = $(data.jq); // $a.data("isDisplayed", false); //FIXME: tc is WRONG!!! - if (!$.inArray(data.linkData.type, ["info", "editor", "tc", "tcRange", "layer"])) { +// if (!$.inArray(data.linkData.type, ["info", "editor", "tc", "tcRange", "layer"])) { +// return false; +// } + + if ($.inArray(data.linkData.type, ["tcRange", 'info']) == -1) { return false; } + + console.log(videoObj); + // console.log(data.linkData); //FIXME: this whole thing is a bit of rubbish, and they should not set type = 'tcRange' if (data.linkData.type == 'info' || data.linkData.type == 'editor' || data.linkData.type == "tc") { data.linkData.tcIn = ms2npt(0); - data.linkData.tcOut = ms2npt(videoObj.video.duration); + data.linkData.tcOut = ms2npt(videoObj.video.duration * 1000); data.linkData.type = "tcRange"; } diff --git a/padmaTexts/templates/text_embed.html b/padmaTexts/templates/text_embed.html index c147137..35736fa 100644 --- a/padmaTexts/templates/text_embed.html +++ b/padmaTexts/templates/text_embed.html @@ -91,7 +91,7 @@ $(function() { - +