示例#1
0
 def _video_update_thumbnail(self):
     cache.clear()
     try:
         thumbnail_url = 'http://img.youtube.com/vi/%s/hqdefault.jpg' % self.code.strip()
         req = urllib2.Request(thumbnail_url)
         obj = urllib2.urlopen(req).read()
         image_saved = save_image_file(thumbnail_url, 'media')
         if image_saved.get('code') == 1:
             self.image = image_saved.get('image_url')
             self.save(update_fields=['image'])
         return True
     except Exception, error:
         return False
示例#2
0
 def _video_update_thumbnail(self):
     cache.clear()
     try:
         thumbnail_url = 'http://img.youtube.com/vi/%s/hqdefault.jpg' % self.code.strip()
         req = urllib2.Request(thumbnail_url)
         obj = urllib2.urlopen(req).read()
         image_saved = save_image_file(thumbnail_url, 'media')
         if image_saved.get('code') == 1:
             self.image = image_saved.get('image_url')
             self.save(update_fields=['image'])
         return True
     except Exception, error:
         return False
示例#3
0
def save_product(request):
    message = {
        'code': 0,
        'link': {},
        'back_text': _('Add more Products'),
        'message': _("Product hasn't been saved"),
    }

    product_form = ProductForm(request.POST or None)
    if product_form.is_valid():
        try:
            #Get information for Product
            title = request.POST.get('title')
            slug = slugify(title)
            description = request.POST.get('description')
            image_url_from_web = urllib.unquote(
                request.POST.get('image')).decode('utf8')

            product_class = get_or_create_product_class()

            #Save product object
            product = Product(title=title,
                              slug=slug,
                              description=description,
                              product_class=product_class,
                              user_id=request.user.pk)
            product.save()

            save_image = save_image_file(image_url_from_web, 'product')

            if save_image.get('code') == 1:
                product_image = ProductImage(
                    product=product,
                    original=save_image.get('image_url'),
                    caption=title,
                    display_order=0)
                product_image.save()

            message = {
                'code': 1,
                'object_id': product.id,
                'link': {
                    'url': '/catalogue/%s_%d/' % (slug, product.id),
                    'text': _('See the product')
                },
                'back_text': _('Add more Products'),
                'message': _('Product has been saved'),
            }
        except Exception, err:
            pass
示例#4
0
def save_product(request):
    message = {
        'code': 0,
        'link': {},
        'back_text': _('Add more Products'),
        'message': _("Product hasn't been saved"),
    }

    product_form = ProductForm(request.POST or None)
    if product_form.is_valid():
        try:
            #Get information for Product
            title = request.POST.get('title')
            slug = slugify(title)
            description = request.POST.get('description')
            image_url_from_web = urllib.unquote(request.POST.get('image')).decode('utf8')

            product_class = get_or_create_product_class()

            #Save product object
            product = Product(title=title, slug=slug, description=description, product_class=product_class, user_id=request.user.pk)
            product.save()

            save_image = save_image_file(image_url_from_web, 'product')

            if save_image.get('code') == 1:
                product_image = ProductImage(product=product, original=save_image.get('image_url'), caption=title, display_order=0)
                product_image.save()

            message = {
                'code': 1,
                'object_id': product.id,
                'link': {'url': '/catalogue/%s_%d/' % (slug, product.id), 'text': _('See the product')},
                'back_text': _('Add more Products'),
                'message': _('Product has been saved'),
            }
        except Exception, err:
            pass