def do_import(annotations, gallery, commenter):
    sys.stderr.write("Importing {} images to gallery '{}'\n"
                     .format(len(annotations), gallery.title))

    ndigits = len(str(len(annotations)-1))

    comment_timestamp = timezone.make_aware(datetime(2015, 10, 4, 20, 0),
                                            timezone.get_fixed_timezone(-240))

    for seq, ann in enumerate(annotations):
        sys.stderr.write(ann.fname + "\n")
        img = GalleryImage(gallery      = gallery,
                           sort_order   = seq,
                           date         = ann.date,
                           notes        = ann.desc)
        img.save()

        if ann.photog: img.photographer.set(ann.photog)
        if ann.loc:    img.location.set(ann.loc)
        if ann.people: img.people.set(*ann.people)
        if ann.tags:   img.tags.set(*ann.tags)

        ifile = ImageFile(open(ann.fname, 'rb'))
        img.image.save("I{1:0{0}}.jpg".format(ndigits, seq),
                       ifile)
        img.save()

        if ann.comment:
            comment = GalleryComment(image   = img,
                                     user    = commenter,
                                     date    = comment_timestamp,
                                     comment = ann.comment)
            comment.save()
Exemple #2
0
    def test_gallery_item_ajax_galleriffic(self):
        # create objects
        gallery = Gallery()
        gallery.save()
        gi_obj = GalleryImage(gallery=gallery, state='published')
        gi_obj.save()
        gi_obj.sites.add(Site.objects.get_current())
        ve_obj = VideoEmbed(gallery=gallery, state='published')
        ve_obj.save()
        ve_obj.sites.add(Site.objects.get_current())
        vf_obj = VideoFile(gallery=gallery, state='published', file='test.flv')
        vf_obj.save()
        vf_obj.sites.add(Site.objects.get_current())

        # raise 404 on invalid slug
        self.assertRaises(Http404, views.gallery_item_ajax_galleriffic, request=None, slug='invalid_slug')

        # use galleryimage template for gallery image object
        client = Client()
        response = client.get(reverse('gallery_item_ajax_galleriffic', kwargs={'slug': gi_obj.slug}))
        self.assertTemplateUsed(response, 'gallery/ajax/galleriffic_galleryimage.html')
        
        # use videoembed template for video embed object
        response = client.get(reverse('gallery_item_ajax_galleriffic', kwargs={'slug': ve_obj.slug}))
        self.assertTemplateUsed(response, 'gallery/ajax/galleriffic_videoembed.html')
        
        # use videofile template for video file object
        response = client.get(reverse('gallery_item_ajax_galleriffic', kwargs={'slug': vf_obj.slug}))
        self.assertTemplateUsed(response, 'gallery/ajax/galleriffic_videofile.html')
Exemple #3
0
    def save(self, commit=True):
        images = []
        if self.cleaned_data['files']:
            for item in self.cleaned_data['files']:
                item.seek(0)
                to_add = []

                # Zip file?
                itemfp = StringIO(item.read())
                item.seek(0)
                try:
                    zfp = zipfile.ZipFile(itemfp, 'r')
                except:
                    # zipfile does not raise a specific exception
                    to_add.append(item)
                else:    
                    if not zfp.testzip():
                        # Running into issues using streams, so use temp files
                        tmpdir = mkdtemp()
                        for filename in sorted(zfp.namelist()):
                            tmpfile = os.path.join(tmpdir, filename)
                            data = zfp.read(filename)
                            fp = open(tmpfile, 'wb')
                            fp.write(data)
                            fp.close()
                            afile = File(open(tmpfile), 'rb')
                            afile.name = filename
                            to_add.append(afile)
                    else:                    
                        to_add.append(item)

                for afile in to_add:                    
                    obj = GalleryImage(title=afile.name, gallery=self.gallery)
                    obj.image = afile
                    obj.save()
                    obj.sites = list(self.gallery.sites.all())
                    obj.save()
                    images.append(obj)

        return images
