Esempio n. 1
0
 def get(self, *args, **kwargs):
     shop_id = ObjectId(self.get_argument('id'))
     shop = yield self.shop_model.GetShopFromId(shop_id)
     shop_data = yield BuildShopData().BuildShopDeatil(shop)
     areas_full = yield BuildAreaData().BuildAreasWithSchools(
         self.current_user)
     school_of_shop = yield self.school_model.GetSchoolFromId(
         shop['school_district'])
     if not school_of_shop:
         school_of_shop = {}
     data = {
         'shop': shop_data,
         'areas': {
             'full':
             json.dumps(areas_full),
             'choosed':
             json.dumps({
                 'area': school_of_shop.get('region', ''),
                 'province': school_of_shop.get('province', ''),
                 'city': school_of_shop.get('city', ''),
                 'campus': school_of_shop.get('name', '')
             })
         },
         'shop_add': False
     }
     self.render('detail_page_shop_edit.html', data=data)
Esempio n. 2
0
 def get(self, *args, **kwargs):
     areas_full = yield BuildAreaData().BuildAreasWithSchools(self.current_user)
     data = {
         'areas': {
             'full': json.dumps(areas_full)
         },
         'shop_add': True
     }
     self.render('detail_page_shop_edit.html', data=data)
Esempio n. 3
0
 def get(self, *args, **kwargs):
     candidates_roles = yield BuildRoleData().BuildRoleCandidatesList()
     area_full = yield BuildAreaData().BuildAreasWithSchools(
         self.current_user)
     data = {
         'roles': [
             {
                 'display_name': u'候选角色',
                 'sub_roles': candidates_roles
             },
         ],
         'areas': {
             'full': json.dumps(area_full)
         }
     }
     self.render('detail_page_member_add.html', data=data)
Esempio n. 4
0
    def post(self, *args, **kwargs):
        action = self.get_argument('type')

        region = self.get_argument('area')
        province = self.get_argument('province')
        city = self.get_argument('city')
        school_name = self.get_argument('campus')

        date_start = self.get_argument('date_start')
        hour_start = self.get_argument('hour_start')
        minute_start = self.get_argument('minute_start')
        second_start = self.get_argument('second_start')

        date_end = self.get_argument('date_end')
        hour_end = self.get_argument('hour_end')
        minute_end = self.get_argument('minute_end')
        second_end = self.get_argument('second_end')

        email = self.get_argument('email')
        set_processed = self.get_argument('set_processed', '')

        start_dt = datetime.datetime.strptime(date_start, '%Y-%m-%d')
        start_dt += datetime.timedelta(hours=int(hour_start),
                                       minutes=int(minute_start),
                                       seconds=int(second_start))
        end_dt = datetime.datetime.strptime(date_end, '%Y-%m-%d')
        end_dt += datetime.timedelta(hours=int(hour_end),
                                     minutes=int(minute_end),
                                     seconds=int(second_end))

        data = {}

        if action == 'create':
            yield CreateExpenseRecords().Create(start_dt, end_dt, region,
                                                province, city, school_name)
            data = {'flag': 'ok', 'message': '生成支出记录成功'}
        elif action == 'export':
            self.queue.enqueue(expense.run, start_dt, end_dt, region, province,
                               city, school_name, [email], set_processed,
                               switch.DEBUG)
            data = {'flag': 'ok', 'message': '导出成功'}

        areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(
            self.current_user)
        data['areas'] = {'full': json.dumps(areas_with_schools)}

        self.render('detail_page_expenses_export.html', data=data)
Esempio n. 5
0
    def post(self, *args, **kwargs):
        region = self.get_argument('area')
        province = self.get_argument('province')
        city = self.get_argument('city')
        campus = self.get_argument('campus')

        areas_full = yield BuildAreaData().BuildAreasWithSchools(self.current_user)
        data = {
            'flag': 'ok',
            'message': u'',
            'areas': {
                'full': json.dumps(areas_full)
            }
        }

        if u'全部' in region or u'全部' in province or u'全部' in city or u'全部' in campus:
            data['flag'] = 'error'
            data['message'] = u'添加店铺失败:未选择校区'
            self.render('detail_page_shop_edit.html', data=data)
            raise gen.Return(None)

        shop_data = yield BuildShopData().BuildShopFromRequest(self)
        shop_data['created_time'] = int(time.time()*1000)
        shop_data['image_id'] = self.GetShopImageId(shop_data['type'])

        school = yield self.school_model.GetSchoolFromName(campus)
        available_couriers = yield self.courier_model.GetCouriersFromDistrictId(school['_id'])
        if not available_couriers:
            shop_data['status'] = 'closed'

        result = yield self.shop_model.insert(shop_data)
        if result:
            self.redirect('/shop_detail?id=%s' % result)
        else:
            data['flag'] = 'error'
            data['message'] = u'添加店铺失败'
            self.render('detail_page_shop_edit.html', data=data)
