def get_style_json(style_id=-1): try: style = sqlobject_to_dict(BJCPStyle.get(style_id)) except SQLObjectNotFound: style = {'error': 'There is no style for id %s' % style_id} return json.dumps(style)
def list_ingredients(ingredient): c = { 'hop': [ 'Hop', ], 'grain': [ 'Grain', ], 'extract': [ 'Extract', ], 'hoppedextract': ['HoppedExtract'], 'mineral': [ 'Mineral', ], 'herb': [ 'Herb', ], 'spice': [ 'Spice', ], 'flavor': [ 'Flavor', ], 'fining': [ 'Fining', ], 'yeast': [ 'Yeast', ], } c['misc'] = c['mineral'] + c['herb'] + c['spice'] + c['fining'] + c[ 'flavor'] c['fermentable'] = c['grain'] + c['extract'] + c['hoppedextract'] data = [] try: for model in c[ingredient]: data += list(globals()[model].select().orderBy('name')) except KeyError: all_ingredients = { 'error': 'No ingredients exist with the name %s' % ingredient } else: all_ingredients = [sqlobject_to_dict(ing) for ing in data] return json.dumps(all_ingredients)
def list_ingredients(ingredient): c = { "hop": ["Hop"], "grain": ["Grain"], "extract": ["Extract"], "hoppedextract": ["HoppedExtract"], "mineral": ["Mineral"], "herb": ["Herb"], "spice": ["Spice"], "flavor": ["Flavor"], "fining": ["Fining"], "yeast": ["Yeast"], } c["misc"] = c["mineral"] + c["herb"] + c["spice"] + c["fining"] + c["flavor"] c["fermentable"] = c["grain"] + c["extract"] + c["hoppedextract"] data = [] try: for model in c[ingredient]: data += list(globals()[model].select().orderBy("name")) except KeyError: all_ingredients = {"error": "No ingredients exist with the name %s" % ingredient} else: all_ingredients = [sqlobject_to_dict(ing) for ing in data] return json.dumps(all_ingredients)
def pymodel_as_json(model): model_name = model[0].capitalize()+model[1:] model_instance = globals()[model_name]() pydict = sqlobject_to_dict(model_instance).keys() pydict.append('id') return json.dumps(pydict)
def pymodel_as_json(model): model_name = model[0].capitalize() + model[1:] model_instance = globals()[model_name]() pydict = sqlobject_to_dict(model_instance).keys() pydict.append('id') return json.dumps(pydict)