Example #1
0
def admin_thumbnail(request):
    content = u''
    if request.method == 'POST' and request.is_ajax():
        form = ThumbnailForm(request.POST)
        if not form.is_valid():
            return HttpResponseBadRequest(form.errors)
        data = form.cleaned_data

        obj = data['id']
        dimensions = '%sx%s' % (data['width'], data['height'])

        if obj.type == 'image':
            image = None
            try:
                image = feincms_thumbnail.thumbnail(obj.file.name, dimensions)
            except:
                pass

            if image:
                try:
                    caption = obj.translation.caption
                except AttributeError:
                    caption = _(u'untitled').encode('utf-8')
                content = json.dumps({
                    'url': image.url,
                    'name': escapejs(caption)
                })
        return HttpResponse(content, content_type='application/json')
    else:
        return HttpResponseForbidden()
Example #2
0
    def render(self, name, value, attrs=None):
        inputfield = super(MediaFileWidget, self).render(name, value, attrs)
        if value:
            try:
                mf = MediaFile.objects.get(pk=value)
                try:
                    caption = mf.translation.caption
                except ObjectDoesNotExist:
                    caption = _('(no caption)')

                if mf.type == 'image':
                    image = feincms_thumbnail.thumbnail(mf.file.name, '240x120')
                    image = u'<img src="%(url)s" alt="" /><br />' % {'url': image}
                else:
                    image = u''

                return mark_safe(u"""
                    <div style="margin-left:10em">%(image)s
                    <a href="%(url)s" target="_blank">%(caption)s (%(url)s)</a><br />
                    %(inputfield)s
                    </div>""" % {
                        'image': image,
                        'url': mf.file.url,
                        'caption': caption,
                        'inputfield': inputfield})
            except:
                pass

        return inputfield
Example #3
0
    def render(self, name, value, attrs=None):
        inputfield = super(MediaFileWidget, self).render(name, value, attrs)
        if value:
            try:
                mf = MediaFile.objects.get(pk=value)
            except MediaFile.DoesNotExist:
                return inputfield

            try:
                caption = mf.translation.caption
            except (ObjectDoesNotExist, AttributeError):
                caption = _("(no caption)")

            if mf.type == "image":
                image = feincms_thumbnail.thumbnail(mf.file.name, "188x142")
                image = u"background: url(%(url)s) center center no-repeat;" % {"url": image}
            else:
                image = u""

            return mark_safe(
                u"""
                <div style="%(image)s" class="admin-gallery-image-bg absolute">
                <p class="admin-gallery-image-caption absolute">%(caption)s</p>
                %(inputfield)s</div>"""
                % {"image": image, "caption": caption, "inputfield": inputfield}
            )

        return inputfield
Example #4
0
    def render(self, name, value, attrs=None):
        inputfield = super(MediaFileWidget, self).render(name, value, attrs)
        if value:
            try:
                mf = MediaFile.objects.get(pk=value)
            except MediaFile.DoesNotExist:
                return inputfield

            try:
                caption = mf.translation.caption
            except (ObjectDoesNotExist, AttributeError):
                caption = _('(no caption)')

            if mf.type == 'image':
                image = feincms_thumbnail.thumbnail(mf.file.name, '188x142')
                image = u'background: url(%(url)s) center center no-repeat;' % {'url': image}
            else:
                image = u''

            return mark_safe(u"""
                <div style="%(image)s" class="admin-gallery-image-bg absolute">
                <p class="admin-gallery-image-caption absolute">%(caption)s</p>
                %(inputfield)s</div>""" % {
                    'image': image,
                    'caption': caption,
                    'inputfield': inputfield})

        return inputfield
Example #5
0
    def render(self, name, value, attrs=None):
        inputfield = super(MediaFileWidget, self).render(name, value, attrs)
        if value:
            try:
                mf = MediaFile.objects.get(pk=value)
            except MediaFile.DoesNotExist:
                return inputfield

            try:
                caption = mf.translation.caption
            except ObjectDoesNotExist:
                caption = _('(no caption)')

            if mf.type == 'image':
                image = feincms_thumbnail.thumbnail(mf.file.name, '188x142')
                image = u'background: url(%(url)s) center center no-repeat;' % {'url': image}
            else:
                image = u''

            return mark_safe(u"""
                <div style="%(image)s" class="admin-gallery-image-bg absolute">
                <p class="admin-gallery-image-caption absolute">%(caption)s</p>
                %(inputfield)s</div>""" % {
                    'image': image,
                    'caption': caption,
                    'inputfield': inputfield})

        return inputfield
Example #6
0
def admin_thumbnail(request):
    content = u''
    if request.method == 'POST' and request.is_ajax():
        form = ThumbnailForm(request.POST)
        if not form.is_valid():
            return HttpResponseBadRequest(form.errors)
        data = form.cleaned_data

        obj = data['id']
        dimensions = '%sx%s' % (data['width'], data['height'])

        if obj.type == 'image':
            image = None
            try:
                image = feincms_thumbnail.thumbnail(obj.file.name, dimensions)
            except:
                pass

            if image:
                content = json.dumps({
                    'url': image.url,
                    'name': escapejs(obj.translation.caption)
                    })
        return HttpResponse(content, mimetype='application/json')
    else:
        return HttpResponseForbidden()
