Esempio n. 1
0
 def save(self, *args, **kwargs):
     super(AlbumForm, self).save(*args, **kwargs)
     reldata = []
     for photo in self._js_fields['photo']:
         handler = ImageHandler()
         handler.load_by_draft(photo['name']['value'], self.draft)
         handler.copy_new_images_to_draft(self.user)
         handler.copy_album_images_to_draft(self.user)
         info = {
             'description': photo['description']['value'],
             'image': photo['name']['value']
         }
         info.update(handler.urls())
         reldata.append(info)
     self._set_rel_fields({'photos': reldata})
     self.draft.set_content_object(self.cleaned_data)
     self.draft.save()
     newhandler = ImageHandler()
     newhandler.load_by_filename_user('', self.user)
     newhandler.delete_path()
     ImageHandler.delete_junk(self.draft)
Esempio n. 2
0
    def _build_img_data(self, name, description):
        handler = ImageHandler()
        if self.draft and self.draft.id:
            handler.load_by_draft(name, self.draft)
        elif self.instance and self.instance.id:
            if self.user:
                handler.load_by_filename_album(name, self.instance, self.user)
            else:
                handler.load_by_filename_album(name, self.instance)
        else:
            handler.load_by_filename_user(name, self.user)

        if not handler.urls():
            handler.load_by_filename_user(name, self.user)
            if not handler.urls():
                raise ImageHandlerException("Image %s not found." % name)

        img = {
            'name': {'value': name},
            'description': {'value': description},
            'url': handler.url('small'),
            'url_view': handler.url('big')
        }
        return img
Esempio n. 3
0
def cancel_upload_ajax(request):
    image = request.POST["image"]
    handler = ImageHandler()
    handler.load_by_filename_user(image, request.user)
    handler.delete()
    return {"success": True}