Example #1
0
 def test27_start_at(self, mocker):
     """ should allow listing resources by start date """
     mocker.return_value = MOCK_RESPONSE
     start_at = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
     api.resources(type="upload", start_at=start_at, direction="asc")
     args, kargs = mocker.call_args
     params = get_params(args)
     self.assertEqual(params['start_at'], start_at)
Example #2
0
 def test04_resources_types(self, mocker):
     """ should allow listing resources by type """
     mocker.return_value = MOCK_RESPONSE
     api.resources(type="upload", context=True, tags=True)
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image/upload'))
     self.assertTrue(get_params(args)['context'])
     self.assertTrue(get_params(args)['tags'])
Example #3
0
 def test05_resources_prefix(self, mocker):
     """ should allow listing resources by prefix """
     mocker.return_value = MOCK_RESPONSE
     api.resources(prefix=API_TEST_PREFIX, context=True, tags=True, type="upload")
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image/upload'))
     self.assertEqual(get_params(args)['prefix'], API_TEST_PREFIX)
     self.assertTrue(get_params(args)['context'])
     self.assertTrue(get_params(args)['tags'])
Example #4
0
 def test06b_resources_direction(self):
     """ should allow listing resources in both directions """
     asc_resources = api.resources(prefix="api_test", direction="asc", type="upload")["resources"]
     desc_resources = api.resources(prefix="api_test", direction="desc", type="upload")["resources"]
     asc_resources.reverse()
     self.assertEquals(asc_resources, desc_resources)
     asc_resources_alt = api.resources(prefix="api_test", direction=1, type="upload")["resources"]
     desc_resources_alt = api.resources(prefix="api_test", direction=-1, type="upload")["resources"]
     asc_resources_alt.reverse()
     self.assertEquals(asc_resources_alt, desc_resources_alt)
     self.assertEquals(asc_resources_alt, asc_resources)
Example #5
0
 def test06b_resources_direction(self):
     """ should allow listing resources in both directions """
     asc_resources = api.resources(prefix = "api_test", direction = "asc", type = "upload")["resources"]
     desc_resources = api.resources(prefix = "api_test", direction = "desc", type = "upload")["resources"]
     asc_resources.reverse()
     self.assertEqual(asc_resources, desc_resources)
     asc_resources_alt = api.resources(prefix = "api_test", direction = 1, type = "upload")["resources"]
     desc_resources_alt = api.resources(prefix = "api_test", direction = -1, type = "upload")["resources"]
     asc_resources_alt.reverse()
     self.assertEqual(asc_resources_alt, desc_resources_alt)
     self.assertEqual(asc_resources_alt, asc_resources)
Example #6
0
    def test03_resources_cursor(self):
        """ should allow listing resources with cursor """
        result = api.resources(max_results=1)
        self.assertNotEqual(result["resources"], None)
        self.assertEqual(len(result["resources"]), 1)
        self.assertNotEqual(result["next_cursor"], None)

        result2 = api.resources(max_results=1, next_cursor=result["next_cursor"])
        self.assertNotEqual(result2["resources"], None)
        self.assertEqual(len(result2["resources"]), 1)
        self.assertNotEqual(result2["resources"][0]["public_id"], result["resources"][0]["public_id"])
Example #7
0
    def test_structured_metadata_in_resources_api(self):
        result = api.resources(prefix=API_TEST_ID, type="upload", metadata=True)

        self.assertTrue(result["resources"])
        for resource in result["resources"]:
            self.assertIn("metadata", resource)

        result = api.resources(prefix=API_TEST_ID, type="upload", metadata=False)

        self.assertTrue(result["resources"])
        for resource in result["resources"]:
            self.assertNotIn("metadata", resource)
Example #8
0
 def test04_resources_types(self):
     """ should allow listing resources by type """
     resource = [
         resource for resource in api.resources(type="upload")["resources"]
         if resource["public_id"] == "api_test"
     ][0]
     self.assertNotEqual(resource, None)
Example #9
0
 def test05_resources_prefix(self):
     """ should allow listing resources by prefix """
     public_ids = [
         resource["public_id"] for resource in api.resources(type="upload", prefix="api_test")["resources"]
     ]
     self.assertIn("api_test", public_ids)
     self.assertIn("api_test2", public_ids)
