Пример #1
0
def get_property(request, property_name):
    if request.method == 'PUT':
        model = simplejson.loads(request.data)
        pr_obj = ProductProperty.get_by_id(property_name)
        if not pr_obj:
            return render_json_response({
                'api_success': False,
                'api_msg': "Property %s not found." % property_name
            })
        pr_obj.title = model['title']
        pr_obj.units = model['units']
        pr_obj.put()
        return render_json_response({
            'api_success': True,
            'api_msg': 'Property %s updated' % model['id']
        })

    if request.method == 'DELETE':
        pr_obj = ProductProperty.get_by_id(property_name)
        if not pr_obj:
            return render_json_response({
                'api_success': False,
                'api_msg': "Property %s not found." % property_name
            })
        pr_obj.key.delete()
        return render_json_response({
            'api_success': True,
            'api_msg': "Property %s deleted" % property_name
        })
Пример #2
0
def create_value(request, property_key):
    if request.method == 'POST':
        model = simplejson.loads(request.data)
        property_obj = ProductProperty.get_by_id(property_key)
        value = ProductPropertyValue(title=model['title'],
            property=property_obj.key)
        value.put()
        return render_json_response(value.to_json())
Пример #3
0
def create(data, is_unique_title=False):
    title = data.get('title', '')
    if not title:
        res = {'api_success':False,
             'api_msg':'"Field title" is required',
             'api_function':create.__name__}
        logging.warning(res)
        return render_json_response(res)
    property = ProductProperty.get_by_id(data.get('property', ''))
    if is_unique_title and is_value_exist(title, property.key):
        res = {'api_success':False,
             'api_msg':'Field "title" must be unique',
             'api_function':create.__name__}
        logging.warning(res)
        return render_json_response(res)

    value = ProductPropertyValue(title=title, property=property.key)
    value.put()
    res = {'api_success': True,
                'api_msg': 'Value "%s" created' % title,
                'property': value.to_json()}
    logging.info(res)
    return render_json_response(res)
Пример #4
0
def get_values(request, property_key):
    property_obj = ProductProperty.get_by_id(property_key)
    values = ProductPropertyValue.query( ProductPropertyValue.property == property_obj.key )
    values = [value.to_json() for value in values]
    return render_json_response(values)
Пример #5
0
def product_property_add_val(request, prop_key):
    prop_obj = ProductProperty.get_by_id(prop_key)
    return render_to_response(
            'shop/admin/property_value.html',
            {'property':prop_obj})
Пример #6
0
def values_json(request, property_id):
    property_obj = ProductProperty.get_by_id(property_id)
    values = [value.to_json() for value in property_obj.values.order(ProductPropertyValue.title)]
    return render_json_response(values)