Пример #1
0
    def sources_from_args(cls, request, asset=None):
        '''
        utilized by add_view to help create a new asset
        returns a dict of sources represented in GET/POST args
        '''
        sources = {}
        args = request.POST if request.method == 'POST' else request.GET
        for key, val in args.items():
            if cls.good_asset_arg(key) and val != '' and len(val) < 4096:
                source = Source(label=key, url=val)

                # UGLY non-functional programming for url_processing
                if asset:
                    source.asset = asset

                src_metadata = args.get(key + '-metadata', None)
                cls.add_metadata(source, src_metadata)
                sources[key] = source

        # iterate the primary labels in order of priority
        # pickup the first matching one & use that
        for lbl in Asset.primary_labels:
            if lbl in sources:
                sources[lbl].primary = True
                return sources

        # no primary source found, return no sources
        return {}
Пример #2
0
    def sources_from_args(cls, request, asset=None):
        '''
        utilized by add_view to help create a new asset
        returns a dict of sources represented in GET/POST args
        '''
        sources = {}
        args = request.POST if request.method == 'POST' else request.GET
        for key, val in args.items():
            if cls.good_asset_arg(key) and val != '' and len(val) < 4096:
                source = Source(label=key, url=val)

                # UGLY non-functional programming for url_processing
                if asset:
                    source.asset = asset

                src_metadata = args.get(key + '-metadata', None)
                cls.add_metadata(source, src_metadata)
                sources[key] = source

        # iterate the primary labels in order of priority
        # pickup the first matching one & use that
        for lbl in Asset.primary_labels:
            if lbl in sources:
                sources[lbl].primary = True
                return sources

        # no primary source found, return no sources
        return {}
Пример #3
0
    def handle(self, *app_labels, **options):
        assets = Asset.objects.filter(metadata_blob__contains='artstor-id')
        for asset in assets:
            fpx_id = asset.metadata()['artstor-id'][0]

            old_image_fpx = Source.objects.get(asset=asset,
                                               label='image_fpx')
            old_image_fpx.primary = False
            old_image_fpx.label = "deprecated_image_fpx"
            old_image_fpx.save()

            source = Source(asset=asset,
                            label='image_fpxid',
                            url=fpx_id,
                            height=old_image_fpx.height,
                            width=old_image_fpx.width,
                            primary=True,
                            media_type='fpx',
                            size=0)

            source.save()

            print "%s [%s]: added image_fpx source %s" % (asset.title,
                                                          asset.id,
                                                          fpx_id)
Пример #4
0
    def test_migrate_artstor_assets(self):
        course = Course.objects.get(id=1)
        author = User.objects.get(username='******')

        asset = Asset(metadata_blob='{"artstor-id": ["SKIDMORE_10312643267"]}',
                      title="Test Asset",
                      active=True,
                      course=course,
                      author=author)
        asset.save()

        old_image_fpx = Source(asset=asset,
                               label='image_fpx',
                               url="the old image fpx url",
                               width=1024,
                               height=768,
                               primary=True,
                               media_type='fpx')
        old_image_fpx.save()
        self.assertTrue(old_image_fpx.primary)

        management.call_command("migrate_artstor_assets")

        s = Source.objects.filter(asset=asset, label='image_fpx')
        self.assertEquals(len(s), 0)

        s = Source.objects.get(asset=asset, label='deprecated_image_fpx')
        self.assertFalse(s.primary)

        s = Source.objects.get(asset=asset, label='image_fpxid')
        self.assertEquals(s.label, "image_fpxid")
        self.assertEquals(s.url, "SKIDMORE_10312643267")
        self.assertTrue(s.primary)
        self.assertEquals(s.width, 1024)
        self.assertEquals(s.height, 768)
