예제 #1
0
    def get(self, *args, **kwargs):
        table_type = self.get_argument('type')

        kwargs = {'user': self.current_user}

        data = {}
        if table_type == 'role_list':
            if not 'RoleRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = BuildRoleData().BuildTableFrame()
        elif table_type == 'member_list':
            if not 'UserRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildUserData().BuildTableFrame(**kwargs)
        elif table_type == 'campus_list':
            if not 'SchoolRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildSchoolData().BuildTableFrame(**kwargs)
        elif table_type == 'order_list':
            if not 'OrderRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildOrderData().BuildTableFrame(**kwargs)
        elif table_type == 'item_list':
            if not 'ItemRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = BuildItemData().BuildTableFrame(**kwargs)
        elif table_type == 'shop_list':
            if not 'ShopRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildShopData().BuildTableFrame(**kwargs)
        elif table_type == 'courier_list':
            if not 'CourierRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildCourierData().BuildTableFrame(**kwargs)
        elif table_type == 'task_list':
            if not 'TaskRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildTaskData().BuildTableFrame(**kwargs)
        elif table_type == 'withdraw_list':
            if not 'WithdrawRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildWithdrawData().BuildTableFrame(**kwargs)
        elif table_type == 'expenses_list':
            if not 'ExpendRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildExpendData().BuildTableFrame(**kwargs)

        table_to_render = {
            'role_list': 'table_role.html',
            'item_list': 'table_role.html',
            'campus_list': 'table_campus.html'
        }.get(table_type, 'table.html')

        self.render(table_to_render, data=data)
예제 #2
0
 def wrapper(self, *args, **kwargs):
     action = self.__class__.RequiredPrivilege
     privileges = self.current_user['privileges']
     if action in privileges:
         return method(self, *args, **kwargs)
     else:
         raise PermissionDeny()
예제 #3
0
    def post(self, *args, **kwargs):
        if not 'SchoolDelete' in self.current_user['privileges']:
            raise PermissionDeny()

        school_id = ObjectId(self.get_argument('id'))
        data_campus = yield BuildSchoolData().BuildSchoolDetail(school_id)

        _delete = self.get_argument('delete', None)
        if _delete == 'true':
            logging.critical('School Delete Attempt: id[%s], user[%s]' %
                             (school_id, self.current_user['name']))
            condition = {'school_district': school_id}
            shops_count = yield self.shop_model.find(condition).count()
            if shops_count > 0:
                data = {
                    'campus': data_campus,
                    'flag': 'error',
                    'message': u'删除学校失败:这个学校还有商店!'
                }
                self.render('detail_page_campus.html', data=data)
            else:
                yield self.school_model.DeleteSchoolFromId(school_id)
                yield SchoolCache().Instance().DeleteSchool(school_id)
                logging.critical('School Delete Success: id[%s], user[%s]' %
                                 (school_id, self.current_user['name']))
                self.redirect('/table?type=campus_list')
        else:
            data = {'campus': data_campus}
            self.render('detail_page_campus.html', data=data)
예제 #4
0
    def post(self, *args, **kwargs):
        if not 'RoleUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        role_id = ObjectId(self.get_argument('id'))
        _delete = self.get_argument('delete', None)
        if _delete == 'true':
            yield self.role_model.DeleteRole(role_id)
            self.redirect('/table?type=role_list')
        else:
            new_privileges = []
            for privilege_group in settings.role.PRIVILEGES:
                for p in privilege_group['privileges']:
                    if self.get_argument(p['name'], None) == 'on':
                        new_privileges.append(p['name'])

            yield self.role_model.UpdateRolePrivileges(role_id, new_privileges)
            role = yield self.role_model.GetRoleFromId(role_id)
            data = {
                'role': {
                    'name':
                    role['text'],
                    '_id':
                    role['_id'],
                    'status':
                    ConvertText().RoleStatusToChinese(role['status']),
                    'permissions':
                    BuildRoleData().BuildPrivileges(role['privileges'])
                }
            }
            self.render('detail_page_role.html', data=data)
예제 #5
0
    def get(self, *args, **kwargs):
        if not 'CourierAccountRead' in self.current_user['privileges']:
            raise PermissionDeny()

        courier_id = ObjectId(self.get_argument('id'))
        data = yield BuildCourierData().BuildCourierAccountData(courier_id)
        self.render('detail_page_courier_account.html', data=data)
