Example #1
0
def product_add(request):
    """
    Add a new product to the DB
    Will return the single product on success
    """
    xml = XMLRenderer()

    prodname = request.POST.get('product', None)
    if not prodname:
        return xml.error('Cannot add an empty product name', errno=103)

    # check languages
    langs = request.POST.getlist('languages')
    locales = product_details.languages.keys()
    if [ l for l in langs if l not in locales ]:
        return xml.error('invalid language code(s)', errno=103)

    # save new product
    products = Product.objects.filter(name__exact=prodname)
    if not products:
        try:
            prod = Product(name=prodname)
            prod.save()
            for lang in langs:
                prod.languages.create(lang=lang)
        except Exception, e:
            return xml.error(e)
        products = Product.objects.filter(pk=prod.pk)
Example #2
0
def product_add(request):
    """
    Add a new product to the DB
    Will return the single product on success
    """
    xml = XMLRenderer()

    prodname = request.POST.get("product", None)
    if not prodname:
        return xml.error("Cannot add an empty product name", errno=103)

    # check languages
    langs = request.POST.getlist("languages")
    locales = product_details.languages.keys()
    ssl_only = bool(request.POST.get("ssl_only", False) == "true")
    if [l for l in langs if l not in locales]:
        return xml.error("invalid language code(s)", errno=103)

    # save new product
    products = Product.objects.filter(name__exact=prodname)
    if not products:
        try:
            prod = Product(name=prodname, ssl_only=ssl_only)
            prod.save()
            for lang in langs:
                prod.languages.create(lang=lang)
        except Exception, e:
            return xml.error(e)
        products = Product.objects.filter(pk=prod.pk)
def product_add(request):
    """
    Add a new product to the DB
    Will return the single product on success
    """
    xml = XMLRenderer()

    prodname = request.POST.get('product', None)
    if not prodname:
        return xml.error('Cannot add an empty product name', errno=103)

    # check languages
    langs = request.POST.getlist('languages')
    locales = product_details('languages').keys()
    ssl_only = bool(request.POST.get('ssl_only', False) == "true")
    if [l for l in langs if l not in locales]:
        return xml.error('invalid language code(s)', errno=103)

    # save new product
    products = Product.objects.filter(name__exact=prodname)
    if not products:
        try:
            prod = Product(name=prodname, ssl_only=ssl_only)
            prod.save()
            for lang in langs:
                prod.languages.create(lang=lang)
        except Exception, e:
            return xml.error(e)
        products = Product.objects.filter(pk=prod.pk)
Example #4
0
    def setUp(self):
        super(ProductTestCase, self).setUp()

        self.locales = ("ar", "da", "vi")

        # products
        self.products = []
        for i in range(1, 11):
            name = "Product-%s-%s" % (i, i % 2 and "odd" or "even")
            p = Product(name=name)
            p.save()

            for lang in self.locales:
                p.languages.create(lang=lang)

            self.products.append(p)
Example #5
0
    def setUp(self):
        super(ProductTestCase, self).setUp()

        self.locales = ('ar', 'da', 'vi')

        # products
        self.products = []
        for i in range(1, 11):
            name = 'Product-%s-%s' % (i, i % 2 and 'odd' or 'even')
            p = Product(name=name)
            p.save()

            for lang in self.locales:
                p.languages.create(lang=lang)

            self.products.append(p)
Example #6
0
    def setUp(self):
        super(ProductTestCase, self).setUp()

        self.locales = ('ar', 'da', 'vi')

        # products
        self.products = []
        for i in range(1, 11):
            name = 'Product-%s-%s' % (i, i % 2 and 'odd' or 'even')
            p = Product(name=name)
            p.save()

            for lang in self.locales:
                p.languages.create(lang=lang)

            self.products.append(p)