def test30_create_list_upload_presets(self): """ should allow deleting upload_presets """ api.create_upload_preset(name="api_test_upload_preset4", folder="folder") api.upload_preset("api_test_upload_preset4") api.delete_upload_preset("api_test_upload_preset4") with self.assertRaises(api.NotFound): api.upload_preset("api_test_upload_preset4")
def noticia_nueva(request): unsigned = request.GET.get("unsigned") == "true" if (unsigned): # For the sake of simplicity of the sample site, we generate the preset on the fly. It only needs to be created once, in advance. try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset(name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( # Form demonstrating backend upload backend_form = PhotoForm(), # Form demonstrating direct upload direct_form = direct_form, # Should the upload form be unsigned unsigned = unsigned, ) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) if request.method == "POST": form = NoticiaForm(request.POST, request.FILES) context['posted'] = form.instance if form.is_valid(): post = form.save() post.imagen = post.image.url post.save() return redirect('noticias.views.noticia_detail', pk=post.pk) else: form = NoticiaForm() return render(request, 'noticias/post_edit.html', {'form': form, 'tipo' : 'Noticia'})
def upload(request): unsigned = request.GET.get("unsigned") == "true" if (unsigned): # For the sake of simplicity of the sample site, we generate the preset on the fly. It only needs to be created once, in advance. try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset(name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( # Form demonstrating backend upload backend_form = PhotoForm(), # Form demonstrating direct upload direct_form = direct_form, # Should the upload form be unsigned unsigned = unsigned, ) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) if request.method == 'POST': # Only backend upload should be posting here form = PhotoForm(request.POST, request.FILES) context['posted'] = form.instance if form.is_valid(): # Uploads image and creates a model instance for it form.save() return render(request, 'noticias/upload.html', context)
def upload(request): unsigned = request.GET.get("unsigned") == "true" if (unsigned): # For the sake of simplicity of the sample site, we generate the preset on the fly. # It only needs to be created once, in advance. try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset(name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( # Form demonstrating backend upload backend_form=PhotoForm(), # Form demonstrating direct upload direct_form=direct_form, # Should the upload form be unsigned unsigned=unsigned, ) # When using direct upload - the following call is necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) if request.method == 'POST': # Only backend upload should be posting here form = PhotoForm(request.POST, request.FILES) context['posted'] = form.instance if form.is_valid(): # Uploads image and creates a model instance for it form.save() return render(request, 'upload.html', context)
def test29_get_upload_presets(self, mocker): """ should allow getting a single upload_preset """ mocker.return_value = MOCK_RESPONSE api.upload_preset(API_TEST_PRESET) args, kargs = mocker.call_args self.assertTrue(get_uri(args).endswith("/upload_presets/" + API_TEST_PRESET)) self.assertEqual("GET", get_method(mocker))
def test31_update_upload_presets(self): """ should allow getting a single upload_preset """ result = api.create_upload_preset(folder="folder") name = result["name"] preset = api.upload_preset(name) settings = preset["settings"] settings.update({"colors": True, "unsigned": True, "disallow_public_id": True}) api.update_upload_preset(name, **settings) preset = api.upload_preset(name) self.assertEqual(preset["unsigned"], True) self.assertEqual(preset["settings"], {"folder": "folder", "colors": True, "disallow_public_id": True}) api.delete_upload_preset(name)
def upload(request, object_id): """View for uploading new photo resource to cloudinary and creating model""" user = request.user character = get_character_from_ob(object_id) if not user.is_authenticated or (user.char_ob != character and not user.is_staff): raise Http404("You are not permitted to upload to this gallery.") unsigned = request.GET.get("unsigned") == "true" if unsigned: # For the sake of simplicity of the sample site, we generate the preset on the fly. # It only needs to be created once, in advance. try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset( name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder", ) direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( # Form demonstrating backend upload backend_form=PhotoForm(), # Form demonstrating direct upload direct_form=direct_form, # Should the upload form be unsigned unsigned=unsigned, ) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context["direct_form"], request) context["character"] = character context["page_title"] = "Upload" if request.method == "POST": # Only backend upload should be posting here owner_char = Photo(owner=character) form = PhotoForm(request.POST, request.FILES, instance=owner_char) context["posted"] = False if form.is_valid(): # Uploads image and creates a model instance for it if user.is_authenticated and user.check_permstring("builders"): context["show_hidden"] = True context["posted"] = form.instance form.save() return render(request, "character/upload.html", context)
def test29_get_upload_presets(self): """ should allow getting a single upload_preset """ result = api.create_upload_preset(unsigned=True, folder="folder", width=100, crop="scale", tags=["a", "b", "c", UNIQUE_API_TAG], context={"a": "b", "c": "d"}) name = result["name"] preset = api.upload_preset(name) self.assertEqual(preset["name"], name) self.assertIs(preset["unsigned"], True) settings = preset["settings"] self.assertEqual(settings["folder"], "folder") self.assertEqual(settings["transformation"], [{"width": 100, "crop": "scale"}]) self.assertEqual(settings["context"], {"a": "b", "c": "d"}) self.assertEqual(settings["tags"], ["a", "b", "c", UNIQUE_API_TAG])
def test29_get_upload_presets(self): """ should allow getting a single upload_preset """ result = api.create_upload_preset(unsigned=True, folder="folder", width=100, crop="scale", tags=["a","b","c"], context={"a": "b","c": "d"}) name = result["name"] preset = api.upload_preset(name) self.assertEqual(preset["name"], name) self.assertEqual(preset["unsigned"], True) settings = preset["settings"] self.assertEqual(settings["folder"], "folder") self.assertEqual(settings["transformation"], [{"width": 100, "crop": "scale"}]) self.assertEqual(settings["context"], {"a": "b","c": "d"}) self.assertEqual(settings["tags"], ["a","b","c"]) api.delete_upload_preset(name)
def upload(request): unsigned = request.GET.get("unsigned") == "true" if (unsigned): try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.Notfound: api.create_upload_preset(name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( backend_form=PhotoForm(), direct_form=direct_form, unsigned=unsigned, ) if request.method == 'POST': form = PhotoForm(request.POST, request.FILES) context['posted'] = form.instance if form.is_valid(): form.save() return render(request, 'upload.html', context)