def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
     Partner = orm['partner.Partner']
     for partner in Partner.objects.all():
         partner.code = slugify(partner.name)
         partner.save()
Beispiel #2
0
def save_video(request):
    video_form = VideoForm(request.POST or None)
    if video_form.is_valid():
        title = request.POST['title']
        video_slug = slugify(title)
        video_code = request.POST['video_code']
        description = request.POST['description']
        user = request.user
        trending = request.POST['video_is_trending']
        image_url_from_web = urllib.unquote(
            request.POST['image']).decode('utf8')
        url_thumb = render_thumb_path(image_url_from_web)
        save_thumb(image_url_from_web, url_thumb)
        video = Video(title=title,
                      slug=video_slug,
                      url=video_code,
                      thumb=url_thumb,
                      description=description,
                      user=user,
                      is_trending=trending)
        video.save()

        video_link = "/video/%s/" % video.pk
        return {
            'code':
            1,
            'pro_link':
            u'<a href="%s" class="f-button close" target="_blank">%s</a>' %
            (video_link, u'See the video'),
            'back_text':
            u'Add more Videos',
            'mes_box':
            u'<h1>Video has been saved!</h1>',
        }
Beispiel #3
0
    def form_valid(self, form):
        """
        Store new flatpage from form data. Checks wether a site
        is specified for the flatpage or sets the current site by
        default. Additionally, if URL is left blank, a slugified
        version of the title will be used as URL after checking
        if it is valid.
        """
        # if no URL is specified, generate from title
        page = form.save(commit=False)

        if not page.url:
            page.url = '/%s/' % slugify(page.title)

        try:
            URLDoesNotExistValidator()(page.url)
        except ValidationError:
            pass
        else:
            # use current site as default for new page
            page.save()
            page.sites.add(Site.objects.get_current())

            return HttpResponseRedirect(self.get_success_url(page))

        ctx = self.get_context_data()
        ctx['form'] = form
        return self.render_to_response(ctx)
Beispiel #4
0
def save_facebook_image(image_params, user):

    image = None
    try:
        title = image_params.get('title')
        slug = slugify(title)
        image_url = image_params.get('url')
        description = image_params.get('description')

        image_url_from_web = urllib.unquote(image_url).decode('utf8')
        image_path = ''
        saved = save_image_file(image_url, 'media')
        if saved.get('code') == 1:
            image_path = saved.get('image_url')

        image = CollectionMedia(title=title,
                                slug=slug,
                                type='image',
                                image=image_path,
                                description=description,
                                user=user)
        image.save()

        return image
    except Exception, err:
        pass
Beispiel #5
0
    def is_slug_conflicting(self, name, ref_node_pk, position):
        # determine parent
        if ref_node_pk:
            ref_category = Category.objects.get(pk=ref_node_pk)
            if position == 'first-child':
                parent = ref_category
            else:
                parent = ref_category.get_parent()
        else:
            parent = None

        # build full slug
        slug_prefix = ''
        if parent:
            slug_prefix = (parent.slug + Category._slug_separator)
        slug = '%s%s' % (slug_prefix, slugify(name))

        # check if slug is conflicting
        try:
            category = Category.objects.get(slug=slug)
        except Category.DoesNotExist:
            pass
        else:
            if category.pk != self.instance.pk:
                return True
        return False
Beispiel #6
0
 def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
     Partner = orm['partner.Partner']
     for partner in Partner.objects.all():
         partner.code = slugify(partner.name)
         partner.save()
Beispiel #7
0
    def save(self, update_slugs=True, *args, **kwargs):
        if update_slugs:
            parent = self.get_parent()
            slug = slugify(self.name)
            # If category has a parent, includes the parents slug in this one
            if parent:
                self.slug = '%s%s%s' % (
                    parent.slug, self._slug_separator, slug)
                self.full_name = '%s%s%s' % (
                    parent.full_name, self._full_name_separator, self.name)
            else:
                self.slug = slug
                self.full_name = self.name

        # Enforce slug uniqueness here as MySQL can't handle a unique index on
        # the slug field
        try:
            match = self.__class__.objects.get(slug=self.slug)
        except self.__class__.DoesNotExist:
            pass
        else:
            if match.id != self.id:
                raise ValidationError(
                    _("A category with slug '%(slug)s' already exists") % {
                        'slug': self.slug})

        super(AbstractCategory, self).save(*args, **kwargs)
