Esempio n. 1
0
 def define_main_image(self, archive_link, save=False, *args, **kwargs):
     image = Image(title=u"{0}-{1}".format(self.title, self.id),
                   slug=u"{0}-{1}".format(self.slug, self.id),
                   user=self.user,
                   site=self.site,
                   archive_link=_url_fix(archive_link),
                   **kwargs)
     image.save()
     self.main_image = image
     if save:
         self.save()
     return image
Esempio n. 2
0
def image_create(request, container_pk):

    container = get_object_or_404(Container, pk=int(container_pk))
    if request.method == "POST":
        f = request.FILES.get('image')

        title = request.POST.get('title') or container.title
        caption = request.POST.get('caption', '')
        source = request.POST.get('source', '')
        tags = request.POST.get('tags', '')
        slug = slugify(title)
        slug = "{0}-{1}".format(slug[:100], random.getrandbits(32))

        instance = Image(
            site=container.site,
            user=container.user,
            date_available=container.date_available,
            title=title,
            slug=slug,
            archive=f,
            source=source,
            published=True,
            tags=tags,
        )
        instance.save()

        order = request.POST.get('order', 0)
        ContainerImage.objects.create(container=container,
                                      image=instance,
                                      caption=caption,
                                      order=int(order))

        data = [{
            'name':
            f.name,
            'url':
            "%s" % instance.archive.url,
            'thumbnail_url':
            "%s" % image_url(instance.archive.url, width=60, height=60),
            "delete_url":
            "",
            "delete_type":
            "DELETE"
        }]
        response = JSONResponse(data, {}, response_mimetype(request))
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response
    else:
        return render(request, 'fileupload/image_form.html',
                      {'container': container})
Esempio n. 3
0
 def define_main_image(self, archive_link, save=False, *args, **kwargs):
     image = Image(
         title=u"{0}-{1}".format(self.title, self.id),
         slug=u"{0}-{1}".format(self.slug, self.id),
         user=self.user,
         site=self.site,
         archive_link=archive_link,
         **kwargs
     )
     image.save()
     self.main_image = image
     if save:
         self.save()
     return image
Esempio n. 4
0
File: views.py Progetto: bgomes/opps
def image_create(request, container_pk):

    container = get_object_or_404(Container, pk=int(container_pk))
    if request.method == "POST":
        f = request.FILES.get('image')

        title = request.POST.get('title') or container.title
        caption = request.POST.get('caption', '')
        source = request.POST.get('source', '')
        tags = request.POST.get('tags', '')
        slug = slugify(title)
        slug = "{0}-{1}".format(slug[:100], random.getrandbits(32))

        instance = Image(
            site=container.site,
            user=container.user,
            date_available=container.date_available,
            title=title,
            slug=slug,
            archive=f,
            source=source,
            published=True,
            tags=tags,
        )
        instance.save()

        order = request.POST.get('order', 0)
        ContainerImage.objects.create(
            container=container,
            image=instance,
            caption=caption,
            order=int(order)
        )

        data = [{'name': f.name,
                 'url': "%s" % instance.archive.url,
                 'thumbnail_url': "%s" % image_url(
                     instance.archive.url,
                     width=60,
                     height=60
                 ),
                 "delete_url": "",
                 "delete_type": "DELETE"}]
        response = JSONResponse(data, {}, response_mimetype(request))
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response
    else:
        return render(request, 'fileupload/image_form.html',
                      {'container': container})
Esempio n. 5
0
def image_create(request, article_pk=None):

    if article_pk:
        article = get_object_or_404(Article, pk=int(article_pk))
        title = article.title
        site = article.site
        user = request.user or article.user
        date_available = article.date_available
    else:
        article = None
        title = 'Uploaded Image'
        site = get_current_site(request)
        user = request.user
        date_available = timezone.now()

    if request.method == "POST":
        f = request.FILES.get('image')

        title = request.POST.get('title') or title
        caption = request.POST.get('caption', '')

        source = request.POST.get('source', None)
        if source:
            qs = Source.objects.filter(name=source, site=site)
            if qs:
                source = qs[0]
            else:
                source = Source.objects.create(
                    name=source,
                    slug=slugify(source),
                    user=request.user,
                    published=True
                )

        slug = slugify(title)
        slug = "{0}-{1}".format(slug[:100], random.getrandbits(32))

        instance = Image(
            site=site,
            user=user,
            date_available=date_available,
            title=title,
            slug=slug,
            image=f,
            published=True,
        )
        if source:
            instance.source = source
        
        if caption:
            instance.description = caption

        instance.save()

        if article:
            order = request.POST.get('order', 0)
            ArticleImage.objects.create(
                article=article,
                image=instance,
                caption=caption,
                order=int(order)
            )

        data = [{'name': f.name,
                 'url': "%s" % instance.image.url,
                 'thumbnail_url': "%s" % image_url(
                     instance.image.url,
                     width=60,
                     height=60
                 ),
                 "delete_url": "",
                 "delete_type": "DELETE"}]
        response = JSONResponse(data, {}, response_mimetype(request))
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response
    else:
        return render(request, 'fileupload/image_form.html',
                      {'article': article})
Esempio n. 6
0
def image_create(request, article_pk=None):

    if article_pk:
        article = get_object_or_404(Article, pk=int(article_pk))
        title = article.title
        site = article.site
        user = request.user or article.user
        date_available = article.date_available
    else:
        article = None
        title = 'Uploaded Image'
        site = get_current_site(request)
        user = request.user
        date_available = timezone.now()

    if request.method == "POST":
        f = request.FILES.get('image')

        title = request.POST.get('title') or title
        caption = request.POST.get('caption', '')

        source = request.POST.get('source', None)
        if source:
            qs = Source.objects.filter(name=source, site=site)
            if qs:
                source = qs[0]
            else:
                source = Source.objects.create(name=source,
                                               slug=slugify(source),
                                               user=request.user,
                                               published=True)

        slug = slugify(title)
        slug = "{0}-{1}".format(slug[:100], random.getrandbits(32))

        instance = Image(
            site=site,
            user=user,
            date_available=date_available,
            title=title,
            slug=slug,
            image=f,
            published=True,
        )
        if source:
            instance.source = source

        if caption:
            instance.description = caption

        instance.save()

        if article:
            order = request.POST.get('order', 0)
            ArticleImage.objects.create(article=article,
                                        image=instance,
                                        caption=caption,
                                        order=int(order))

        data = [{
            'name':
            f.name,
            'url':
            "%s" % instance.image.url,
            'thumbnail_url':
            "%s" % image_url(instance.image.url, width=60, height=60),
            "delete_url":
            "",
            "delete_type":
            "DELETE"
        }]
        response = JSONResponse(data, {}, response_mimetype(request))
        response['Content-Disposition'] = 'inline; filename=files.json'
        return response
    else:
        return render(request, 'fileupload/image_form.html',
                      {'article': article})