Ejemplo n.º 1
0
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'})
Ejemplo n.º 2
0
 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 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, 'upload.html', context)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
 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")
Ejemplo n.º 6
0
    def test28_create_upload_preset(self, mocker):
        """ should allow creating upload_presets """
        mocker.return_value = MOCK_RESPONSE

        api.create_upload_preset(name=API_TEST_PRESET, folder="folder")

        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith("/upload_presets"))
        self.assertEqual("POST", get_method(mocker))
        self.assertEqual(get_param(mocker, "name"), API_TEST_PRESET)
        self.assertEqual(get_param(mocker, "folder"), "folder")
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder",
                                       unsigned=True)
     result = uploader.unsigned_upload("tests/logo.png", preset["name"])
     self.assertRegexpMatches(result["public_id"],
                              '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])
Ejemplo n.º 9
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder",
                                       unsigned=True)
     result = uploader.unsigned_upload(TEST_IMAGE, preset["name"])
     six.assertRegex(self, result["public_id"],
                     '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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])
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name=API_TEST_PRESET, folder="folder", tags=[UNIQUE_TAG])
        api.create_upload_preset(name=API_TEST_PRESET2, folder="folder2", tags=[UNIQUE_TAG])
        api.create_upload_preset(name=API_TEST_PRESET3, folder="folder3", tags=[UNIQUE_TAG])

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        names = [preset["name"] for preset in presets]
        self.assertIn(API_TEST_PRESET3, names)
        self.assertIn(API_TEST_PRESET2, names)
        self.assertIn(API_TEST_PRESET, names)
Ejemplo n.º 16
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name=API_TEST_PRESET, folder="folder", tags=[UNIQUE_API_TAG])
        api.create_upload_preset(name=API_TEST_PRESET2, folder="folder2", tags=[UNIQUE_API_TAG])
        api.create_upload_preset(name=API_TEST_PRESET3, folder="folder3", tags=[UNIQUE_API_TAG])

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        names = [preset["name"] for preset in presets]
        self.assertIn(API_TEST_PRESET3, names)
        self.assertIn(API_TEST_PRESET2, names)
        self.assertIn(API_TEST_PRESET, names)
Ejemplo n.º 17
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name="api_test_upload_preset", folder="folder")
        api.create_upload_preset(name="api_test_upload_preset2", folder="folder2")
        api.create_upload_preset(name="api_test_upload_preset3", folder="folder3")

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        self.assertEqual(presets[0]["name"], "api_test_upload_preset3")
        self.assertEqual(presets[1]["name"], "api_test_upload_preset2")
        self.assertEqual(presets[2]["name"], "api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset2")
        api.delete_upload_preset("api_test_upload_preset3")
Ejemplo n.º 18
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name="api_test_upload_preset", folder="folder")
        api.create_upload_preset(name="api_test_upload_preset2", folder="folder2")
        api.create_upload_preset(name="api_test_upload_preset3", folder="folder3")

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        self.assertEqual(presets[0]["name"], "api_test_upload_preset3")
        self.assertEqual(presets[1]["name"], "api_test_upload_preset2")
        self.assertEqual(presets[2]["name"], "api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset")
        api.delete_upload_preset("api_test_upload_preset2")
        api.delete_upload_preset("api_test_upload_preset3")
Ejemplo n.º 19
0
    def test28_create_list_upload_presets(self):
        """ should allow creating and listing upload_presets """
        api.create_upload_preset(name=API_TEST_PRESET,
                                 folder="folder",
                                 tags=[UNIQUE_TAG])
        api.create_upload_preset(name=API_TEST_PRESET2,
                                 folder="folder2",
                                 tags=[UNIQUE_TAG])
        api.create_upload_preset(name=API_TEST_PRESET3,
                                 folder="folder3",
                                 tags=[UNIQUE_TAG])

        api_response = api.upload_presets()
        presets = api_response["presets"]
        self.assertGreaterEqual(len(presets), 3)
        self.assertEqual(presets[0]["name"], API_TEST_PRESET3)
        self.assertEqual(presets[1]["name"], API_TEST_PRESET2)
        self.assertEqual(presets[2]["name"], API_TEST_PRESET)
        api.delete_upload_preset(API_TEST_PRESET)
        api.delete_upload_preset(API_TEST_PRESET2)
        api.delete_upload_preset(API_TEST_PRESET3)
Ejemplo n.º 20
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder", unsigned=True, tags=[UNIQUE_TAG])
     result = uploader.unsigned_upload(TEST_IMAGE, preset["name"], tags=[UNIQUE_TAG])
     six.assertRegex(self, result["public_id"], '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])
Ejemplo n.º 21
0
 def test_upload_preset(self):
     """ should support unsigned uploading using presets """
     preset = api.create_upload_preset(folder="upload_folder", unsigned=True)
     result = uploader.unsigned_upload("tests/logo.png", preset["name"])
     self.assertRegexpMatches(result["public_id"], '^upload_folder\/[a-z0-9]+$')
     api.delete_upload_preset(preset["name"])