Beispiel #8
0
    def form_valid(self, form):
        """
        Store new flatpage from form data. Checks wether a site
        is specified for the flatpage or sets the current site by
        default. Additionally, if URL is left blank, a slugified
        version of the title will be used as URL after checking
        if it is valid.
        """
        # if no URL is specified, generate from title
        page = form.save(commit=False)

        if not page.url:
            page.url = '/%s/' % slugify(page.title)

        try:
            URLDoesNotExistValidator()(page.url)
        except ValidationError:
            pass
        else:
            # use current site as default for new page
            page.save()
            page.sites.add(Site.objects.get_current())

            return HttpResponseRedirect(self.get_success_url(page))

        ctx = self.get_context_data()
        ctx['form'] = form
        return self.render_to_response(ctx)
Beispiel #9
0
    def form_valid(self, form):
        """
        Store new flatpage from form data.
        Additionally, if URL is left blank, a slugified
        version of the title will be used as URL after checking
        if it is valid.
        从表单数据存储新的flatpage。 此外,如果URL留空,则在检查
        标题是否有效后,将使用标题的嵌入版本作为URL。
        """
        # if no URL is specified, generate from title
        # 如果未指定URL,则从title生成
        page = form.save(commit=False)

        if not page.url:
            page.url = '/%s/' % slugify(page.title)

        try:
            URLDoesNotExistValidator()(page.url)
        except ValidationError:
            pass
        else:
            return super().form_valid(form)

        ctx = self.get_context_data()
        ctx['form'] = form
        return self.render_to_response(ctx)
Beispiel #10
0
def create_product_class(apps, schema_editor):
    """Create a Coupon product class."""
    for klass in (Category, ProductAttribute, ProductClass):
        klass.skip_history_when_saving = True

    coupon = ProductClass(
        track_stock=False,
        requires_shipping=False,
        name=COUPON_PRODUCT_CLASS_NAME,
        slug=slugify(COUPON_PRODUCT_CLASS_NAME),
    )
    coupon.save()

    pa = ProductAttribute(product_class=coupon,
                          name='Coupon vouchers',
                          code='coupon_vouchers',
                          type='entity',
                          required=False)
    pa.save()

    # Create a category for coupons.
    c = Category(description='All Coupons',
                 slug='coupons',
                 depth=1,
                 path='0002',
                 image='',
                 name='Coupons')
    c.save()
Beispiel #11
0
    def save(self, update_slugs=True, *args, **kwargs):
        if update_slugs:
            parent = self.get_parent()
            slug = slugify(self.name)
            # If category has a parent, includes the parents slug in this one
            if parent:
                self.slug = '%s%s%s' % (
                    parent.slug, self._slug_separator, slug)
                self.full_name = '%s%s%s' % (
                    parent.full_name, self._full_name_separator, self.name)
            else:
                self.slug = slug
                self.full_name = self.name

        # Enforce slug uniqueness here as MySQL can't handle a unique index on
        # the slug field
        try:
            match = self.__class__.objects.get(slug=self.slug)
        except self.__class__.DoesNotExist:
            pass
        else:
            if match.id != self.id:
                raise ValidationError(
                    _("A category with slug '%(slug)s' already exists") % {
                        'slug': self.slug})

        super(AbstractCategory, self).save(*args, **kwargs)
Beispiel #12
0
 def enrollment_code_product_class(self):
     attributes = (('seat_type', 'text'), ('course_key', 'text'),
                   ('id_verification_required', 'boolean'))
     product_class = self._create_product_class(
         ENROLLMENT_CODE_PRODUCT_CLASS_NAME,
         slugify(ENROLLMENT_CODE_PRODUCT_CLASS_NAME), attributes)
     return product_class
