コード例 #1
0
ファイル: forms.py プロジェクト: jennspics/ductus
    def validate(self):
        from ductus.resource import get_resource_database
        from ductus.resource.ductmodels import DuctModelMismatchError
        resource_database = get_resource_database()

        for r in self._re_objects:
            match = r.match(self.uri)
            if match is not None:
                hash_type, digest = match.group(1), match.group(2)
                urn = "urn:%s:%s" % (hash_type, digest)
                if urn not in resource_database:
                    raise forms.ValidationError(
                        _(u"This urn cannot be found on the server you are currently accessing."
                          ))
                try:
                    Picture.load(urn)
                except DuctModelMismatchError:
                    raise forms.ValidationError(
                        _(u"This urn represents content that is not a picture."
                          ))
                # fixme: handle exception raised by get_resource_object if it's
                # actually a blob
                self.urn = urn
                return

        # this should never be reached
        assert self.handles(self.uri)
コード例 #2
0
ファイル: forms.py プロジェクト: jennspics/ductus
 def save(self, save_context):
     if self.cleaned_data['uri'] != '':
         # either we have a uri (like a flickr picture)
         return self.handler.save(save_context)
     if self.cleaned_data['file'] is not None:
         # or it's a local file we need to save
         pic = Picture()
         pic.blob.store(iter(self.cleaned_data['file'].chunks()))
         pic.blob.mime_type = self.cleaned_data['file'].ductus_mime_type
         pic.common.patch_from_blueprint(None, save_context)
         return pic.save()
コード例 #3
0
ファイル: forms.py プロジェクト: antiface/ductus
 def save(self, save_context):
     if self.cleaned_data['uri'] != '':
         # either we have a uri (like a flickr picture)
         return self.handler.save(save_context)
     if self.cleaned_data['file'] is not None:
         # or it's a local file we need to save
         pic = Picture()
         pic.blob.store(iter(self.cleaned_data['file'].chunks()))
         pic.blob.mime_type = self.cleaned_data['file'].ductus_mime_type
         pic.common.patch_from_blueprint(None, save_context)
         return pic.save()
コード例 #4
0
ファイル: flickr.py プロジェクト: antiface/ductus
 def save(self, save_context, picture=None, return_before_saving=False):
     photo = self.photo
     if picture is None:
         picture = Picture()
     img_url = photo.original_url or photo.large_url or photo.medium_url
     picture.blob.store(iterate_file_object(urlopen(img_url)))
     picture.blob.mime_type = 'image/jpeg'
     license_elt = picture.common.licenses.new_item()
     license_elt.href = photo['license']
     picture.common.licenses.array = [license_elt]
     picture.common.patch_from_blueprint(None, save_context)
     picture.credit.title.text = photo['title']['_content']
     picture.credit.original_url.href = photo.page_url
     picture.credit.author.text = "%(realname)s (%(username)s)" % photo['owner']
     picture.credit.author_url.href = photo.userpage_url
     if photo['rotation'] and photo.original_url:
         picture.rotation = unicode(360 - int(photo['rotation']))
     if return_before_saving:
         return
     return picture.save()
コード例 #5
0
ファイル: forms.py プロジェクト: antiface/ductus
    def validate(self):
        from ductus.resource import get_resource_database
        from ductus.resource.ductmodels import DuctModelMismatchError
        resource_database = get_resource_database()

        for r in self._re_objects:
            match = r.match(self.uri)
            if match is not None:
                hash_type, digest = match.group(1), match.group(2)
                urn = "urn:%s:%s" % (hash_type, digest)
                if urn not in resource_database:
                    raise forms.ValidationError(_(u"This urn cannot be found on the server you are currently accessing."))
                try:
                    Picture.load(urn)
                except DuctModelMismatchError:
                    raise forms.ValidationError(_(u"This urn represents content that is not a picture."))
                # fixme: handle exception raised by get_resource_object if it's
                # actually a blob
                self.urn = urn
                return

        # this should never be reached
        assert self.handles(self.uri)
コード例 #6
0
def edit_picture(request):
    if request.method == 'POST':
        form = PictureRotationForm(request.POST)
        if form.is_valid() and "parent" in request.POST:
            save_context = BlueprintSaveContext.from_request(request)
            blueprint = {
                'resource': {
                    '@patch': request.POST["parent"],
                    'rotation': form.cleaned_data['rotation'],
                }
            }
            urn = Picture.save_blueprint(blueprint, save_context)
            return SuccessfulEditRedirect(urn)
    else:
        form = PictureRotationForm()

    return render_to_response('picture/edit.html', {
        'form': form,
        'parent_urn': request.ductus.resource.urn,
    }, RequestContext(request))
コード例 #7
0
ファイル: edit_views.py プロジェクト: antiface/ductus
def edit_picture(request):
    if request.method == 'POST':
        form = PictureRotationForm(request.POST)
        if form.is_valid() and "parent" in request.POST:
            save_context = BlueprintSaveContext.from_request(request)
            blueprint = {
                'resource': {
                    '@patch': request.POST["parent"],
                    'rotation': form.cleaned_data['rotation'],
                }
            }
            urn = Picture.save_blueprint(blueprint, save_context)
            return SuccessfulEditRedirect(urn)
    else:
        form = PictureRotationForm()

    return render_to_response('picture/edit.html', {
        'form': form,
        'parent_urn': request.ductus.resource.urn,
    }, RequestContext(request))