Exemple #4
0
    def handle(self, *args, **options):
        assigned_mediums = {
            '7 deadly sins': 'Collage',
            'attempt to mimic water': 'Sculpture',
            'bound': 'Collage',
            'collage 2019': 'Collage',
            'collage 2020': 'Collage',
            'commissions': 'Mixed Media',
            'containment': 'Mixed Media',
            'dissimulation': 'Sculpture',
            'dusk': 'Mixed Media',
            'emily owens as a rock': 'Sculpture',
            'endless nightmare': 'Painting',
            'ephemeral embedding': 'Sculpture',
            'exit landscape': 'Painting',
            'fertile ground': 'Mixed Media',
            'growth': 'Painting',
            'house plant with artificial shadow': 'Mixed Media',
            'i dreamt of you': 'Painting',
            'imagined landscapes and watersources': 'Painting',
            'imitation of a chair': 'Video',
            'inconspicuous growth': 'Painting',
            'moss': 'Painting',
            'new mexico': 'Painting',
            'no place (utopic traces)': 'Painting',
            'object in the environment': 'Photography',
            'paintings 2013': 'Painting',
            'paintings 2014': 'Painting',
            'paintings in flux': 'Painting',
            'process': 'Photography',
            'push (traces)': 'Video',
            'representing abstraction': 'Mixed Media',
            'return to soil': 'Mixed Media',
            'shore': 'Mixed Media',
            'tarot series': 'Collage',
            'the zodiac': 'Collage',
            'twin peaks': 'Collage',
            'utopia': 'Painting',
            'voyage: an expedition into materiality': 'Mixed Media'
        }
        self.stdout.write("Trying to add mediums...")
        mediums = [
            'Collage', 'Painting', 'Photography', 'Mixed Media', 'Sculpture',
            'Video'
        ]
        post_date = datetime.today() - timedelta(days=365)
        for m in mediums:
            existing_mediums = [
                i.name for i in InstallationMedium.objects.all()
            ]
            if m in existing_mediums:
                self.stdout.write(f"{m} already exists as a medium.")
            else:
                medium = InstallationMedium(name=m)
                medium.save()
        wd = os.path.abspath(os.getcwd())
        print(wd)
        with open(os.path.join(wd, 'organized.json'), 'r') as f:
            data = json.load(f)  # ['data']
            for page in reversed(data):
                name = page['name']
                body = page.get('body', '')
                items = page['items']

                gallery = Gallery.objects.first()

                installation = InstallationPage(
                    title=name,
                    slug=slugify(name),
                    date=post_date,
                    body=json.dumps([{
                        'type': 'paragraph',
                        'value': body
                    }]) if len(body) else None,
                    mediums=[
                        InstallationMedium.objects.get(
                            name=assigned_mediums[name])
                    ])
                self.stdout.write(f"Initialized page {name}")
                gallery.add_child(instance=installation)
                # installation.save_revision().publish()
                # saved_items = []
                image_counter = 0
                for item_data in items:
                    gallery_item = GalleryItem(
                        title=name,
                        slug=slugify(name) + str(image_counter),
                        description=item_data.get('description', ''))
                    gallery_images = []
                    for img_data in item_data['images']:
                        filename = img_data['filename']
                        path = os.path.join(
                            os.path.join(wd, 'migration_images'), filename)

                        with open(path, "rb") as imagefile:

                            image = Image(
                                file=ImageFile(BytesIO(imagefile.read()),
                                               name=filename),
                                title=name + '-' + filename.rsplit('.', 1)[0])
                            image.save()
                            gallery_image = GalleryImage(
                                image=image, caption=img_data['caption'])
                            gallery_images.append(gallery_image)
                            gallery_item.gallery_images.add(gallery_image)

                    self.stdout.write(
                        f"    Saved image {filename} to database")

                    installation.add_child(instance=gallery_item)
                    image_counter += 1

                # installation.gallery_images=saved_items
                installation.save_revision().publish()

                self.stdout.write(f"        Attached images to {name}.")

                self.stdout.write(
                    f"Published page {name} with {str(len(items))} images.")
                post_date = post_date + timedelta(days=1)
        self.stdout.write(
            'Finalizing homepage and publishing all page objects...')
        all_images = list(GalleryImage.objects.all())
        random_images = random.sample(all_images, 5)

        for img_obj in random_images:
            img = img_obj.image
            featured_img = HomePageImage(home_page_image=img)
            featured_img.save()
        for item in GalleryItem.objects.all():
            item.save_revision().publish()
        self.stdout.write('Done.')
Exemple #5
0
 def mutate(root, info, input=None):
     ok = True
     image_instance = GalleryImage(title=input.title, thumbnail=input.thumbnail)
     image_instance.save()
     return CreateImage(ok=ok, image=image_instance)