Example #10
0
def api_member(request, slug):
    data = get_image_cloud_url([Member.objects.get(slug=slug)])[0]
    images = resources(prefix=f'{ASSET_DIR}/member/{data.href}',
                       type='upload',
                       max_results=500)['resources']
    images = [i['public_id'] for i in images][::-1]
    return JsonResponse(dict(data=images))
Example #11
0
 def test05_resources_prefix(self):
     """ should allow listing resources by prefix """
     public_ids = [
         resource["public_id"] for resource in api.resources(
             type="upload", prefix="api_test")["resources"]
     ]
     self.assertIn("api_test", public_ids)
     self.assertIn("api_test2", public_ids)
Example #12
0
 def test05_resources_prefix(self):
     """ should allow listing resources by prefix """
     resources = api.resources(prefix = "api_test", context = True, tags = True, type = "upload")["resources"]
     public_ids = [resource["public_id"] for resource in resources]
     self.assertIn("api_test", public_ids)
     self.assertIn("api_test2", public_ids)
     self.assertIn(["api_test_tag"], [resource["tags"] for resource in resources])
     self.assertIn({"custom": {"key": "value"}}, [resource["context"] for resource in resources])
Example #13
0
 def test05_resources_prefix(self):
     """ should allow listing resources by prefix """
     resources = api.resources(prefix="api_test", context=True, tags=True, type="upload")["resources"]
     public_ids = [resource["public_id"] for resource in resources]
     self.assertIn("api_test", public_ids)
     self.assertIn("api_test2", public_ids)
     self.assertIn(["api_test_tag"], [resource["tags"] for resource in resources])
     self.assertIn({"custom": {"key": "value"}}, [resource["context"] for resource in resources])
Example #14
0
 def test02_resources(self):
     """ should allow listing resources """
     resource = [
         resource
         for resource in api.resources(max_results=500)["resources"]
         if resource["public_id"] == "api_test"
     ][0]
     self.assertNotEqual(resource, None)
     self.assertEqual(resource["type"], "upload")
Example #15
0
 def test27_start_at(self):
     """ should allow listing resources by start date """
     time.sleep(2)
     start_at = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
     time.sleep(2)
     response = uploader.upload("tests/logo.png")
     api_repsonse = api.resources(type="upload", start_at=start_at, direction="asc")
     resources = api_repsonse["resources"];
     self.assertEqual(len(resources), 1)
     self.assertEqual(resources[0]["public_id"], response["public_id"])
Example #16
0
 def test27_start_at(self):
     """ should allow listing resources by start date """
     time.sleep(2)
     start_at = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
     time.sleep(2)
     response = uploader.upload("tests/logo.png")
     api_repsonse = api.resources(type="upload", start_at=start_at, direction="asc")
     resources = api_repsonse["resources"];
     self.assertEqual(len(resources), 1)
     self.assertEqual(resources[0]["public_id"], response["public_id"])
Example #17
0
 def test05_resources_prefix(self):
     """ should allow listing resources by prefix """
     resources = api.resources(prefix="api_test", context=True, tags=True, type="upload", max_results=500)["resources"]
     public_ids = [resource["public_id"] for resource in resources]
     self.assertIn("api_test", public_ids)
     self.assertIn("api_test2", public_ids)
     resources_tags = [resource["tags"] for resource in resources]
     tags = [x for y in resources_tags for x in y]
     self.assertIn("api_test_tag", tags)
     self.assertIn({"custom": {"key": "value"}}, [resource.get("context") for resource in resources])
Example #18
0
def render_portfolio(request, username):
    designer = Designer.objects.get_designer_info(username=username)

    # if portfolio isn't real then raise error
    if designer is None:
        raise Http404

    context = {"designer": designer, "num_collections": 0}
    context['favorites'] = Like.objects.get_favorite_count(liker=designer)

    # get collections related to portfolio
    collections = Collection.objects.get_collections(username=username)
    if collections is not None:

        context['num_collections'] = len(collections)
        for collection in collections:
            collection['tags'] = Collection.objects.get_tags(
                collection_id=collection['id'])

            # get collection previews
            bucket_link = "%s/%d" % (username, collection['id'])
            collection["photos"] = []
            try:
                folder = resources(type="upload",
                                   resource_type="image",
                                   prefix=bucket_link)
                num_photos = len(folder['resources'])
                num_display = 4 if num_photos > 4 else num_photos
                for i in xrange(0, num_display):
                    collection["photos"].append(
                        folder['resources'][i]['public_id'])
            except:
                pass
        context['collections'] = collections

        # get if liked by user for each collection
        try:
            liker = request.user.buyer
        except AttributeError:
            liker = request.user.designer

        likes = Like.objects.get_likes(liker=liker)
        context['likes'] = likes

    # get follow
    if request.user.username != username:
        try:
            follower = request.user.buyer
        except AttributeError:
            follower = request.user.designer

        context['is_following'] = Follow.objects.get_is_following(
            follower=follower, followee=designer)
    return render(request, "Portfolios/portfolio.html", context)