Beispiel #13
0
    def is_slug_conflicting(self, name, ref_node_pk, position):
        # determine parent
        if ref_node_pk:
            ref_category = Category.objects.get(pk=ref_node_pk)
            if position == 'first-child':
                parent = ref_category
            else:
                parent = ref_category.get_parent()
        else:
            parent = None

        # build full slug
        slug_prefix = ''
        if parent:
            slug_prefix = (parent.slug + Category._slug_separator)
        slug = '%s%s' % (slug_prefix, slugify(name))

        # check if slug is conflicting
        try:
            category = Category.objects.get(slug=slug)
        except Category.DoesNotExist:
            pass
        else:
            if category.pk != self.instance.pk:
                return True
        return False
Beispiel #14
0
def create_product_class(apps, schema_editor):  # pylint: disable=unused-argument
    """ Create a donation product class for donations from checkout tests """
    Category = apps.get_model("catalogue", "Category")
    ProductClass = apps.get_model("catalogue", "ProductClass")

    ProductClass.skip_history_when_saving = True
    Category.skip_history_when_saving = True

    # Create a new product class for donations for the donations from checkout tests
    donation, __ = ProductClass.objects.get_or_create(
        track_stock=False,
        requires_shipping=False,
        name=DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME,
        slug=slugify(DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME)
    )

    # Create a category for donations.
    c = Category(
        description="All donations",
        slug="donations",
        image="",
        name="Donations",
        depth=1,
        path='0004',
    )
    c.save()
def create_product_class(apps, schema_editor):
    """ Create a course entitlement product class """

    # Create a new product class for course entitlement
    course_entitlement = ProductClass.objects.create(
        track_stock=False,
        requires_shipping=False,
        name=COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME,
        slug=slugify(COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME)
    )

    # Create product attributes for course entitlement products
    ProductAttribute.objects.create(
        product_class=course_entitlement,
        name="course_key",
        code="course_key",
        type="text",
        required=True
    )
    ProductAttribute.objects.create(
        product_class=course_entitlement,
        name="certificate_type",
        code="certificate_type",
        type="text",
        required=False
    )

    # Create a category for course entitlements
    Category.add_root(
        description="All course entitlements",
        slug="course_entitlements",
        image="",
        name="Course Entitlements"
    )
def create_enrollment_code_product_class(apps, schema_editor):
    """Create an Enrollment code product class and switch to turn automatic creation on."""
    for klass in (Category, ProductAttribute, ProductClass):
        klass.skip_history_when_saving = True

    enrollment_code = ProductClass(
        track_stock=False,
        requires_shipping=False,
        name=ENROLLMENT_CODE_PRODUCT_CLASS_NAME,
        slug=slugify(ENROLLMENT_CODE_PRODUCT_CLASS_NAME),
    )
    enrollment_code.save()

    pa1 = ProductAttribute(product_class=enrollment_code,
                           name='Course Key',
                           code='course_key',
                           type='text',
                           required=True)
    pa1.save()

    pa2 = ProductAttribute(product_class=enrollment_code,
                           name='Seat Type',
                           code='seat_type',
                           type='text',
                           required=True)
    pa2.save()
def create_product_class(apps, schema_editor):
    """ Create a course entitlement product class """
    for klass in (Category, ProductAttribute, ProductClass):
        klass.skip_history_when_saving = True

    # Create a new product class for course entitlement
    course_entitlement = ProductClass(
        track_stock=False,
        requires_shipping=False,
        name=COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME,
        slug=slugify(COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME))
    course_entitlement.save()

    # Create product attributes for course entitlement products
    pa1 = ProductAttribute(product_class=course_entitlement,
                           name="course_key",
                           code="course_key",
                           type="text",
                           required=True)
    pa1.save()

    pa2 = ProductAttribute(product_class=course_entitlement,
                           name="certificate_type",
                           code="certificate_type",
                           type="text",
                           required=False)
    pa2.save()

    # Create a category for course entitlements
    Category.add_root(description="All course entitlements",
                      slug="course_entitlements",
                      image="",
                      name="Course Entitlements")
