All posts by Social marketing master

Jquery Uncaught reference errors in google chrome

I’ve been using jquery for this web design project and there’s one problem I’ve been running into. The script works just fine in safari, though in firefox and google chrome I get a uncaught reference error. I’ve read in few places that it might be charset of the script, but when I changed the charset nothing would happened. Has anyone else had this problem? If somebody knows a good fix to this problem help would be appreciated.

Here’s the script I’m working with:

$(function ($) {
    'use strict';
    var slidebar = new $.slidebars({siteClose: true, scrollLock: true});
    $('i.button').on('click', function () {
        slidebar.slidebars.toggle('left');
    });
});
$(function PYLoad() {
    'use strict';
    $.ajax({
        url: 'http://127.0.0.1:8000/json',
        type: 'GET',
        success: function (data) {
            console.log("PY_Load has Loaded successfully...");
            console.log(data);
            if (data.green === "green") {
                    $('#PY_Load').addClass('server-status-green').removeClass('server-status-red server-status-red-blink default');
            };
            if (data.red === "red") {
                $('#PY_Load').addClass('server-status-red').removeClass('server-status-green server-status-red-blink default');
            };
            if (data.blink === "blink") {
                $('#PY_Load').addClass('server-status-red- blink').removeClass('server-status-green server-status-red default');
            };
            if (data.default === "default") {
                $('#PY_Load').addClass('default').removeClass('server-status-green server-status-red server-status-red-blink');
            };
        },
        complete: function () {
            console.log('Reloading...');
            setTimeout(PYLoad, 3000);
        }
     });
});

read more

Query works fine in phpmyadmin but does not work in PHP

I have this query

$sql = "SELECT inv.GLOBA_SKU_NUM as sku, inv.LIST_PRICE as price , inv.WEIGHT as weight, st_st.STYLE_NAME_FR as style_fr, st_st.STYLE_NAME_EN as style_en, att_sec.SECTION_FR as section_fr, att_sec.SECTION_en as section_en, att_prod_type.product_type_en as product_type_en, att_prod_type.product_type_fr as product_type_fr, att_prod_type.product_type_en as product_type_en, att_prod_type.product_type_fr as product_type_fr, att_att.ATTRIBUTE_ID as attribute_id, att_att.ATTRIBUTE_NAME_FR as attribute_name_fr, att_att.ATTRIBUTE_NAME_EN as attribute_name_en, att_val.VALUE_EN as value_en, att_val.VALUE_FR as value_fr, st_st.STYLE_DESCRIPTION_FR as style_description_fr, st_st.STYLE_DESCRIPTION_en as style_description_en FROM 0099903_inventory inv LEFT JOIN 0099903_attributes att ON (inv.`GLOBA_SKU_NUM` = att.`GLOBA_SKU_NUM`) LEFT JOIN 0099903_attributes_attributes att_att ON(att.`ATTRIBUTE_ID` = att_att.`ATTRIBUTE_ID`) LEFT JOIN 0099903_attributes_values att_val ON (att_val.`VALUE_ID` = att.`VALUE_ID`) LEFT JOIN 0099903_attributes_product_type att_prod_type ON (att.`PRODUCT_TYPE_ID` = att_prod_type.PRODUCT_TYPE_ID) LEFT JOIN 0099903_attributes_sections att_sec ON (att_prod_type.`SECTION_ID` = att_sec.`SECTION_ID`) LEFT JOIN 0099903_styles st ON (st.`GLOBA_SKU_NUM` = att.`GLOBA_SKU_NUM`) LEFT JOIN 0099903_styles_styles st_st ON (st_st.`STYLE_ID` = st.`STYLE_ID`) where st_st.brand = 'CKX' ";

when i run it on Phpmyadmin – i get back the rows as expected. But when doing a query with PHP – i do not get any result.

 $rs = $this->dbh->query($sql, PDO::FETCH_ASSOC);
 return $rs->fetchAll();

if i change the above $sql to a simple select statement it works fine.

Query works fine in phpmyadmin but does not work in PHP

Django ORM – Dynamically add When to Case

I have a list of lists

my_list= [
    [1,2,3],
    [4,5,6],
    ...
]

I’d like to annotate some values like this:

from django.db.models import CharField, Case, When, Value

MyModel.objects.filter(...).annotate(label=Case(When(some_value__in=my_list[0] then=Value('first list')), output_field=CharField()))

Now I need add a similar When for the other lists in my_list, but my_list could have different lengths.

How could I do this?

Django ORM – Dynamically add When to Case

Django ORM – Dynamically add When to Case

I have a list of lists

my_list= [
    [1,2,3],
    [4,5,6],
    ...
]

I’d like to annotate some values like this:

from django.db.models import CharField, Case, When, Value

MyModel.objects.filter(...).annotate(label=Case(When(some_value__in=my_list[0] then=Value('first list')), output_field=CharField()))

Now I need add a similar When for the other lists in my_list, but my_list could have different lengths.

How could I do this?

Django ORM – Dynamically add When to Case