Example #19
0
def render_portfolio(request, username):
    designer = Designer.objects.get_designer_info(username=username)

    # if portfolio isn't real then raise error
    if designer is None:
        raise Http404

    context = {"designer": designer, "num_collections": 0}
    context['favorites'] = Like.objects.get_favorite_count(liker=designer)
    
    # get collections related to portfolio
    collections = Collection.objects.get_collections(username=username)
    if collections is not None:

        context['num_collections'] = len(collections)
        for collection in collections:
            collection['tags'] = Collection.objects.get_tags(collection_id=collection['id'])
            
            # get collection previews
            bucket_link = "%s/%d" %(username, collection['id'])
            collection["photos"] = []
            try:
                folder = resources(type="upload", resource_type="image", prefix=bucket_link)
                num_photos = len(folder['resources']) 
                num_display = 4 if num_photos > 4 else num_photos
                for i in xrange(0, num_display):
                    collection["photos"].append(folder['resources'][i]['public_id'])
            except:
                pass
        context['collections'] = collections

        # get if liked by user for each collection
        try:
            liker = request.user.buyer
        except AttributeError:
            liker = request.user.designer

        likes = Like.objects.get_likes(liker=liker)    
        context['likes'] = likes

    # get follow 
    if request.user.username != username:
        try:
            follower = request.user.buyer
        except AttributeError:
            follower = request.user.designer

        context['is_following'] = Follow.objects.get_is_following(follower=follower, followee=designer) 
    return render(request, "Portfolios/portfolio.html", context)
Example #20
0
def fill_db():

    f = open("./src/BD.txt", "w+")
    response = resources(type="upload", max_results=5000)

    for item in response.get("resources"):

        if item.get("bytes", 0) > 0:

            img = None

            try:
                img_bytes = requests.get(item.get("url"))
                img = Image.open(BytesIO(img_bytes.content))
            except Exception as e:
                continue

            prom = getPromedioRGB(img)

            if prom:
                f.write(f'{item.get("url")},{prom}\n')

    f.close()
Example #21
0
def get_resources(path, order="date"):
    images = resources(
        prefix=path,
        type="upload",
        max_results=500,
        secure=True,
    )["resources"]
    if order == "date":
        images = sorted(
            images,
            key=lambda k: datetime.strptime(k["created_at"],
                                            "%Y-%m-%dT%H:%M:%SZ"),
            reverse=True,
        )
    elif order == "name":
        images = sorted(images, key=lambda k: k["public_id"])
    images = [{
        "url": i["public_id"],
        "publicId": i["public_id"],
        "width": i["width"],
        "height": i["height"],
    } for i in images]
    images = build_url(images)
    return images
Example #22
0
 def test02_resources(self, mocker):
     """ should allow listing resources """
     mocker.return_value = MOCK_RESPONSE
     api.resources()
     args, kargs = mocker.call_args
     self.assertTrue(get_uri(args).endswith('/resources/image'))
Example #23
0
def get_resources():
    response = resources(type = "upload", max_results = 5000)

    for item in response["resources"]:
        if item["bytes"] > 0:
            print(item["url"])
Example #24
0
 def test04_resources_types(self):
     """ should allow listing resources by type """
     resource = [resource for resource in api.resources(type="upload")["resources"] if resource["public_id"] == "api_test"][0]
     self.assertNotEqual(resource, None)
Example #25
0
 def test04_resources_types(self):
     """ should allow listing resources by type """
     resources = api.resources(type="upload")["resources"]
     public_ids = [resource["public_id"] for resource in resources]
     self.assertIn("api_test", public_ids)
Example #26
0
 def test04_resources_types(self):
     """ should allow listing resources by type """
     resources = api.resources(type="upload", max_results=500)["resources"]
     public_ids = [resource["public_id"] for resource in resources]
     self.assertIn("api_test", public_ids)