예제 #1
0
    def patch_from_blueprint(self, blueprint, save_context):
        ductmodels.blueprint_expects_dict(blueprint)
        blueprint = dict(blueprint)
        if "credit" in blueprint:
            del blueprint["credit"]

        super(Picture, self).patch_from_blueprint(blueprint, save_context)

        if 'flickr_photo_id' in blueprint:
            flickr_photo_id = blueprint['flickr_photo_id']
            flickr_photo_id = ductmodels.blueprint_cast_to_string(flickr_photo_id)
            # FIXME TEMPORARY
            from ductus.modules.picture.flickr import FlickrUriHandler
            url = 'http://flickr.com/photos/0/%s' % flickr_photo_id
            if FlickrUriHandler.handles(url):
                fuh = FlickrUriHandler(url)
                fuh.validate()
                fuh.save(save_context, picture=self, return_before_saving=True)

        if 'rotation' in blueprint:
            rotation = blueprint['rotation']
            rotation = ductmodels.blueprint_cast_to_string(rotation)
            rotation_validator(rotation)
            self.rotation = rotation

        if 'net_rotation' in blueprint:
            net_rotation = blueprint['net_rotation']
            net_rotation = ductmodels.blueprint_cast_to_string(net_rotation)
            rotation_validator(net_rotation)
            self.rotation = str((int(self.rotation or 0) +
                                 int(net_rotation or 0)) % 360)
예제 #2
0
def flickr_search_view(request):
    kw = {'page': request.GET.get("page", "1")}
    place_name = None
    if "place_id" in request.GET:
        kw["place_id"] = request.GET["place_id"]
    elif "place" in request.GET and request.GET["place"]:
        places = flickr.places_find(query=request.GET["place"])["places"]["place"]
        try:
            place = places[0]
        except IndexError:
            pass
        else:
            kw["place_id"] = place["place_id"]
            place_name = place["_content"]
    if "q" in request.GET:
        search_photos = partial(flickr.photos_search, per_page=100,
                                license=(','.join(license_map())),
                                safe_search=1, content_type=1, media="photos",
                                extras="license,owner_name,original_format")

        if request.GET.get("sort", None) in valid_sort_methods:
            kw["sort"] = request.GET["sort"]
        if request.GET.get("search_by", None) == 'tags':
            tags = [t for t in re.split(r'\s|"(.+)"', request.GET['q']) if t]
            kw['tags'] = ','.join(tags)
        else:
            kw['text'] = request.GET['q']
        if "group" in request.GET:
            kw['group_id'] = request.GET["group"]
        search_result = search_photos(**kw)["photos"]
        page = int(search_result["page"])
        pages = int(search_result["pages"])
        # if we're not searching in a specific group, only return results for
        # which we are allowed to download the original image.  see ductus
        # ticket #64 for explanation of why
        photos = [FlickrPhoto(p).dict for p in search_result['photo']
                  if 'group' in request.GET or 'originalsecret' in p]

        # if somebody entered a flickr url in the search box, return that image
        if FlickrUriHandler.handles(request.GET['q']):
            from django import forms
            handler = FlickrUriHandler(request.GET['q'])
            try:
                handler.validate()
            except forms.ValidationError:
                pass
            else:
                photos.insert(0, handler.photo.dict)
    else:
        photos = None
        page = 0
        pages = 0

    return render_json_response({
        'place': place_name,
        'photos': photos,
        'page': page,
        'pages': pages,
        'sort_method': kw.get('sort', 'date-posted-desc'),
    })
예제 #3
0
    def patch_from_blueprint(self, blueprint, save_context):
        ductmodels.blueprint_expects_dict(blueprint)
        blueprint = dict(blueprint)
        if "credit" in blueprint:
            del blueprint["credit"]

        super(Picture, self).patch_from_blueprint(blueprint, save_context)

        if 'flickr_photo_id' in blueprint:
            flickr_photo_id = blueprint['flickr_photo_id']
            flickr_photo_id = ductmodels.blueprint_cast_to_string(
                flickr_photo_id)
            # FIXME TEMPORARY
            from ductus.modules.picture.flickr import FlickrUriHandler
            url = 'http://flickr.com/photos/0/%s' % flickr_photo_id
            if FlickrUriHandler.handles(url):
                fuh = FlickrUriHandler(url)
                fuh.validate()
                fuh.save(save_context, picture=self, return_before_saving=True)

        if 'rotation' in blueprint:
            rotation = blueprint['rotation']
            rotation = ductmodels.blueprint_cast_to_string(rotation)
            rotation_validator(rotation)
            self.rotation = rotation

        if 'net_rotation' in blueprint:
            net_rotation = blueprint['net_rotation']
            net_rotation = ductmodels.blueprint_cast_to_string(net_rotation)
            rotation_validator(net_rotation)
            self.rotation = str(
                (int(self.rotation or 0) + int(net_rotation or 0)) % 360)
예제 #4
0
def flickr_search_view(request):
    kw = {'page': request.GET.get("page", "1")}
    place_name = None
    if "place_id" in request.GET:
        kw["place_id"] = request.GET["place_id"]
    elif "place" in request.GET and request.GET["place"]:
        places = flickr.places_find(
            query=request.GET["place"])["places"]["place"]
        try:
            place = places[0]
        except IndexError:
            pass
        else:
            kw["place_id"] = place["place_id"]
            place_name = place["_content"]
    if "q" in request.GET:
        search_photos = partial(flickr.photos_search,
                                per_page=100,
                                license=(','.join(license_map())),
                                safe_search=1,
                                content_type=1,
                                media="photos",
                                extras="license,owner_name,original_format")

        if request.GET.get("sort", None) in valid_sort_methods:
            kw["sort"] = request.GET["sort"]
        if request.GET.get("search_by", None) == 'tags':
            tags = [t for t in re.split(r'\s|"(.+)"', request.GET['q']) if t]
            kw['tags'] = ','.join(tags)
        else:
            kw['text'] = request.GET['q']
        if "group" in request.GET:
            kw['group_id'] = request.GET["group"]
        search_result = search_photos(**kw)["photos"]
        page = int(search_result["page"])
        pages = int(search_result["pages"])
        # if we're not searching in a specific group, only return results for
        # which we are allowed to download the original image.  see ductus
        # ticket #64 for explanation of why
        photos = [
            FlickrPhoto(p).dict for p in search_result['photo']
            if 'group' in request.GET or 'originalsecret' in p
        ]

        # if somebody entered a flickr url in the search box, return that image
        if FlickrUriHandler.handles(request.GET['q']):
            from django import forms
            handler = FlickrUriHandler(request.GET['q'])
            try:
                handler.validate()
            except forms.ValidationError:
                pass
            else:
                photos.insert(0, handler.photo.dict)
    else:
        photos = None
        page = 0
        pages = 0

    return render_json_response({
        'place':
        place_name,
        'photos':
        photos,
        'page':
        page,
        'pages':
        pages,
        'sort_method':
        kw.get('sort', 'date-posted-desc'),
    })