Beispiel #18
0
class ShippingEventTypeFactory(factory.django.DjangoModelFactory):
    name = 'Test event'
    code = factory.LazyAttribute(lambda o: slugify(o.name).replace('-', '_'))

    class Meta:
        model = get_model('order', 'ShippingEventType')
        django_get_or_create = ('code', )
Beispiel #19
0
def save_media(request, type=None):
    try:
        user = request.user
        video_code = request.POST.get('id')
        title = request.POST.get('title')
        video_slug = slugify(title)
        if 'vine' in request.POST:
            video_slug = 'vine'
        description = request.POST.get('description') or ''
        image = None
        if 'image' in request.POST:
            image_url = urllib.unquote(request.POST.get('image')).decode('utf8')
            saved = save_image_file(image_url, 'media')
            if saved.get('code') == 1:
                image = saved.get('image_url')

        video = CollectionMedia(title=title, slug=video_slug, type=type, code=video_code.strip(), user=user, description=description, image=image)
        video.save()

        if image is None and video_slug != 'vine':
            video._video_update_thumbnail()

        return render_to_response('collection/media/add_media_return.html',
                                  {
                                      'media_obj': video,
                                      'message': {'code': 1, 'type': type}
                                  }, context_instance=RequestContext(request))
    except Exception, error:
        return HttpResponse(json.dumps({'code': 0, 'type': type}), mimetype='application/json')
Beispiel #20
0
    def coupon_product_class(self):
        defaults = {'requires_shipping': False, 'track_stock': False, 'name': COUPON_PRODUCT_CLASS_NAME}
        pc, created = ProductClass.objects.get_or_create(
            name=COUPON_PRODUCT_CLASS_NAME, slug=slugify(COUPON_PRODUCT_CLASS_NAME), defaults=defaults
        )

        if created:
            factories.ProductAttributeFactory(
                code='coupon_vouchers',
                name='Coupon vouchers',
                product_class=pc,
                type='entity'
            )
            factories.ProductAttributeFactory(
                code='note',
                name='Note',
                product_class=pc,
                type='text'
            )
            factories.ProductAttributeFactory(
                product_class=pc,
                name='Notification Email',
                code='notify_email',
                type='text'
            )

        return pc
Beispiel #21
0
    def clean_code(self):
        code = self.cleaned_data.get("code")
        title = self.cleaned_data.get("name")

        if not code and title:
            code = slugify(title)

        return code
Beispiel #22
0
    def clean_code(self):
        code = self.cleaned_data.get("code")
        title = self.cleaned_data.get("name")

        if not code and title:
            code = slugify(title)

        return code
 def _get_or_create_product_attribute(self, product_class, attributes):
     for attr in attributes.split(';'):
         attr_name = attr.split(':')[0].strip()
         attr_type = attr.split(':')[1].strip()
         pa, created = ProductAttribute.objects.get_or_create(product_class=product_class,
                                                             name=attr_name,
                                                             type=attr_type,
                                                             code=slugify(attr_name))
Beispiel #24
0
 def entitlement_product_class(self):
     attributes = (
         ('certificate_type', 'text'),
         ('UUID', 'text'),
     )
     product_class = self._create_product_class(
         COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME,
         slugify(COURSE_ENTITLEMENT_PRODUCT_CLASS_NAME), attributes)
     return product_class
Beispiel #25
0
def imp_product_template(client, filter = None):
    oe_mod_name = 'product.template'
    oe_mod_fieds = ['type']
    oe_mod_val = get_oe_mod_val(client, oe_mod_name, oe_mod_fieds)
    oscar_mod = oscar.apps.catalogue.models.ProductClass
    for i in range(0, len(oe_mod_val)):
        oscar_mod_obj = oscar_mod.objects.get_or_create(id = i)[0]
        oscar_mod_obj.name = oe_mod_val[i]['type']
        oscar_mod_obj.slug = slugify(oe_mod_val[i]['type'])
        oscar_mod_obj.save()