Example #7
0
def admin_thumbnail(request):
    content = u""
    if request.method == "POST" and request.is_ajax():
        form = ThumbnailForm(request.POST)
        if not form.is_valid():
            return HttpResponseBadRequest(form.errors)
        data = form.cleaned_data

        obj = data["id"]
        dimensions = "%sx%s" % (data["width"], data["height"])

        if obj.type == "image":
            image = None
            try:
                image = feincms_thumbnail.thumbnail(obj.file.name, dimensions)
            except:
                pass

            if image:
                try:
                    caption = obj.translation.caption
                except AttributeError:
                    caption = _(u"untitled").encode("utf-8")
                content = json.dumps({"url": image.url, "name": escapejs(caption)})
        return HttpResponse(content, mimetype="application/json")
    else:
        return HttpResponseForbidden()
Example #8
0
    def render(self, name, value, attrs=None):
        inputfield = super(MediaFileWidget, self).render(name, value, attrs)
        if value:
            try:
                mf = MediaFile.objects.get(pk=value)
            except MediaFile.DoesNotExist:
                return inputfield

            try:
                caption = mf.translation.caption
            except (AttributeError, ObjectDoesNotExist):
                caption = _('(no caption)')

            if mf.type == 'image':
                image = feincms_thumbnail.thumbnail(mf.file.name, '240x120')
                image = u'<img src="%(url)s" alt="" /><br />' % {'url': image}
            else:
                image = u''

            return mark_safe(
                u"""
                <div style="margin-left:10em">%(image)s
                <a href="%(url)s" target="_blank">%(caption)s - %(url)s</a><br />
                %(inputfield)s
                </div>""" % {
                    'image': image,
                    'url': mf.file.url,
                    'caption': caption,
                    'inputfield': inputfield
                })

        return inputfield
Example #9
0
def admin_thumbnail(obj):
    if obj.type == 'image':
        image = feincms_thumbnail.thumbnail(obj.file.name, '80x80')
        return mark_safe(u"""
            <a href="%(url)s" target="_blank">
                <img src="%(image)s" alt="" />
            </a>""" % { 
                'url': obj.file.url,
                'image': image,})
    return ''
Example #10
0
    def label_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.to._default_manager.using(self.db).get(**{key: value})
            label = [u'&nbsp;<strong>%s</strong>' % escape(truncate_words(obj, 14))]

            if obj.type == 'image':
                image = feincms_thumbnail.thumbnail(obj.file.name, '240x120')
                label.append(u'<br /><img src="%s" alt="" style="margin:1em 0 0 10em" />' % image)

            return u''.join(label)
        except (ValueError, self.rel.to.DoesNotExist):
            return ''
Example #11
0
def admin_thumbnail(obj):
    if obj.type == 'image':
        image = None
        try:
            image = feincms_thumbnail.thumbnail(obj.file.name, '100x60')
        except:
            pass

        if image:
            return mark_safe(u"""
                <a href="%(url)s" target="_blank">
                    <img src="%(image)s" alt="" />
                </a>""" % {
                    'url': obj.file.url,
                    'image': image, })
    return ''
Example #12
0
def admin_thumbnail(obj):
    if obj.mediafile.type == 'image':
        image = None
        try:
            image = feincms_thumbnail.thumbnail(obj.mediafile.file.name, '100x100')
        except:
            pass

        if image:
            return mark_safe(u"""
                <a href="%(url)s&t=id" target="_blank">
                    <img src="%(image)s" alt="" />
                </a>""" % {
                    'url': obj.mediafile.file.url,
                    'image': image,})
    return ''
Example #13
0
def admin_thumbnail(obj):
    if obj.type == "image":
        image = None
        try:
            image = feincms_thumbnail.thumbnail(obj.file.name, "100x60")
        except:
            pass

        if image:
            return mark_safe(
                u"""
                <a href="%(url)s" target="_blank">
                    <img src="%(image)s" alt="" />
                </a>"""
                % {"url": obj.file.url, "image": image}
            )
    return ""
Example #14
0
    def label_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.to._default_manager.using(
                self.db).get(**{key: value})
            label = [
                u'&nbsp;<strong>%s</strong>' % escape(truncate_words(obj, 14))
            ]

            if obj.type == 'image':
                image = feincms_thumbnail.thumbnail(obj.file.name, '240x120')
                label.append(
                    u'<br /><img src="%s" alt="" style="margin:1em 0 0 10em" />'
                    % image)

            return u''.join(label)
        except (ValueError, self.rel.to.DoesNotExist):
            return ''
Example #15
0
 def thumb(self, obj):
     try:
         return u'<img src="%s" >' % thumbnail(obj.picture, '200x60')
     except ValueError:
         return u'No Image'
Example #16
0
def default_admin_thumbnail(mediafile):
    if mediafile.type != 'image':
        return None

    return feincms_thumbnail.thumbnail(mediafile.file, '100x100')
Example #17
0
def default_admin_thumbnail(mediafile, dimensions='100x100', **kwargs):
    if mediafile.type != 'image':
        return None

    return feincms_thumbnail.thumbnail(mediafile.file, dimensions)
Example #18
0
def default_admin_thumbnail(mediafile):
    if mediafile.type != 'image':
        return None

    return feincms_thumbnail.thumbnail(mediafile.file, '100x100')
Example #19
0
 def thumb(self, obj):
     try:
         return u'<img src="%s" >' % thumbnail(obj.picture, '200x60')
     except ValueError:
         return u'No Image'