Ejemplo n.º 1
0
Archivo: admin.py Proyecto: gmist/f-toy
def categories(request):
    form = CategoryForm()
    if request.method == 'POST':
        if form.validate(request.form):
            form.save()
            form = CategoryForm()
    return render_to_response('gift/admin/category.html',
            {'form':form.as_widget(),
             'categories':Category.all().order('category')})
Ejemplo n.º 2
0
Archivo: views.py Proyecto: gmist/f-toy
def get_category(json_data):
    category = json_data.get('subcategory', '').replace('\\"', '"')
    if category:
        category_obs = Category.all().filter('category =', category)
        if not category_obs.count():
            category = Category(category=category)
            category.put()
        else:
            category = category_obs.get()
        return category
    return None
Ejemplo n.º 3
0
def get_clear_subs():
    subs = Category.all().order("order")
    clear_subs = []
    for sub_el in subs:
        if sub_el.gifts and sub_el.gifts.filter("in_trash =", False).filter("leftovers >", 0).count(limit=1):
            groups_tmp = sub_el.groups.order("name")
            groups = []
            for g in groups_tmp:
                gifts = accept_filters(g.gifts).count(limit=1)
                if gifts:
                    groups.append(g)
            clear_subs.append((sub_el, groups))
    return clear_subs
Ejemplo n.º 4
0
Archivo: views.py Proyecto: gmist/f-toy
def get_cat_subcat():
    categories_tmp = Category.all().order('category')
    categories = []
    for c in categories_tmp:
        if c.gift_category.filter('leftovers >', 0).count():
            categories.append(c)
    subcategories = {}
    subcategories_keys = {}
    for category in categories:
        subcat = []
        for sub in category.subcategories:
            if sub.gift_subcategory.filter('leftovers >', 0).count():
                subcat.append(sub.subcategory)
                subcategories_keys[sub.subcategory] = sub.key().id()
        if subcat:
            subcat.sort()
            subcategories[category.key().id()] = subcat
    return categories, subcategories, subcategories_keys
Ejemplo n.º 5
0
def import_data(in_file='quick_export.csv'):
    images_path = os.path.join(DEFAULT_PATH, 'images')
    reader = csv.reader(open(os.path.join(DEFAULT_PATH, in_file)))
    for i, line in enumerate(reader):
        if not i:
            continue
        uid = line[0]
        gift_imgs_path = os.path.join(images_path, uid)
        try:
            imgs_files = os.listdir(gift_imgs_path)
        except OSError:
            imgs_files = []
        name = line[2].decode('utf-8')
        category = line[3].decode('utf-8')
        subcategory = line[4].decode('utf-8')
        brand = line[5].decode('utf-8')

        if line[6]:
            price = float(line[6])
        else:
            price = 0.0

        size = line[9].decode('utf-8')
        if not size:
            size = u''
        desc = line[10].decode('utf-8')

        if line[11]:
            rating = float(line[11])
        else:
            rating = 3.0
            
        if imgs_files:
            imgs_files =\
            [open(os.path.join(gift_imgs_path, img), 'rb').read() \
             for img in imgs_files]

        if brand:
            brand_obj = Brand.all().filter('brand =', brand)
            if not brand_obj.count():
                brand_obj = Brand(brand=brand)
                brand_obj.put()
            else:
                brand_obj = brand_obj[0]
        else:
            brand_obj = None

        if category:
            category_obj = Category.all().filter('category =', category)
            if category_obj.count():
                category_obj = category_obj[0]
            else:
                category_obj = Category(category=category)
                category_obj.put()
        else:
            category_obj = None

        if category and subcategory:
            subcategory_obj = Subcategory.all().filter('subcategory =', subcategory).filter('on_category =', category_obj)
            if subcategory_obj.count():
                subcategory_obj = subcategory_obj[0]
            else:
                subcategory_obj = Subcategory(subcategory=subcategory, on_category=category_obj)
                subcategory_obj.put()
        else:
            subcategory_obj = None

        gift = Gift(name=name,
                    uid_5studio=uid,
                    brand=brand_obj,
                    category=category_obj,
                    subcategory=subcategory_obj,
                    description=desc,
                    rating=rating,
                    price=price,
                    size=size)
        gift.put()

        if gift.name:
            title = gift.name.replace('"', '"')
        else:
            title = ''
        content_type = 'image/jpeg'
        for thumb in imgs_files:
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            if not gift.thumbs.count():
                thumb_img.main_gift = gift
            thumb_img.gift = gift
            thumb_img.put()