Beispiel #26
0
def imp_product_template(client, filter=None):
    oe_mod_name = 'product.template'
    oe_mod_fieds = ['type']
    oe_mod_val = get_oe_mod_val(client, oe_mod_name, oe_mod_fieds)
    oscar_mod = oscar.apps.catalogue.models.ProductClass
    for i in range(0, len(oe_mod_val)):
        oscar_mod_obj = oscar_mod.objects.get_or_create(id=i)[0]
        oscar_mod_obj.name = oe_mod_val[i]['type']
        oscar_mod_obj.slug = slugify(oe_mod_val[i]['type'])
        oscar_mod_obj.save()
Beispiel #27
0
def create_catalog(apps, schema_editor):
    """

    Create all the Product Types, Products, Attributes, Categories, and other data models we need out of the
    box for the EdX Catalog. This data migration will create the "Seat" type, along with our
    default product, a DemoX Course and Seat with an Honor Certificate.

    """
    Category = apps.get_model("catalogue", "Category")
    ProductAttribute = apps.get_model("catalogue", "ProductAttribute")
    ProductClass = apps.get_model("catalogue", "ProductClass")

    for klass in (Category, ProductAttribute, ProductClass):
        klass.skip_history_when_saving = True

    # Create a new product class for course seats
    seat = ProductClass(track_stock=False,
                        requires_shipping=False,
                        name=SEAT_PRODUCT_CLASS_NAME,
                        slug=slugify(SEAT_PRODUCT_CLASS_NAME))
    seat.save()

    # Create product attributes for course seat products
    pa1 = ProductAttribute(product_class=seat,
                           name="course_key",
                           code="course_key",
                           type="text",
                           required=True)
    pa1.save()

    pa2 = ProductAttribute(product_class=seat,
                           name="id_verification_required",
                           code="id_verification_required",
                           type="boolean",
                           required=False)
    pa2.save()

    pa3 = ProductAttribute(product_class=seat,
                           name="certificate_type",
                           code="certificate_type",
                           type="text",
                           required=False)
    pa3.save()

    # Create a category for course seats
    c = Category(description="All course seats",
                 numchild=1,
                 slug="seats",
                 depth=1,
                 full_name="Course Seats",
                 path="0001",
                 image="",
                 name="Seats")
    c.save()
Beispiel #28
0
def get_or_create_product_class():
    #Product class
    products = ProductClass.objects.all()
    if len(products) > 0:
        product_class = products[0]
    else:
        pro_cls_name = u'Default'
        pro_cls_slug = slugify(pro_cls_name)
        product_class = ProductClass(name=pro_cls_name, slug=pro_cls_slug)
        product_class.save()

    return product_class
Beispiel #29
0
    def get(self, request, *args, **kwargs):
        voucher_set = self.get_object()

        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = (
            'attachment; filename="%s.csv"' % slugify(voucher_set.name))

        writer = csv.writer(response)
        for code in voucher_set.vouchers.values_list('code', flat=True):
            writer.writerow([code])

        return response
Beispiel #30
0
 def seat_product_class(self):
     attributes = (
         ('certificate_type', 'text'),
         ('course_key', 'text'),
         ('credit_provider', 'text'),
         ('id_verification_required', 'boolean'),
         ('credit_hours', 'integer'),
     )
     product_class = self._create_product_class(
         SEAT_PRODUCT_CLASS_NAME, slugify(SEAT_PRODUCT_CLASS_NAME),
         attributes)
     return product_class
Beispiel #31
0
def get_or_create_product_class():
    #Product class
    products = ProductClass.objects.all()
    if len(products) > 0:
        product_class = products[0]
    else:
        pro_cls_name = u'Default'
        pro_cls_slug = slugify(pro_cls_name)
        product_class = ProductClass(name=pro_cls_name, slug=pro_cls_slug)
        product_class.save()

    return product_class