예제 #6
0
    def get(self, *args, **kwargs):
        if not 'ExpendRead' in self.current_user['privileges']:
            raise PermissionDeny()

        expend_id = ObjectId(self.get_argument('id'))
        data = yield BuildExpendData().BuildExpendDetail(expend_id)
        self.render('detail_page_expenses.html', data=data)
예제 #7
0
    def post(self, *args, **kwargs):
        process = self.get_argument('process', None)

        if process == 'true':

            if not 'WithdrawUpdate' in self.current_user['privileges']:
                raise PermissionDeny()
            withdraw_id = ObjectId(self.get_argument('id'))
            withdraw_data = yield BuildWithdrawData().BuildWithdrawDetail(withdraw_id)
            result = yield self.withdraw_model.MarkWithdrawProcessed(withdraw_id, '')
            success = result['updatedExisting'] and result['ok'] == 1 and result['nModified'] > 0
            if success:
                data = {
                    'flag': 'ok',
                    'message': '处理成功',
                    'withdraw': withdraw_data
                }
            else:
                data = {
                    'flag': 'error',
                    'message': '处理失败',
                    'withdraw': withdraw_data
                }
            self.render('detail_page_withdraw.html', data=data)

        else:
            self.write('')
예제 #8
0
    def get(self, *args, **kwargs):
        if not 'OrderRead' in self.current_user['privileges']:
            raise PermissionDeny()

        order_id = ObjectId(self.get_argument('id'))
        order = yield self.order_model.GetOrderFromId(order_id)
        data = yield BuildOrderData().BuildOrderDetail(order)
        self.render('detail_page_order.html', data=data)
예제 #9
0
    def get(self, *args, **kwargs):
        if not 'SchoolRead' in self.current_user['privileges']:
            raise PermissionDeny()

        school_id = ObjectId(self.get_argument('id'))
        data_campus = yield BuildSchoolData().BuildSchoolDetail(school_id)
        data = {'campus': data_campus}
        self.render('detail_page_campus.html', data=data)
예제 #10
0
    def get(self, *args, **kwargs):
        if not 'BuildingRead' in self.current_user['privileges']:
            raise PermissionDeny()

        school_id = ObjectId(self.get_argument('school_id'))

        data = yield BuildBuildingData().BuildBuildingCouriersOfSchool(
            school_id)
        self.render('building_couriers.html', data=data)
예제 #11
0
    def get(self, *args, **kwargs):
        if not 'WithdrawRead' in self.current_user['privileges']:
            raise PermissionDeny()

        withdraw_id = ObjectId(self.get_argument('id'))
        withdraw_data = yield BuildWithdrawData().BuildWithdrawDetail(withdraw_id)
        data = {
            'withdraw': withdraw_data
        }
        self.render('detail_page_withdraw.html', data=data)
예제 #12
0
    def post(self, *args, **kwargs):
        if not 'ExpendUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        expend_id = ObjectId(self.get_argument('id'))
        process = self.get_argument('process', '')
        if process:
            result = yield self.expend_model.SetProcessed(expend_id)
        data = yield BuildExpendData().BuildExpendDetail(expend_id)
        data['flag'] = 'ok'
        data['message'] = '处理成功'
        self.render('detail_page_expenses.html', data=data)
예제 #13
0
    def get(self, *args, **kwargs):
        if not 'ItemRead' in self.current_user['privileges']:
            raise PermissionDeny()

        type_id = self.get_argument('type_id', None)
        item_id = ObjectId(self.get_argument('id'))

        if type_id:
            if not 'ShopItemRead' in self.current_user['privileges']:
                raise PermissionDeny()
            category = yield self.category_model.find_one(
                {'_id': ObjectId(type_id)})
            item = yield self.item_model.GetItemFromId(item_id)
            data = BuildShopItemData().BuildShopItemDeatil(item)
            data['shop_id'] = category['shop_id']
            data['type_id'] = category['_id']
            self.render('detail_page_item.html', data=data)
        else:
            if not 'ItemRead' in self.current_user['privileges']:
                raise PermissionDeny()
            item = yield self.item_repo_model.GetItemFromId(item_id)
            data = BuildItemData().BuildItemDeatil(item)
            self.render('detail_page_item.html', data=data)
