示例#1
0
    def handle(self, *args, **options):
        print "fetching content from forest..."
        url = "http://wacep2.forest.ccnmtl.columbia.edu/pagetree/export/"
        url = url + "?hierarchy=" + "wacep2.forest.ccnmtl.columbia.edu"
        d = requests.get(url).json()
        print "removing old pagetree hierarchy..."
        Hierarchy.objects.all().delete()
        print "importing the new one..."
        Hierarchy.from_dict(d)
        # override the hierarchy name (since it's coming from forest)
        h = Hierarchy.objects.all()[0]
        h.name = "main"
        h.save()

        print "pulling down uploaded files..."
        base_len = len("http://wacep2.forest.ccnmtl.columbia.edu/uploads/")
        for upload in d.get('resources', []):
            relative_path = upload[base_len:]
            relative_dir = os.path.join(*os.path.split(relative_path)[:-1])
            full_dir = os.path.join(settings.MEDIA_ROOT, relative_dir)
            try:
                os.makedirs(full_dir)
            except OSError:
                pass
            with open(os.path.join(settings.MEDIA_ROOT,
                                   relative_path), "w") as f:
                print "  writing %s to %s" % (upload, relative_path)
                f.write(requests.get(upload).text)
        print "done"
示例#2
0
    def handle(self, *args, **options):
        if not settings.DEBUG:
            print("this should never be run on production")
            return
        if not hasattr(settings, 'PROD_BASE_URL'):
            print("you must set PROD_BASE_URL")
            return
        print("fetching content from prod...")
        url = settings.PROD_BASE_URL + "_pagetree/export/"
        if args:
            url = url + "?hierarchy=" + args[0]
        d = loads(GET(url))
        print("removing old pagetree hierarchy...")
        Hierarchy.objects.all().delete()
        print("importing the new one...")
        Hierarchy.from_dict(d)

        if not hasattr(settings, 'PROD_MEDIA_BASE_URL'):
            print("in order to pull down uploaded files,")
            print("you must set PROD_MEDIA_BASE_URL")

        print("pulling down uploaded files...")
        base_len = len(settings.PROD_MEDIA_BASE_URL)
        for upload in d.get('resources', []):
            relative_path = upload[base_len:]
            relative_dir = os.path.join(*os.path.split(relative_path)[:-1])
            full_dir = os.path.join(settings.MEDIA_ROOT, relative_dir)
            try:
                os.makedirs(full_dir)
            except OSError:
                pass
            with open(os.path.join(settings.MEDIA_ROOT, relative_path),
                      "w") as f:
                print("  writing %s to %s" % (upload, relative_path))
                f.write(GET(upload))
        print("done")
    def handle(self, *args, **options):
        if not settings.DEBUG:
            print "this should never be run on production"
            return
        if not hasattr(settings, 'PROD_BASE_URL'):
            print "you must set PROD_BASE_URL"
            return
        print "fetching content from prod..."
        url = settings.PROD_BASE_URL + "_pagetree/export/"
        if args:
            url = url + "?hierarchy=" + args[0]
        d = loads(GET(url))
        print "removing old pagetree hierarchy..."
        Hierarchy.objects.all().delete()
        print "importing the new one..."
        Hierarchy.from_dict(d)

        if not hasattr(settings, 'PROD_MEDIA_BASE_URL'):
            print "in order to pull down uploaded files,"
            print "you must set PROD_MEDIA_BASE_URL"

        print "pulling down uploaded files..."
        base_len = len(settings.PROD_MEDIA_BASE_URL)
        for upload in d.get('resources', []):
            relative_path = upload[base_len:]
            relative_dir = os.path.join(*os.path.split(relative_path)[:-1])
            full_dir = os.path.join(settings.MEDIA_ROOT, relative_dir)
            try:
                os.makedirs(full_dir)
            except OSError:
                pass
            with open(os.path.join(settings.MEDIA_ROOT,
                                   relative_path), "w") as f:
                print "  writing %s to %s" % (upload, relative_path)
                f.write(GET(upload))
        print "done"
示例#4
0
 def test_edit_form(self):
     h = Hierarchy.from_dict({'name': 'main', 'base_url': ""})
     root = h.get_root()
     d = DashboardInfo.objects.create(dashboard=root, info="")
     f = d.edit_form()
     self.assertTrue(f is not None)
示例#5
0
 def test_edit_form(self):
     h = Hierarchy.from_dict({'name': 'main', 'base_url': ""})
     root = h.get_root()
     sc = SectionCss.objects.create(section_css=root, css_field="")
     self.assertTrue(sc.edit_form() is not None)
示例#6
0
 def test_edit_form(self):
     h = Hierarchy.from_dict({'name': 'main', 'base_url': ""})
     root = h.get_root()
     m = ModuleType.objects.create(module_type=root, info="")
     self.assertTrue(m.edit_form() is not None)
示例#7
0
 def setUp(self):
     self.h = Hierarchy.from_dict({'name': "main", 'base_url': ""})
示例#8
0
 def setUp(self):
     self.h = Hierarchy.from_dict({'name': "main",
                                   'base_url': ""})