Beispiel #32
0
    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)

        # Check to see if consumption thresholds have been broken
        if not self.is_suspended:
            if self.get_max_applications() == 0:
                self.status = self.CONSUMED
            else:
                self.status = self.OPEN

        return super(ConditionalOffer, self).save(*args, **kwargs)
Beispiel #33
0
    def get(self, request, *args, **kwargs):
        voucher_set = self.get_object()

        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = ('attachment; filename="%s.csv"' %
                                           slugify(voucher_set.name))

        writer = csv.writer(response)
        for code in voucher_set.vouchers.values_list('code', flat=True):
            writer.writerow([code])

        return response
Beispiel #34
0
def create_product_class(apps, schema_editor):  # pylint: disable=unused-argument
    """ Create a donation product class for donations from checkout tests """

    # Create a new product class for donations for the donations from checkout tests
    donation, __ = ProductClass.objects.get_or_create(
        track_stock=False,
        requires_shipping=False,
        name=DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME,
        slug=slugify(DONATIONS_FROM_CHECKOUT_TESTS_PRODUCT_TYPE_NAME))

    Category.add_root(description="All donations",
                      slug="donations",
                      image="",
                      name="Donations")
Beispiel #35
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
Beispiel #36
0
    def save(self, *args, **kwargs):
        if self.is_top_level and not self.title:
            raise ValidationError(_("Canonical products must have a title"))
        if not self.slug:
            self.slug = slugify(self.get_title())

        # Validate attributes if necessary
        self.attr.validate_attributes()

        # Save product
        super(AbstractProduct, self).save(*args, **kwargs)

        # Finally, save attributes
        self.attr.save()
Beispiel #37
0
    def save(self, *args, **kwargs):
        if self.is_top_level and not self.title:
            raise ValidationError(_("Canonical products must have a title"))
        if not self.slug:
            self.slug = slugify(self.get_title())

        # Validate attributes if necessary
        self.attr.validate_attributes()

        # Save product
        super(AbstractProduct, self).save(*args, **kwargs)

        # Finally, save attributes
        self.attr.save()
 def update_slug(self, commit=True):
     """
     Updates the instance's slug. Use update_children_slugs for updating
     the rest of the tree.
     """
     parent = self.get_parent()
     slug = slugify(self.name)
     # If category has a parent, includes the parents slug in this one
     if parent:
         self.slug = "%s%s%s" % (parent.slug, self._slug_separator, slug)
         self.full_name = "%s%s%s" % (parent.full_name, self._full_name_separator, self.name)
     else:
         self.slug = slug
         self.full_name = self.name
     if commit:
         self.save()
    def save(self, *args, **kwargs):
        if self.is_top_level and not self.title:
            raise ValidationError(_("Canonical products must have a title"))
        if not self.slug:
            self.slug = slugify(self.get_title())

        # Allow attribute validation to be skipped.  This is required when
        # saving a parent product which belongs to a product class with
        # required attributes.
        if kwargs.pop('validate_attributes', True):
            self.attr.validate_attributes()

        # Save product
        super(AbstractProduct, self).save(*args, **kwargs)

        # Finally, save attributes
        self.attr.save()
Beispiel #40
0
    def save(self, *args, **kwargs):
        if self.is_top_level and not self.title:
            raise ValidationError(_("Canonical products must have a title"))
        if not self.slug:
            self.slug = slugify(self.get_title())

        # Allow attribute validation to be skipped.  This is required when
        # saving a parent product which belongs to a product class with
        # required attributes.
        if not self.is_group and kwargs.pop('validate_attributes', True):
            self.attr.validate_attributes()

        # Save product
        super(AbstractProduct, self).save(*args, **kwargs)

        # Finally, save attributes
        self.attr.save()