예제 #14
0
    def get(self, *args, **kwargs):
        if not 'BuildingRead' in self.current_user['privileges']:
            raise PermissionDeny()

        area = self.get_argument('area', '')
        province = self.get_argument('province', '')
        city = self.get_argument('city', '')
        campus = self.get_argument('campus', '')
        if campus == u'全部校区':
            campus = None

        data = yield BuildBuildingData().BuildBuildingsOfArea(
            self.current_user, area, province, city, campus)

        self.render('building.html', data=data)
예제 #15
0
    def get(self, *args, **kwargs):
        if not 'RoleRead' in self.current_user['privileges']:
            raise PermissionDeny()

        role_id = ObjectId(self.get_argument('id'))
        role = yield self.role_model.GetRoleFromId(role_id)
        role_privileges = role['privileges']
        data = {
            'role': {
                'name': role['text'],
                '_id': role['_id'],
                'status': ConvertText().RoleStatusToChinese(role['status']),
                'permissions': BuildRoleData().BuildPrivileges(role_privileges)
            }
        }
        self.render('detail_page_role.html', data=data)
예제 #16
0
    def post(self, *args, **kwargs):
        if not 'ShopUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        shop_id = ObjectId(self.get_argument('id'))
        categories = yield self.category_model.GetCategoriesByShopId(shop_id)
        deleted = []
        for c in categories:
            arg_name = 'name_' + str(c['_id'])
            name = self.get_argument(arg_name, None)
            arg_priority = str(c['_id'])
            priority = self.get_argument(arg_priority, None)
            if not name and not priority:
                deleted.append(c['_id'])
                continue
            condition = {'_id': c['_id']}
            setter = {'$set': {}}
            if name:
                setter['$set']['name'] = name
            if priority:
                setter['$set']['priority'] = int(priority)
            result = yield self.category_model.update(condition, setter)

        yield self.category_model.remove({'_id': {'$in': deleted}})
        yield self.item_model.remove({
            'shop_id': shop_id,
            'category': {
                '$in': deleted
            }
        })

        for k, v in self.request.arguments.items():
            if k.startswith('newnode_'):
                id = k[8:]
                name_key = 'name_newnode_' + id
                name = self.get_argument(name_key)
                priority = int(v[0])
                result = yield self.category_model.insert({
                    'shop_id': shop_id,
                    'name': name,
                    'priority': priority
                })

        self.redirect('/shop_edit_items?id=%s' % shop_id)
예제 #17
0
    def post(self, *args, **kwargs):
        if not 'BuildingUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        school_id = ObjectId(self.get_argument('school_id'))
        buildings = yield self.building_model.GetSchoolBuildings(school_id)
        couriers = yield self.courier_model.GetCouriersFromDistrictId(
            school_id)
        for c in couriers:
            courier_buildings = []
            for b in buildings:
                arg_key = str(b['_id']) + '_' + str(c['_id'])
                if arg_key in self.request.arguments:
                    courier_buildings.append(b['_id'])
            yield self.courier_model.UpdateDeliveryBuildings(
                c['_id'], courier_buildings)

        school = yield self.school_model.GetSchoolFromId(school_id)
        data = yield BuildBuildingData().BuildBuildingCouriersOfSchool(
            school_id)
        self.render('building_couriers.html', data=data)
예제 #18
0
    def get(self, *args, **kwargs):
        if not 'ShopRead' in self.current_user['privileges']:
            raise PermissionDeny()

        shop_id = ObjectId(self.get_argument('shop_id'))
        faked_category_id = self.get_argument('id', None)
        if not faked_category_id or faked_category_id == '0':
            self.write('')
            raise gen.Return(None)
        faked_category = settings.item.GetCategoryFromId(faked_category_id)
        if not faked_category:
            self.write('')
            raise gen.Return(None)

        data_items = yield BuildShopData().BuildShopItems(shop_id, faked_category['name'])

        data = {
            'items': data_items,
            'shop_id': shop_id
        }
        self.render('detail_page_shop_edit_items_content.html', data=data)
