Beispiel #1
0
def create_product(shop):
    category = Category()
    category.title = 'test_title'
    category.description = 'test_description'
    category.shop = shop.id
    category.save()
    product = Product()
    product.title = 'test_title'
    product.description = 'test_description'
    product.category = category.id
    product.price = 1000
    product.image = 'test_image'
    product.save()
    return product
Beispiel #2
0
def add_category():
    status_code = 0
    error_msg = 'error'
    try:
        ins = Category()
        ins.title = getparms('title','new category')
        ins.sort_num = int(getparms('sort_num','0'))
        ins.join_date = datetime.now()
        ins.status = 1
        ins.save()
        status_code = 1
        error_msg = '成功'
    except Exception as e:
        error_msg = '出错了 %r' % e
    result = {'status_code':status_code,'msg':error_msg }
    return  jsonify(result)
Beispiel #3
0
 def test_create(self):
     """
     Test a category creation
     """
     shop = create_shop()
     category = Category()
     category.title = 'test_title'
     category.description = 'test_description'
     category.shop = shop.id
     category.save()
     storage.close()
     savedCat = shop.categories[0]
     self.assertIsNotNone(savedCat)
     us = storage.get(User, shop.user)
     storage.delete(us)
     storage.save()
     storage.close()
Beispiel #4
0
 def test_products(self):
     """
     Test the products @property
     """
     shop = create_shop()
     category = Category()
     category.title = 'test_title'
     category.description = 'test_description'
     category.shop = shop.id
     category.save()
     product = Product()
     product.title = 'test_title'
     product.description = 'test_description'
     product.price = 1000
     product.category = category.id
     product.image = 'test_image'
     product.save()
     storage.close()
     savedProd = category.products[0]
     self.assertEqual(savedProd.id, product.id)
     us = storage.get(User, shop.user)
     storage.delete(us)
     storage.save()
     storage.close()
Beispiel #5
0
#!/usr/bin/python3

from models.category import Category

CA = Category()
CA.save()
print(CA.to_dict())
Beispiel #6
0
class Controller:
    def __init__(self):
        self.category = Category()

    def create(self, request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            data['creator'] = res['data']['username']
            result = self.category.save(data)
            if result == None:
                return response({}, code=50000, message='该分类已存在!')
            return response({}, code=20000, message='创建成功!')
        else:
            return p

    def getList(self, request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.find(data)
            return response(result, code=20000, message='获取成功!')
        else:
            return p
    def delete(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.delete(data)
            print(type(result))
            return response({}, code=20000, message='删除成功!')
        else:
            return p
    def edit(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.update_one(data['id'],data)
            if result == None:
                return response({}, code=50000, message='该分类已存在!')
            return response({}, code=20000, message='修改成功!')
        else:
            return p
    def delete(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.delete(data)
            print(type(result))
            return response({}, code=20000, message='删除成功!')
        else:
            return p
    def getCascader(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            results=self.category.findAll()
            series = []
            for result in results:
                series.append(result['series'])
            formatList = list({}.fromkeys(series).keys())
            data = []
            for i in formatList:
                children = []
                for result in results:
                    if result['series'] == i:
                        children.append({"label": result['label'], "value": result['value']})
                data.append({"value": i, "label": i, "children": children})
            return response(data, code=20000, message='获取成功!')
        else:
            return p
Beispiel #7
0
###
fr.subcat = [savoie, calvados, idf]
savoie.subcat = [restausav, coiffsav]
calvados.subcat = [restaucal, lavcal]
idf.subcat = [restauidf, superidf]

uk.subcat = [eng, scot, ireland]

ita.subcat = [milan, turin, roma]

root = Category()
root.subcat = [fr, uk, ita]

for c in savoie.subcat + calvados.subcat + idf.subcat:
    if c.name not in Translation.objects:
        c.name.save()
    c.save()

for c in fr.subcat + uk.subcat + ita.subcat:
    if c.name not in Translation.objects:
        c.name.save()
    c.save()

for c in [fr, uk, ita]:
    if c.name not in Translation.objects:
        c.name.save()
    c.save()

root.is_root = True
root.save()
Beispiel #8
0
#!/usr/bin/python3
from models.category import Category
from models.tags import Tag
from models.user import User
from models.product import Products
CAT = Category()
CAT.label = "a8888"
TA = Tag()
TA.label = "azzzabi"
PRO = Products()
US = User()
US.email = "AZEAZEAZEAZEAZEAZE"
US.password = "******"
PRO.user_id = US.id
tag_id = TA.id
category_id = CAT.id
title = "zazazaz"
description = "hjdbfjfe"
CAT.save()
TA.save()
US.save()
PRO.save()

print(CAT.to_dict())
print(TA.to_dict())
print(US.to_dict())
print(PRO.to_dict())
Beispiel #9
0
def create_category():
    """
    Creates a new category linked to a shop
    create a shop if the user doesn't have one
    ---
    parameters:
      - in: header
        name: authorization
        required: true
        schema:
          type: string
      - in: query
        name: title
        required: true
        schema:
          type: string
      - in: query
        name: description
        required: true
        schema:
          type: string
    responses:
      200:
        description: the category was saved succefully
        schema:
          type: object
          parameters:
            id:
              type: string
              example: 1239102941-1231290412-dfs12rf-123re-1234r223
      400:
        description: incomplete request
        schema:
          type: object
          parameters:
            message:
              type: string
              example: incomplete request
    """
    state = request.get_json()
    user = request.user
    # tests the input values
    print(state)
    if not state['title'] or not state['description']:
        return jsonify(message="incomplete request"), 400
    # verify the store for the user
    shops = storage.filter_by(Shop, 'user', user)
    shop = None
    for shp in shops:
        if shp.user == user:
            shop = shp
    # if shop doesn't exists create a new instance
    if not shop:
        shop = Shop()
        shop.user = user
        shop.save()
    # Create the Category instance
    category = Category()
    category.title = state['title']
    category.description = state['description']
    category.shop = shop.id
    category.save()
    return jsonify(id=category.id)
Beispiel #10
0
#Pylint: disable=C0302
from app import app, db
from models.user import UserSchema
from models.category import Category
from models.sale import Sale

user_schema = UserSchema()

with app.app_context():
    db.drop_all()
    db.create_all()

    #Category seeds.........................................
    lunch = Category(type='Lunch', logo='assets/cupcake.png')
    lunch.save()
    coffee = Category(type='Coffee', logo='assets/coffee.png')
    coffee.save()
    food = Category(type='Food', logo='assets/cutlery.png')
    food.save()
    shopping = Category(type='Shopping', logo='assets/shopping-bag.png')
    shopping.save()
    fitness = Category(type='Fitness', logo='assets/weightlifting.png')
    fitness.save()
    entertainment = Category(type='Entertainment', logo='assets/ticket.png')
    entertainment.save()
    plants = Category(type='Plants', logo='assets/plant.png')
    plants.save()
    bars = Category(type='Bars', logo='assets/glass.png')
    bars.save()
    clothes = Category(type='Clothes', logo='assets/hanger.png')
    clothes.save()