Пример #5
0
    def import_course_data(self, json_file, course):
        raw_data = open(json_file)
        json_data = json.load(raw_data)

        for asset_data in json_data['asset_set']:
            # Create asset
            author = User.objects.get(
                username=asset_data["author"]["username"])
            asset = Asset(author=author,
                          title=asset_data["title"],
                          course=course)

            asset.metadata_blob = asset_data["metadata_blob"]
            asset.save()

            # Add sources
            for key, value in asset_data["sources"].items():
                source_data = asset_data["sources"][key]
                source = Source(asset=asset,
                                label=source_data["label"],
                                url=source_data["url"],
                                primary=source_data["primary"],
                                media_type=source_data["media_type"],
                                size=source_data["size"],
                                height=source_data["height"],
                                width=source_data["width"])
                source.save()

            # Recreate annotations
            for ann_data in asset_data["annotations"]:
                ann_author = User.objects.get(
                    username=ann_data["author"]["username"])
                if ann_data["is_global_annotation"]:
                    ann = asset.global_annotation(ann_author, True)
                else:
                    ann = SherdNote(asset=asset,
                                    author=ann_author)

                ann.range1 = ann_data["range1"]
                ann.range2 = ann_data["range2"]
                ann.annotation_data = ann_data["annotation_data"]
                ann.title = ann_data["title"]

                tags = ""
                for tag in ann_data["metadata"]["tags"]:
                    tags = tags + "," + tag["name"]
                ann.tags = tags
                ann.body = ann_data["metadata"]["body"]
                ann.save()
Пример #6
0
def sources_from_args(request, asset=None):
    '''
    utilized by add_view to help create a new asset
    returns a dict of sources represented in GET/POST args
    '''
    sources = {}
    args = request.REQUEST
    for key, val in args.items():
        if good_asset_arg(key) and val != '':
            source = Source(label=key, url=val)
            # UGLY non-functional programming for url_processing
            source.request = request
            if asset:
                source.asset = asset
            src_metadata = args.get(key + '-metadata', None)
            if src_metadata:
                # w{width}h{height};{mimetype} (with mimetype and w+h optional)
                the_match = re.match('(w(\d+)h(\d+))?(;(\w+/[\w+]+))?',
                                     src_metadata).groups()
                if the_match[1]:
                    source.width = int(the_match[1])
                    source.height = int(the_match[2])
                if the_match[4]:
                    source.media_type = the_match[4]
            sources[key] = source

    for lbl in Asset.primary_labels:
        if lbl in args:
            sources[lbl].primary = True
            break
    return sources
Пример #7
0
def sources_from_args(request, asset=None):
    '''
    utilized by add_view to help create a new asset
    returns a dict of sources represented in GET/POST args
    '''
    sources = {}
    args = request.REQUEST
    for key, val in args.items():
        if good_asset_arg(key) and val != '':
            source = Source(label=key, url=val)
            # UGLY non-functional programming for url_processing
            source.request = request
            if asset:
                source.asset = asset
            src_metadata = args.get(key + '-metadata', None)
            if src_metadata:
                # w{width}h{height};{mimetype} (with mimetype and w+h optional)
                m = re.match('(w(\d+)h(\d+))?(;(\w+/[\w+]+))?',
                             src_metadata).groups()
                if m[1]:
                    source.width = int(m[1])
                    source.height = int(m[2])
                if m[4]:
                    source.media_type = m[4]
            sources[key] = source

    for lbl in Asset.primary_labels:
        if lbl in args:
            sources[lbl].primary = True
            break
    return sources
Пример #8
0
    def handle(self, *app_labels, **options):
        assets = Asset.objects.filter(metadata_blob__contains='artstor-id')
        for asset in assets:
            fpx_id = asset.metadata()['artstor-id'][0]

            old_image_fpx = Source.objects.get(asset=asset, label='image_fpx')
            old_image_fpx.primary = False
            old_image_fpx.label = "deprecated_image_fpx"
            old_image_fpx.save()

            source = Source(asset=asset,
                            label='image_fpxid',
                            url=fpx_id,
                            height=old_image_fpx.height,
                            width=old_image_fpx.width,
                            primary=True,
                            media_type='fpx',
                            size=0)

            source.save()

            print "%s [%s]: added image_fpx source %s" % (asset.title,
                                                          asset.id, fpx_id)