예제 #19
0
    def post(self, *args, **kwargs):
        if not 'CourierAccountUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        courier_id = ObjectId(self.get_argument('id'))
        # debt = self.get_argument('debt', '')
        freeze = self.get_argument('freeze', '')

        if freeze == 'freeze':
            result = yield self.courier_model.UpdateAccountStatus(courier_id, True)
        elif freeze == 'unfreeze':
            result = yield self.courier_model.UpdateAccountStatus(courier_id, False)
            # Set 'freezed' expense record to 'unprocessed'
            condition = {
                'courier_id': courier_id,
                'status': 'freezed'
            }
            updater = {
                '$set': {
                    'status': 'unprocessed',
                    'created_time': int(time.time() * 1000)
                }
            }
            result = yield self.expend_model.update(
                condition,
                updater,
                multi=True
            )

        '''
        if debt:
            debt = int(decimal.Decimal(self.get_argument('debt'))*100)
            # TODO: lock update
            result = yield self.courier_model.SetDebt(courier_id, debt)
        '''

        data = yield BuildCourierData().BuildCourierAccountData(courier_id)
        data['flag'] = 'ok'
        data['message'] = '修改成功'
        self.render('detail_page_courier_account.html', data=data)
예제 #20
0
    def post(self, *args, **kwargs):
        if not 'ScheduleUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        area = self.get_argument('area', '')
        province = self.get_argument('province', '')
        city = self.get_argument('city', '')
        campus = self.get_argument('campus', '')

        courier_schedules = {}
        for k, v in self.request.arguments.items():
            m = re.findall('sched_(.*)_(.*)_(.*)', k)
            if not m or len(m[0]) != 3:
                continue
            courier_id = m[0][0]
            sched = courier_schedules.setdefault(courier_id, [])
            sched.append({'start': int(m[0][1]), 'end': int(m[0][2])})

        yield BuildWordhourData().UpdateSchedules(campus, courier_schedules)

        data = yield BuildWordhourData().BuildWorkhourOfArea(
            self.current_user, area, province, city, campus)

        self.render('work_hour.html', data=data)
예제 #21
0
    def post(self, *args, **kwargs):
        order_id = ObjectId(self.get_argument('id'))
        confirm = self.get_argument('confirm', '')
        refund = self.get_argument('refund', '')
        send_to_wukong = self.get_argument('send_to_wukong', '')
        go_to_task = self.get_argument('go_to_task', '')
        hurry = self.get_argument('hurry', '')

        if confirm == 'true':
            if not 'OrderConfirm' in self.current_user['privileges']:
                raise PermissionDeny()
            order = yield self.order_model.GetOrderFromId(order_id)
            if order['status'] in ['sending']:
                yield self.order_model.SetOrderConfirmed(None, order_id)
                express_id = order.get('express_id', None)
                if express_id:
                    client = WukongClient()
                    yield client.NotifyExpressDone(express_id,
                                                   order.get('items_price', 0))

        if refund == 'true':
            if not 'OrderRefund' in self.current_user['privileges']:
                raise PermissionDeny()
            result = yield RefundOrder().Action(order_id)
            if result:
                order_subtask = yield self.subtask_model.find_one(
                    {'express_no': str(order_id)})
                if order_subtask and 'owner_task' in order_subtask:
                    task = yield self.task_model.find_one(
                        {'_id': order_subtask['owner_task']})
                    courier_id = task.get('courier_id')
                    if courier_id:
                        courier = yield self.courier_model.find_one(
                            {'_id': courier_id})
                        device_token = courier.get('device_token')
                        if device_token:
                            push_args = {'data': str(task['_id'])}
                            Push().Action(
                                settings.push.COURIER_APP, device_token,
                                settings.push.PUSH_CONSOLE_SUBTASK_CANCEL,
                                **push_args)

            refund_reason = self.get_argument('refund_reason', '')
            refund_detail = self.get_argument('refund_detail', '')
            record = yield self.order_refund_model.find_one(
                {'order_id': order_id})
            if not record:
                result = yield self.order_refund_model.UpdateRecord(
                    order_id, refund_reason, refund_detail)

        if send_to_wukong == 'true':
            if not 'OrderSend' in self.current_user['privileges']:
                raise PermissionDeny()
            order = yield self.order_model.GetOrderFromId(order_id)
            if order['status'] == 'paid' and not order.get('express_id', ''):
                client = WukongClient()
                express_id = yield client.CreateNewExpress(order)
                yield self.order_model.SetOrderExpressId(
                    order['_id'], express_id)

        if go_to_task == 'true':
            if not 'TaskRead' in self.current_user['privileges']:
                raise PermissionDeny()
            order = yield self.order_model.GetOrderFromId(order_id)
            subtask_id = order.get('express_id')
            if subtask_id:
                task = yield self.task_model.find_one({'subtasks': subtask_id})
                self.redirect('/task_detail?id=%s' % str(task['_id']))

        if hurry == 'true':
            hurry_reason = self.get_argument('hurry_reason', '')
            hurry_detail = self.get_argument('hurry_detail', '')
            result = yield self.order_hurry_model.CreateRecord(
                order_id, hurry_reason, hurry_detail)

        # order = yield self.order_model.GetOrderFromId(order_id)
        # data = yield BuildOrderData().BuildOrderDetail(order)
        # self.render('detail_page_order.html', data=data)
        self.redirect('/order_detail?id=%s' % str(order_id))