Beispiel #41
0
 def update_slug(self, commit=True):
     """
     Updates the instance's slug. Use update_children_slugs for updating
     the rest of the tree.
     """
     parent = self.get_parent()
     slug = slugify(self.name)
     # If category has a parent, includes the parents slug in this one
     if parent:
         self.slug = '%s%s%s' % (parent.slug, self._slug_separator, slug)
         self.full_name = '%s%s%s' % (parent.full_name,
                                      self._full_name_separator, self.name)
     else:
         self.slug = slug
         self.full_name = self.name
     if commit:
         self.save()
Beispiel #42
0
def save_media(request, type=None):
    try:
        user = request.user
        video_code = request.POST.get('id')
        title = request.POST.get('title')
        video_slug = slugify(title)
        if 'vine' in request.POST:
            video_slug = 'vine'
        description = request.POST.get('description') or ''
        image = None
        if 'image' in request.POST:
            image_url = urllib.unquote(
                request.POST.get('image')).decode('utf8')
            saved = save_image_file(image_url, 'media')
            if saved.get('code') == 1:
                image = saved.get('image_url')

        video = CollectionMedia(title=title,
                                slug=video_slug,
                                type=type,
                                code=video_code.strip(),
                                user=user,
                                description=description,
                                image=image)
        video.save()

        if image is None and video_slug != 'vine':
            video._video_update_thumbnail()

        return render_to_response('collection/media/add_media_return.html', {
            'media_obj': video,
            'message': {
                'code': 1,
                'type': type
            }
        },
                                  context_instance=RequestContext(request))
    except Exception, error:
        return HttpResponse(json.dumps({
            'code': 0,
            'type': type
        }),
                            mimetype='application/json')
Beispiel #43
0
def save_video(request):
    message = {
        'code': 0,
        'link': {},
        'back_text': _('Add more Videos'),
        'message': _("Video hasn't been saved"),
    }
    video_form = CollectionVideo_Form(request.POST or None)
    if video_form.is_valid():
        try:
            image_url = urllib.unquote(
                request.POST.get('image')).decode('utf8')
            saved = save_image_file(image_url, 'media')
            if saved.get('code') == 1:
                title = request.POST.get('title')
                video_slug = slugify(title)
                image_url = saved.get('image_url')
                video_code = request.POST.get('video_code')
                description = request.POST.get('description')
                user = request.user

                video = CollectionMedia(title=title,
                                        slug=video_slug,
                                        type='video',
                                        code=video_code.strip(),
                                        image=image_url,
                                        description=description,
                                        user=user)
                video.save()

                message = {
                    'code': 1,
                    'object_id': video.pk,
                    'hash_tag_thumb_url': image_url,
                    'link': {
                        'url': "/collection/media/video/%s/" % video.pk,
                        'text': _('See the video')
                    },
                    'back_text': _('Add more Videos'),
                    'message': _('Video has been saved'),
                }
        except Exception, err:
            pass
Beispiel #44
0
def save_facebook_image(image_params, user):

    image = None
    try:
        title = image_params.get('title')
        slug = slugify(title)
        image_url = image_params.get('url')
        description = image_params.get('description')

        image_url_from_web = urllib.unquote(image_url).decode('utf8')
        image_path = ''
        saved = save_image_file(image_url, 'media')
        if saved.get('code') == 1:
            image_path = saved.get('image_url')

        image = CollectionMedia(title=title, slug=slug, type='image', image=image_path, description=description, user=user)
        image.save()

        return image
    except Exception, err:
        pass
Beispiel #45
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
Beispiel #46
0
    def form_valid(self, form):
        """
        Store new flatpage from form data.
        Additionally, if URL is left blank, a slugified
        version of the title will be used as URL after checking
        if it is valid.
        """
        # if no URL is specified, generate from title
        page = form.save(commit=False)

        if not page.url:
            page.url = '/%s/' % slugify(page.title)

        try:
            URLDoesNotExistValidator()(page.url)
        except ValidationError:
            pass
        else:
            return super().form_valid(form)

        ctx = self.get_context_data()
        ctx['form'] = form
        return self.render_to_response(ctx)
