예제 #1
0
 def post(self):
     main_category_id = self.request.get_range('main_category_id')
     main_category = MenuCategory.get_by_id(main_category_id)
     if not main_category:
         self.abort(400)
     category = MenuCategory(sequence_number=MenuCategory.generate_category_sequence_number(),
                             category=main_category.key)
     category.title = self.request.get('title')
     category.put()
     if self.request.get('image_file') or self.request.get('picture'):
         if self.request.get('image_file'):
             new_url = get_new_image_url('MenuCategory', category.key.id(), image_data=str(self.request.get('image_file')))
         elif self.request.get('picture'):
             new_url = get_new_image_url('MenuCategory', category.key.id(), url=self.request.get('picture'))
         else:
             new_url = None
         if new_url:
             category.picture = new_url
     if category.picture:
         category.icon = get_new_image_url('MenuCategoryIcon', category.key.id(), url=category.picture, size=ICON_SIZE)
     category.put()
     self.redirect_to('mt_category_list')
예제 #2
0
    def post(self):
        data = json.loads(self.request.body)
        name, phone, email = map(data['info'].get, ('name', 'phone', 'email'))
        phone = '7' + ''.join(c for c in phone if '0' <= c <= '9')

        namespace = self._find_namespace(name)
        password = "******" % random.randint(0, 10000)
        CompanyUser.create_user(namespace,
                                namespace=namespace,
                                password_raw=password,
                                login=namespace,
                                rights=CompanyUser.RIGHTS_MASK_ADMIN)

        namespace_manager.set_namespace(namespace)
        cfg = Config(id=1)
        cfg.APP_NAME = name
        cfg.DELIVERY_PHONES = [phone]
        cfg.DELIVERY_EMAILS = ['*****@*****.**', email]
        cfg.SUPPORT_EMAILS = [email]
        cfg.ACTION_COLOR = "FF25B8CD"
        cfg.put()

        delivery_slot_keys = [
            DeliverySlot(name=u'Сейчас', slot_type=0, value=0).put(),
            DeliverySlot(name=u'Через 5 минут', slot_type=0, value=5).put(),
            DeliverySlot(name=u'Через 10 минут', slot_type=0, value=10).put(),
            DeliverySlot(name=u'Через 15 минут', slot_type=0, value=15).put(),
            DeliverySlot(name=u'Через 20 минут', slot_type=0, value=20).put(),
            DeliverySlot(name=u'Через 25 минут', slot_type=0, value=25).put(),
            DeliverySlot(name=u'Через 30 минут', slot_type=0, value=30).put()
        ]

        menu = data['menu']
        init = MenuCategory(category=None, title="Init")
        init.put()
        for i, category_dict in enumerate(menu):
            MenuCategory.generate_category_sequence_number(
            )  # only to increase counter
            category = MenuCategory(title=category_dict["title"],
                                    sequence_number=i,
                                    category=init.key)
            category.put()
            for j, item in enumerate(category_dict["items"]):
                MenuItem(category=category.key,
                         title=item["title"],
                         description=item["description"],
                         picture=item["imageUrl"],
                         price=int(round(float(item["price"]) * 100)),
                         sequence_number=j).put()
            for _ in category.get_items():
                category.generate_sequence_number()  # only to increase counter

        venue_dict = data['venue']
        venue = Venue(title=venue_dict['title'],
                      description=venue_dict['address'],
                      coordinates=ndb.GeoPt(venue_dict['lat'],
                                            venue_dict['lng']),
                      active=True)
        venue.update_address()
        venue.schedule = Schedule(days=[
            DaySchedule(
                weekday=i, start=datetime.time(0, 0), end=datetime.time(0, 0))
            for i in xrange(1, 8)
        ])

        for delivery_type in (SELF, IN_CAFE):
            delivery = DeliveryType.create(delivery_type)
            delivery.put()
            delivery.status = STATUS_AVAILABLE
            delivery.max_time = DAY_SECONDS + HOUR_SECONDS  # need hour to order on tomorrow
            delivery.delivery_slots = delivery_slot_keys
            venue.delivery_types.append(delivery)

        venue.put()

        PaymentType(id=str(CASH_PAYMENT_TYPE),
                    title="cash",
                    status=STATUS_AVAILABLE).put()

        deferred.defer(_notify_sms, phone, namespace, password)
        deferred.defer(_notify_email, email, phone, name, namespace, password)

        self.render_json({'login': namespace, 'password': password})
예제 #3
0
def menu_parse(file_excel):
    wb = xlrd.open_workbook(file_contents=file_excel)
    sh = wb.sheet_by_index(0)
    categories = {}
    products = {}
    group_modifiers = {}
    group_choices = {}
    for row_number in range(sh.nrows):
        if row_number > 0:
            current_category = MenuCategory()
            current_item = MenuItem()
            current_modifier = GroupModifier()
            current_choice = GroupModifierChoice()
            item_add = True
            for index, cell in enumerate(sh.row_values(row_number)):
                if index == 0:
                    current_category.sequence_number = int(cell)
                    current_item.sequence_number = int(cell)
                elif index == 1:
                    if categories.get(cell):
                        current_category = categories[cell]
                    else:
                        current_category.title = cell
                        categories[cell] = current_category
                elif index == 2:
                    if products.get(cell):
                        current_item = products[cell]
                        item_add = False
                    else:
                        current_item.title = cell
                        products[cell] = current_item
                elif index == 3:
                    if item_add:
                        current_item.description = cell
                elif index == 4 and cell:
                    if item_add:
                        current_item.price = int(float(cell) * 100)
                elif index == 5:
                    if item_add and cell:
                        current_item.volume = float(cell)
                elif index == 6:
                    if item_add and cell:
                        current_item.weight = float(cell)
                elif index == 7:
                    if item_add and cell:
                        current_item.kal = int(cell)
                elif index == 8:
                    if cell:
                        if group_modifiers.get(cell):
                            current_modifier = group_modifiers[cell]
                        else:
                            current_modifier.title = cell
                            group_modifiers[cell] = current_modifier
                elif index == 9:
                    if cell:
                        current_choice.title = cell
                elif index == 10:
                    if cell or cell == 0:
                        current_choice.price = int(float(cell) * 100)
                        key = '%s_%s' % (current_choice.title,
                                         current_choice.price)
                        if group_choices.get(key):
                            current_choice = group_choices[key]
                        else:
                            current_choice.choice_id = GroupModifierChoice.generate_id(
                            )
                            group_choices[key] = current_choice
                        if current_choice not in current_modifier.choices:
                            current_modifier.choices.append(current_choice)
                            current_choice.put()
            logging.info(current_modifier)
            if current_modifier.title:
                current_modifier.put()
                if current_modifier.key not in current_item.group_modifiers:
                    current_item.group_modifiers.append(current_modifier.key)
            current_item.put()
            if item_add:
                current_item.category = current_category.key
            current_category.put()