예제 #22
0
    def post(self, *args, **kwargs):
        if not 'CourierUpdate' in self.current_user['privileges']:
            raise PermissionDeny()
        courier_id = ObjectId(self.get_argument('id'))
        name = self.get_argument('name', None)
        school = self.get_argument('campus', None)
        mobile = self.get_argument('mobile', None)
        verify_result = self.get_argument('pass', None)
        lock_result = self.get_argument('lock', None)
        longitude = self.get_argument('lng', None)
        latitude = self.get_argument('lat', None)

        new_data = {}
        if name:
            new_data['name'] = name
        if mobile:
            new_data['mobile'] = mobile
        if verify_result == 'pass':
            new_data['status'] = 'verified'
        if verify_result == 'reject':
            new_data['status'] = 'failed'
        if lock_result == 'lock':
            new_data['status'] = 'locked'
        if lock_result == 'unlock':
            new_data['status'] = 'verified'
        if latitude and latitude:
            new_data['location'] = [float(longitude), float(latitude)]

        region = self.get_argument('area', None)
        province = self.get_argument('province', None)
        city = self.get_argument('city', None)
        school = self.get_argument('campus', None)

        if school:
            school = yield self.school_model.GetSchoolFromName(school)
            if school:
                new_data['district_id'] = school['_id']
                new_data['school'] = school['name']

        condition = {'_id': courier_id}
        updater = {'$set': new_data}

        result = yield self.courier_model.update(condition, updater)

        courier = yield self.courier_model.GetCourierFromId(courier_id)

        courier_school_id = courier.get('district_id')
        if courier_school_id:
            available_couriers = yield self.courier_model.GetCouriersFromDistrictId(
                courier_school_id)
            if not available_couriers:
                result = yield self.shop_model.update(
                    {'school_district': courier_school_id},
                    {'$set': {
                        'status': 'closed'
                    }},
                    multi=True)

        data = yield BuildCourierData().BuildCourierDeatil(
            courier, self.current_user)
        self.render('detail_page_courier.html', data=data)
예제 #23
0
    def post(self, *args, **kwargs):
        if not 'BuildingUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        school_id = ObjectId(self.get_argument('school_id'))
        building_dispatch = self.get_argument('building_dispatch', None)

        if building_dispatch:
            yield self.school_model.SetDispatchStrategy(school_id, 'building')
        else:
            yield self.school_model.DeleteDispatchStrategy(
                school_id, 'building')

        buildings = yield self.building_model.GetSchoolBuildings(school_id)
        deleted = []
        for b in buildings:
            arg_name = 'name_' + str(b['_id'])
            name = self.get_argument(arg_name, None)
            if not name:
                deleted.append(b['_id'])
                continue
            condition = {'_id': b['_id']}
            setter = {'$set': {}}
            if name:
                setter['$set']['name'] = name
            result = yield self.building_model.update(condition, setter)

        yield self.building_model.remove({'_id': {'$in': deleted}})

        exist_building_name = []
        for k, v in self.request.arguments.items():
            if k.startswith('newnode_'):
                id = k[8:]
                name_key = 'name_newnode_' + id
                name = self.get_argument(name_key)
                exist_building = yield self.building_model.find_one({
                    'school_id':
                    school_id,
                    'name':
                    name
                })
                if exist_building:
                    exist_building_name.append(name)
                else:
                    result = yield self.building_model.insert({
                        'school_id': school_id,
                        'name': name
                    })

        school = yield self.school_model.GetSchoolFromId(school_id)
        data = yield BuildBuildingData().BuildBuildingsOfArea(
            self.current_user, school['region'], school['province'],
            school['city'], school['name'])

        if exist_building_name:
            data['flag'] = 'error'
            names = ''
            for name in exist_building_name:
                names += ' ' + name
            data['message'] = u'重复校区名:' + names

        self.render('building.html', data=data)