Beispiel #47
0
def save_image(request):

    message = {
        'code': 0,
        'link': {},
        'back_text': _('Add more Images'),
        'message': _("Image hasn't been saved"),
    }
    image_form = CollectionImage_Form(request.POST or None)
    if image_form.is_valid():
        try:
            host_path = get_host_path_of_inside_image(request)
            image_url = host_path + request.POST.get('image')
            image_url = urllib.unquote(image_url).decode('utf8')
            saved = save_image_file(image_url, 'media')
            if saved.get('code') == 1:
                title = request.POST.get('title')
                slug = slugify(title)
                description = request.POST.get('description')
                user = request.user
                image_url = saved.get('image_url')
                do_crop_image(request, image_url)
                image = CollectionMedia(title=title, slug=slug, type='image', image=image_url, description=description, user=user)
                image.save()
                message = {
                    'code': 1,
                    'object_id': image.pk,
                    'link': {
                        'url': "/collection/media/images/",
                        'text': _('View the images')
                    },
                    'back_text': _('Add more Images'),
                    'message': _('Image has been saved'),
                }

        except Exception, err:
            pass
Beispiel #48
0
def save_video(request):
    message = {
        'code': 0,
        'link': {},
        'back_text': _('Add more Videos'),
        'message': _("Video hasn't been saved"),
    }
    video_form = CollectionVideo_Form(request.POST or None)
    if video_form.is_valid():
        try:
            image_url = urllib.unquote(request.POST.get('image')).decode('utf8')
            saved = save_image_file(image_url, 'media')
            if saved.get('code') == 1:
                title = request.POST.get('title')
                video_slug = slugify(title)
                image_url = saved.get('image_url')
                video_code = request.POST.get('video_code')
                description = request.POST.get('description')
                user = request.user

                video = CollectionMedia(title=title, slug=video_slug, type='video', code=video_code.strip(), image=image_url, description=description, user=user)
                video.save()

                message = {
                    'code': 1,
                    'object_id': video.pk,
                    'hash_tag_thumb_url': image_url,
                    'link': {
                        'url': "/collection/media/video/%s/" % video.pk,
                        'text': _('See the video')
                    },
                    'back_text': _('Add more Videos'),
                    'message': _('Video has been saved'),
                }
        except Exception, err:
            pass
Beispiel #49
0
 def save(self, *args, **kwargs):
     if not self.code:
         self.code = slugify(self.name)
     super(AbstractShippingEventType, self).save(*args, **kwargs)
 def salvataggio_genera_slug(self, Model):
     el1 = crea_modello(Model, name="Piero")
     
     el_saved = Model.objects.filter(name='Piero')
     self.assertEqual(el_saved[0].slug, slugify(el1.name))
Beispiel #51
0
 def save(self, *args, **kwargs):
     if not self.code:
         self.code = slugify(self.name)
     super(AbstractSourceType, self).save(*args, **kwargs)
Beispiel #52
0
 def save(self, *args, **kwargs):
     if not self.code:
         self.code = slugify(self.name)
     super(ShippingMethod, self).save(*args, **kwargs)
Beispiel #53
0
 def slugify_func(self, content):
     if content:
         return slugify(content)
     return ''
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.name)
     super(AbstractAttributeEntityType, self).save(*args, **kwargs)
 def save(self, *args, **kwargs):
     if not self.code:
         self.code = slugify(self.name)
     super(AbstractOption, self).save(*args, **kwargs)
Beispiel #56
0
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.get_title())
     super(AbstractProduct, self).save(*args, **kwargs)
     self.attr.save()
Beispiel #57
0
 def generate_slug(self):
     """
     Generates a slug for a category. This makes no attempt at generating
     a unique slug.
     """
     return slugify(self.name)
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.name)
     super(AbstractContributor, self).save(*args, **kwargs)
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.name)
     return super(AbstractProductClass, self).save(*args, **kwargs)
Beispiel #60
0
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.get_title())
     super().save(*args, **kwargs)
     self.attr.save()