def _parse_display_name(raw_input): value_key = 'display_name' old_value = raw_input.get(value_key) # Log.info("Old value for %s is %s" % (value_key, old_value)) if not raw_input: new_value = DisplayName('Unnamed Inventory') elif type(old_value) is str: new_value = DisplayName(old_value) else: raise ValidationException( "Bad display name given for inventory (%s)" % old_value) # Log.info("New value for %s is %s" % (value_key, new_value)) raw_input.update({value_key: new_value}) return raw_input
def __init__(self, slug, display_name=None, quantity=None, unit=None, notes=None): if not display_name: display_name = DisplayName(slug) if not notes: notes = [] self.slug = slug self.display_name = display_name self.quantity = quantity self.unit = unit self.notes = notes
def raw_to_obj(raw): raw_menu = MenuFactory.sanitize_raw(raw) if not raw_menu.get('display_name'): raw_menu.update({'display_name', DisplayName(raw_menu.get('slug'))}) menu_item_list = [] for raw_item in raw_menu.get('items'): mi = MenuItem(**raw_item) menu_item_list.append(mi) m = Menu(slug=raw_menu.get('slug'), display_name=raw_menu.get('display_name'), items=menu_item_list) return m
def _get_display_name(self): display_name = self.content.h3.next_element.strip() return DisplayName(display_name)
def raw_to_obj(raw_spec): # Tortuga Data Format v3 replaced all names with slugs, but it means that # the slugs for specs are not accurate. Same problem for ingredients. spec_slug = Slug(raw_spec['slug']) try: spec_display_name = raw_spec['display_name'] except KeyError: spec_display_name = DisplayName(spec_slug) raw_spec = SpecFactory.sanitize_raw(raw_spec) if raw_spec['origin'] is not None: origin_obj = Origin(**raw_spec['origin']) else: origin_obj = Origin() glassware_obj_list = [] for glassware in raw_spec['glassware']: if type(glassware) is dict: glassware_obj_list.append(Glassware(**glassware)) else: glassware_slug = Slug(glassware) glassware_display_name = DisplayName(glassware_slug) glassware_obj_list.append( Glassware(slug=glassware_slug, display_name=glassware_display_name)) components = [] # ingredients == specingredient == component. Yay evolution for raw_ingredient in raw_spec['components']: try: component_slug = Slug(raw_ingredient['name']) component_display_name = DisplayName(component_slug) del (raw_ingredient['name']) notes = [] if 'notes' in raw_ingredient.keys(): notes = [Text(**note) for note in raw_ingredient['notes']] del (raw_ingredient['notes']) spec_ing_obj = SpecComponent( slug=component_slug, display_name=component_display_name, notes=notes, **raw_ingredient) except KeyError: notes = [] if 'notes' in raw_ingredient.keys(): notes = [Text(**note) for note in raw_ingredient['notes']] raw_ingredient.update({'notes': notes}) raw_ingredient.update( {'slug': Slug(raw_ingredient.get('slug'))}) spec_ing_obj = SpecComponent(**raw_ingredient) components.append(spec_ing_obj) # print(ingredient_obj_list) c_obj_list = CitationFactory.raw_list_to_obj(raw_spec['citations']) # print(c_obj_list) n_obj_list = [] for note in raw_spec['notes']: if type(note) is dict: n_obj_list.append(Text(**note)) elif type(note) is Text: n_obj_list.append(note) else: n_obj_list.append(Text(text=note)) # print(n_obj_list) straw = SpecFactory.infer_bool(raw_spec['straw']) # print(straw) garnish_obj_list = [] for raw_garnish in raw_spec['garnish']: if 'notes' in raw_garnish.keys(): notes = [] for raw_note in raw_garnish.get('notes'): notes.append(Text(**raw_note)) raw_garnish['notes'] = notes garnish_obj = SpecComponent(**raw_garnish) garnish_obj_list.append(garnish_obj) # print(garnish_obj_list) instr_obj_list = [] for instruction in raw_spec['instructions']: if type(instruction) is dict: instr_obj_list.append(Text(**instruction)) elif type(instruction) is Text: instr_obj_list.append(instruction) else: instr_obj_list.append(Text(text=instruction)) # print(instr_obj_list) if type(raw_spec['construction']) is dict: construction_obj = Construction(**raw_spec['construction']) elif type(raw_spec['construction']) is None: construction_obj = Construction(slug='unknown') else: construction_obj = Construction(slug=raw_spec['construction']) image_obj_list = [] for image in raw_spec['images']: image_obj_list.append(Image(**image)) s_obj = Spec( slug=spec_slug, display_name=spec_display_name, origin=origin_obj, glassware=glassware_obj_list, components=components, citations=c_obj_list, notes=n_obj_list, straw=straw, garnish=garnish_obj_list, instructions=instr_obj_list, construction=construction_obj, images=image_obj_list, ) return s_obj
def __init__(self, slug, display_name=None): if not display_name: display_name = DisplayName(slug) self.slug = slug self.display_name = display_name
def __init__(self, slug, display_name=None): self.slug = slug self.display_name = display_name if self.display_name is None: self.display_name = DisplayName(slug)