예제 #24
0
    def get(self, *args, **kwargs):
        type = self.get_argument('type')
        page = int(self.get_argument('page', 1))
        filter_type = self.get_argument('filter_type', '')
        filter_value = self.get_argument('filter_value', '')
        filter_status = self.get_argument('filter_status', '')
        filter_time_start = self.get_argument('filter_datestart', None)
        filter_time_end = self.get_argument('filter_dateend', None)
        area = self.get_argument('area', '')
        province = self.get_argument('province', '')
        city = self.get_argument('city', '')
        campus = self.get_argument('campus', '')

        if not area or u'全部' in area:
            area = self.current_user['region']
        if not province or u'全部' in province:
            province = self.current_user['province']
        if not city or u'全部' in city:
            city = self.current_user['city']
        if not campus or u'全部' in campus:
            campus = self.current_user['school_name']

        if filter_time_start:
            dt = datetime.datetime.utcfromtimestamp(int(filter_time_start)/1000)
            filter_time_start = int(time.mktime(dt.timetuple())) * 1000
        if filter_time_end:
            dt = datetime.datetime.utcfromtimestamp(int(filter_time_end)/1000) + datetime.timedelta(days=1)
            filter_time_end = int(time.mktime(dt.timetuple())) * 1000

        kwargs = {
            'page': page,
            'filter_type': filter_type,
            'filter_value': filter_value,
            'filter_status': filter_status,
            'filter_time_start': filter_time_start,
            'filter_time_end': filter_time_end,
            'area': area,
            'province': province,
            'city': city,
            'campus': campus
        }

        data = {}
        if type == 'role_list':
            if not 'RoleRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildRoleData().BuildTableContent(**kwargs)
        elif type == 'member_list':
            if not 'UserRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildUserData().BuildTableContent(**kwargs)
        elif type == 'campus_list':
            if not 'SchoolRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildSchoolData().BuildTableContent(**kwargs)
        elif type == 'order_list':
            if not 'OrderRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildOrderData().BuildTableContent(**kwargs)
        elif type == 'item_list':
            if not 'ItemRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildItemData().BuildTableContent(**kwargs)
        elif type == 'shop_list':
            if not 'ShopRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildShopData().BuildTableContent(**kwargs)
        elif type == 'courier_list':
            if not 'CourierRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildCourierData().BuildTableContent(**kwargs)
        elif type == 'task_list':
            if not 'TaskRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildTaskData().BuildTableContent(**kwargs)
        elif type == 'withdraw_list':
            if not 'WithdrawRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildWithdrawData().BuildTableContent(**kwargs)
        elif type == 'expenses_list':
            if not 'ExpendRead' in self.current_user['privileges']:
                raise PermissionDeny()
            data = yield BuildExpendData().BuildTableContent(**kwargs)

        self.render('table_content.html', data=data)