Esempio n. 6
0
    def post(self, *args, **kwargs):
        shop_id = ObjectId(self.get_argument('id'))
        shop_data = yield BuildShopData().BuildShopFromRequest(self)

        if shop_data['status'] == 'open':
            shop = yield self.shop_model.GetShopFromId(shop_id)
            school = yield self.school_model.GetSchoolFromId(
                shop['school_district'])
            available_couriers = yield self.courier_model.GetCouriersFromDistrictId(
                school['_id'])
            if not available_couriers:
                del shop_data['status']
                shop = yield self.shop_model.GetShopFromId(shop_id)
                shop_data = yield BuildShopData().BuildShopDeatil(shop)
                areas_full = yield BuildAreaData().BuildAreasWithSchools(
                    self.current_user)
                school_of_shop = yield self.school_model.GetSchoolFromId(
                    shop['school_district'])
                if not school_of_shop:
                    school_of_shop = {}
                data = {
                    'shop': shop_data,
                    'areas': {
                        'full':
                        json.dumps(areas_full),
                        'choosed':
                        json.dumps({
                            'area':
                            school_of_shop.get('region', ''),
                            'province':
                            school_of_shop.get('province', ''),
                            'city':
                            school_of_shop.get('city', ''),
                            'campus':
                            school_of_shop.get('name', '')
                        })
                    }
                }
                data['flag'] = 'error'
                data['message'] = '没有工作的速递员,不能营业'
                self.render('detail_page_shop_edit.html', data=data)
                raise gen.Return(None)

        result = yield self.shop_model.UpdateShop(shop_id, shop_data)
        success = result['updatedExisting'] and result['ok'] == 1

        if success:
            self.redirect('/shop_detail?id=%s' % shop_id)
        else:
            shop = yield self.shop_model.GetShopFromId(shop_id)
            shop_data = yield BuildShopData().BuildShopDeatil(shop)
            areas_full = yield BuildAreaData().BuildAreasWithSchools(
                self.current_user)
            school_of_shop = yield self.school_model.GetSchoolFromId(
                shop['school_district'])
            if not school_of_shop:
                school_of_shop = {}
            data = {
                'shop': shop_data,
                'areas': {
                    'full':
                    json.dumps(areas_full),
                    'choosed':
                    json.dumps({
                        'area': school_of_shop.get('region', ''),
                        'province': school_of_shop.get('province', ''),
                        'city': school_of_shop.get('city', ''),
                        'campus': school_of_shop.get('name', '')
                    })
                }
            }
            data['flag'] = 'error'
            data['message'] = '修改学校资料失败'
            self.render('detail_page_shop_edit.html', data=data)
Esempio n. 7
0
    def post(self, *args, **kwargs):
        name = self.get_argument('name').strip().encode('utf8')
        realname = self.get_argument('realname', '').strip()
        password = self.get_argument('pass').strip()
        mobile = self.get_argument('mobile', '').strip()
        region = self.get_argument('area').encode('utf8')
        province = self.get_argument('province').encode('utf8')
        city = self.get_argument('city').encode('utf8')
        school = self.get_argument('campus').encode('utf8')
        note = self.get_argument('note', '').encode('utf8')

        if not name or not password or not mobile:
            raise ParamInvalidError()

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

        if not self._ValidatePassword(password):
            area_full = yield BuildAreaData().BuildAreasWithSchools(
                self.current_user)
            data = {
                'roles': [{
                    'display_name': u'候选角色',
                    'sub_roles': candidate_roles
                }],
                'areas': {
                    'full': json.dumps(area_full)
                },
                'flag': 'error',
                'message': '创建新用户失败 密码不合法'
            }
            self.render('detail_page_member_add.html', data=data)
            raise gen.Return(None)

        user_data = {
            'name': name,
            'password': HashPassword().Action(password),
            'status': 'normal',
            'mobile': mobile,
            'roles': roles,
            'region': region,
            'province': province,
            'city': city,
            'school_name': school,
            'note': note,
            'realname': realname
        }

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

        result, user_id = yield self.console_user_model.CreateNewUser(
            user_data)

        if result == 'created':
            self.redirect('/member_detail?id=%s' % user_id)
        else:
            error_info = ''
            if result == 'updated':
                error_info = '用户名已存在'
            area_full = yield BuildAreaData().BuildAreasWithSchools(
                self.current_user)
            data = {
                'roles': [
                    {
                        'display_name': u'候选角色',
                        'sub_roles': candidate_roles
                    },
                ],
                'areas': {
                    'full': json.dumps(area_full)
                },
                'flag': 'error',
                'message': '创建新用户失败 ' + error_info
            }
            self.render('detail_page_member_add.html', data=data)
Esempio n. 8
0
 def get(self, *args, **kwargs):
     areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(
         self.current_user)
     data = {'areas': {'full': json.dumps(areas_with_schools)}}
     self.render('detail_page_expenses_export.html', data=data)