예제 #25
0
    def post(self, *args, **kwargs):
        if not 'ShopUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        shop_id = ObjectId(self.get_argument('shop_id'))
        faked_category_id = self.get_argument('id')
        hardcoded_category = settings.item.GetCategoryFromId(faked_category_id)

        selected_items = {}
        for k,v in self.request.arguments.items():
            m = re.findall('.*_(.*)_checked', k)
            if m:
                selected_items[m[0]] = {}
        for k,v in self.request.arguments.items():
            m = re.findall('.*_(.*)_price', k)
            if m and m[0] in selected_items:
                selected_items[m[0]]['price'] = int(decimal.Decimal(v[0])*100)

        condition = {
            'shop_id': shop_id,
            'name': hardcoded_category['name']
        }
        category = yield self.category_model.find_one(condition)
        if not category and selected_items:
            category_data = {
                'shop_id': shop_id,
                'name': hardcoded_category['name'],
                'priority': hardcoded_category['priority']
            }
            new_category_id = yield self.category_model.insert(category_data)
            category = yield self.category_model.find_one({'_id': new_category_id})

        condition = {
            '_id': {  '$in': [ObjectId(_) for _ in selected_items] }
        }
        selected_repo_items = yield self.item_repo_model.find(condition).to_list(None)
        selected_item_numbers = [_['number'] for _ in selected_repo_items]

        condition = {
            'category': hardcoded_category['name']
        }
        all_repo_items = yield self.item_repo_model.find(condition).to_list(None)
        all_repo_item_numbers = [_['number'] for _ in all_repo_items]

        on_sale_items_condition = {
            'shop_id': shop_id,
            'category': category['_id'],
            'status': 'on_sale',
            'old': { '$exists': False }
        }
        current_shop_on_sale_items = yield self.item_model.find(on_sale_items_condition).to_list(None)
        go_off_shelves_item_numbers = [
            i['id']
            for i in current_shop_on_sale_items
                if i ['id'] in all_repo_item_numbers and not i['id'] in selected_item_numbers
        ]

        condition = {
            'shop_id': shop_id,
            'category': category['_id'],
            'old': { '$exists': False },
            'id': { '$in': go_off_shelves_item_numbers }
        }
        updater = {
            '$set': { 'status': 'off_shelves' }
        }
        result = yield self.item_model.update(condition, updater, multi=True)
        logging.info('[ShopEditItemsContent] ' + self.current_user.get('name','') + ' off_shelves: ' + str(go_off_shelves_item_numbers))

        # current_shop_on_sale_item_numbers = [_['id'] for _ in current_shop_on_sale_items]
        for item in selected_repo_items:
            condition = {
                'shop_id': shop_id,
                'category': category['_id'],
                'id': item['number'],
                'name': item['name']
            }
            updater = {
                '$set': {
                    'status': 'on_sale',
                    'price': selected_items[str(item['_id'])]['price'],
                    'priority': item['priority'],
                    'image_id': item['image_id'],
                    'description': item.get('description', '')
                }
            }

            if 'limit' in item:
                updater['$set']['special_price'] = item['special_price']
                updater['$set']['limit'] = item['limit']

            result = yield self.item_model.update(condition, updater, upsert=True)

        data_items = yield BuildShopData().BuildShopItems(shop_id, category['name'])
        data = {
            'items': data_items,
            'shop_id': shop_id,
            'flag': 'ok',
            'message': u'修改成功'
        }
        self.render('detail_page_shop_edit_items_content.html', data=data)
예제 #26
0
    def post(self, *args, **kwargs):
        item_id = ObjectId(self.get_argument('id'))
        type = self.get_argument('type', None)
        name = self.get_argument('name', None)
        description = self.get_argument('des', None)
        status = self.get_argument('status', None)
        brand = self.get_argument('brand', None)
        note = self.get_argument('note', None)
        code = self.get_argument('code', None)
        price = self.get_argument('price', None)
        priority = self.get_argument('priority', None)
        is_special = self.get_argument('is_special', None)
        special_price = self.get_argument('special_price', None)
        limit = self.get_argument('limit', None)

        category_id = self.get_argument('type_id', None)

        if category_id:
            if not 'ShopItemUpdate' in self.current_user['privileges']:
                raise PermissionDeny()

            category = yield self.category_model.find_one(
                {'_id': ObjectId(category_id)})
            new_item_data = {}
            new_item_data['shop_id'] = category['shop_id']
            new_item_data['category'] = category['_id']
            new_item_data['priority'] = 0
            if name:
                new_item_data['name'] = name.strip().encode('utf8')
            if price:
                new_item_data['price'] = int(decimal.Decimal(price) * 100)
            if description:
                new_item_data['description'] = description.strip().encode(
                    'utf8')
            if priority:
                new_item_data['priority'] = int(priority.strip())
            if status:
                if status == 'on':
                    new_item_data['status'] = 'on_sale'
                elif status == 'off':
                    new_item_data['status'] = 'off_shelves'
                elif status == 'deleted':
                    new_item_data['status'] = 'deleted'
            #if brand:
            #    new_item_data['brand'] = brand.strip().encode('utf8')
            image_file = self.request.files.get('photo', '')
            if image_file:
                photo_bin = self.request.files['photo'][0]['body']
                image_id = yield self.image_model.Save(photo_bin)
                new_item_data['image_id'] = image_id

            result = yield self.item_model.update({'_id': item_id},
                                                  {'$set': new_item_data})
            success = result['updatedExisting'] and result[
                'ok'] == 1 and result['nModified'] > 0
            item = yield self.item_model.GetItemFromId(item_id)
            data = BuildShopItemData().BuildShopItemDeatil(item)
            data['shop_id'] = category['shop_id']
            data['type_id'] = category['_id']
            if success:
                data['flag'] = 'ok'
                data['message'] = '修改商品资料成功'
                self.render('detail_page_item.html', data=data)
            else:
                data['flag'] = 'error'
                data['message'] = '修改商品资料失败'
                self.render('detail_page_item.html', data=data)
        else:
            if not 'ItemUpdate' in self.current_user['privileges']:
                raise PermissionDeny()

            # Remove item from shop.
            if status in ['off', 'deleted', 'off_shelves']:
                item = yield self.item_repo_model.GetItemFromId(item_id)
                result = yield self.item_model.update(
                    {'id': item['number']},
                    {'$set': {
                        'status': 'off_shelves'
                    }},
                    multi=True)

            new_item_data = {}
            if type:
                new_item_data['category'] = type.strip().encode('utf8')
            if name:
                new_item_data['name'] = name.strip().encode('utf8')
            if description:
                new_item_data['description'] = description.strip().encode(
                    'utf8')
            if brand:
                new_item_data['brand'] = brand.strip().encode('utf8')
            if note:
                new_item_data['note'] = note.strip().encode('utf8')
            if status:
                new_item_data['status'] = status
            #if code:
            #    new_item_data['number'] = int(code.strip())
            if price:
                new_item_data['price'] = int(
                    decimal.Decimal(price.strip()) * 100)
            if priority:
                new_item_data['priority'] = float(
                    decimal.Decimal(priority.strip()))

            if is_special == 'true':
                new_item_data['special_price'] = int(
                    decimal.Decimal(special_price) * 100)
                new_item_data['limit'] = int(limit)

            image_file = self.request.files.get('photo', '')
            if image_file:
                photo_bin = self.request.files['photo'][0]['body']
                image_id = yield self.image_model.Save(photo_bin)
                new_item_data['image_id'] = image_id

            result = yield self.item_repo_model.UpdateItem(
                item_id, new_item_data)
            success = result['updatedExisting'] and result[
                'ok'] == 1 and result['nModified'] > 0
            item = yield self.item_repo_model.GetItemFromId(item_id)
            data = BuildItemData().BuildItemDeatil(item)
            if success:
                data['flag'] = 'ok'
                data['message'] = '修改商品资料成功'
            else:
                data['flag'] = 'error'
                data['message'] = '修改商品资料失败'
            self.render('detail_page_item.html', data=data)
예제 #27
0
    def post(self, *args, **kwargs):
        if not 'UserUpdate' in self.current_user['privileges']:
            raise PermissionDeny()

        user_id = ObjectId(self.get_argument('id'))
        name = self.get_argument('name', None)
        mobile = self.get_argument('mobile', None)
        password = self.get_argument('pass', None)
        region = self.get_argument('area', None)
        province = self.get_argument('province', None)
        city = self.get_argument('city', None)
        school = self.get_argument('campus', None)
        note = self.get_argument('note', None)
        lock = self.get_argument('lock', None)

        user_data = {}
        if self._IsParamAvailable(name):
            user_data['name'] = name.encode('utf8')
        if self._IsParamAvailable(mobile):
            user_data['mobile'] = mobile
        if self._IsParamAvailable(password):
            user_data['password'] = HashPassword().Action(
                password.encode('utf8'))
        if self._IsParamAvailable(region):
            user_data['region'] = region.encode('utf8')
        if self._IsParamAvailable(province):
            user_data['province'] = province.encode('utf8')
        if self._IsParamAvailable(city):
            user_data['city'] = city.encode('utf8')
        if self._IsParamAvailable(city):
            user_data['school_name'] = school.encode('utf8')
        if self._IsParamAvailable(note):
            user_data['note'] = note.encode('utf8')
        if lock == 'lock':
            user_data['status'] = 'locked'
        elif lock == 'unlock':
            user_data['status'] = 'normal'

        roles = []
        candidate_roles = yield BuildRoleData().BuildRoleCandidatesList()
        for cr in candidate_roles:
            if self.get_argument(cr['arg_name'].encode('utf8'), None) == 'on':
                roles.append(cr['arg_name'])
        user_data['roles'] = roles

        if school != u'全部校区':
            __school__ = yield self.school_model.GetSchoolFromName(school)
            user_data['school_id'] = __school__['_id']

        result = yield self.console_user_model.UpdateUserInfo(
            user_id, user_data)
        success = result['updatedExisting'] and result[
            'ok'] == 1 and result['nModified'] > 0
        if success:
            data = {'flag': 'ok', 'message': '修改用户资料成功'}
        else:
            data = {'flag': 'error', 'message': '修改用户资料失败'}

        user = yield self.console_user_model.GetUserFromId(user_id)
        data = yield BuildUserData().BuildUserDetail(self.current_user, user)

        self.render('detail_page_member.html', data=data)